--- a/web/views/cwuser.py Fri Sep 16 10:36:46 2011 +0200
+++ b/web/views/cwuser.py Fri Sep 16 12:48:26 2011 +0200
@@ -68,8 +68,8 @@
self.cell_call(i, 0)
self.w(u'</rdf:RDF>\n')
- def cell_call(self, row, col):
- entity = self.cw_rset.complete_entity(row, col)
+ def entity_call(self, entity, **kwargs):
+ entity.complete()
# account
self.w(u'<foaf:OnlineAccount rdf:about="%s">\n' % entity.absolute_url())
self.w(u' <foaf:accountName>%s</foaf:accountName>\n' % entity.login)
@@ -126,11 +126,10 @@
__regid__ = 'cwgroup-permissions'
__select__ = is_instance('CWGroup')
- def cell_call(self, row, col):
+ def entity_call(self, entity):
self._cw.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
access_types = ('read', 'delete', 'add', 'update')
w = self.w
- entity = self.cw_rset.get_entity(row, col)
objtype_access = {'CWEType': ('read', 'delete', 'add', 'update'),
'CWRelation': ('add', 'delete')}
rql_cwetype = 'DISTINCT Any X WHERE X %s_permission CWG, X is CWEType, ' \
@@ -148,12 +147,13 @@
self.w(u'<div>%s:</div>' % self._cw.__(access_type + '_permission'))
self.w(u'<div>%s</div><br/>' % self._cw.view('csv', rset, 'null'))
+
class CWGroupInContextView(EntityView):
__regid__ = 'incontext'
__select__ = is_instance('CWGroup')
- def cell_call(self, row, col):
- entity = self.cw_rset.complete_entity(row, col)
+ def entity_call(self, entity, **kwargs):
+ entity.complete()
self.w(u'<a href="%s" class="%s">%s</a>' % (
entity.absolute_url(), entity.name, entity.printable_value('name')))
@@ -166,34 +166,64 @@
category = 'manage'
+class UsersAndGroupsManagementView(tabs.TabsMixin, StartupView):
+ __regid__ = 'cw.users-and-groups-management'
+ __select__ = StartupView.__select__ & match_user_groups('managers')
+ title = _('Users and groups management')
+ tabs = [_('cw.users-management'), _('cw.groups-management'),]
+ default_tab = 'cw.users-management'
+
+ def call(self, **kwargs):
+ """The default view representing the instance's management"""
+ self.w(u'<h1>%s</h1>' % self._cw._(self.title))
+ self.render_tabs(self.tabs, self.default_tab)
+
+
class CWUserManagementView(StartupView):
- __regid__ = 'cw.user-management'
+ __regid__ = 'cw.users-management'
+ __select__ = StartupView.__select__ & match_user_groups('managers')
+ cache_max_age = 0 # disable caching
# XXX one could wish to display for instance only user's firstname/surname
# for non managers but filtering out NULL cause crash with an ldapuser
# source.
- __select__ = StartupView.__select__ & match_user_groups('managers')
- rql = ('Any U,USN,F,S,U,UAA,UDS, L,UAA,UDSN ORDERBY L WHERE U is CWUser, '
+ rql = ('Any U,US,F,S,U,UAA,UDS, L,UAA,USN,UDSN ORDERBY L WHERE U is CWUser, '
'U login L, U firstname F, U surname S, '
'U in_state US, US name USN, '
'U primary_email UA?, UA address UAA, '
'U cw_source UDS, US name UDSN')
- title = _('users and groups management')
+
+ def call(self, **kwargs):
+ add_button(self, 'CWUser')
+ self.w(u'<div class="clear"></div>')
+ self.wview('cw.users-table', self._cw.execute(self.rql))
+
+
+class CWGroupsManagementView(StartupView):
+ __regid__ = 'cw.groups-management'
+ __select__ = StartupView.__select__ & match_user_groups('managers')
cache_max_age = 0 # disable caching
+ rql = ('Any G,COUNT(U), GN GROUPBY G,GN ORDERBY GN '
+ 'WHERE G is CWGroup, U? in_group G, G name GN, NOT G name "owners"')
+ headers = [None, None]
+ cellvids = {}
def call(self, **kwargs):
- self.w('<h1>%s</h1>' % self._cw._(self.title))
- for etype in ('CWUser', 'CWGroup'):
- eschema = self._cw.vreg.schema.eschema(etype)
- if eschema.has_perm(self._cw, 'add'):
- self.w(u'<a href="%s" class="addButton right">%s</a>' % (
- self._cw.build_url('add/%s' % eschema),
- self._cw.__('New %s' % etype).capitalize()))
+ add_button(self, 'CWGroup')
self.w(u'<div class="clear"></div>')
- self.wview('cw.user-table', self._cw.execute(self.rql))
+ self.wview('editable-table', self._cw.execute(self.rql),
+ headers=self.headers, cellvids=self.cellvids)
-class CWUserTable(tableview.EditableTableView):
- __regid__ = 'cw.user-table'
+def add_button(self, etype):
+ eschema = self._cw.vreg.schema.eschema(etype)
+ if eschema.has_perm(self._cw, 'add'):
+ self.w(u'<a href="%s" class="addButton right">%s</a>' % (
+ self._cw.build_url('add/%s' % eschema),
+ self._cw.__('New %s' % etype).capitalize()))
+
+
+class CWUsersTable(tableview.EditableTableView):
+ __regid__ = 'cw.users-table'
__select__ = is_instance('CWUser')
def call(self, **kwargs):
@@ -203,25 +233,24 @@
display_name(self._cw, 'CWGroup', 'plural'),
display_name(self._cw, 'primary_email'),
display_name(self._cw, 'CWSource'))
- super(CWUserTable, self).call(
+ super(CWUsersTable, self).call(
paginate=True, displayfilter=True,
cellvids={0: 'cw.user.login',
- 4: 'cw.user-table.group-cell'},
+ 4: 'cw.users-table.group-cell'},
headers=headers, **kwargs)
class CWUserGroupCell(EntityView):
- __regid__ = 'cw.user-table.group-cell'
+ __regid__ = 'cw.users-table.group-cell'
__select__ = is_instance('CWUser')
- def cell_call(self, row, col, **kwargs):
- entity = self.cw_rset.get_entity(row, col)
+ def entity_call(self, entity, **kwargs):
self.w(entity.view('reledit', rtype='in_group', role='subject'))
+
class CWUserLoginCell(EntityView):
__regid__ = 'cw.user.login'
__select__ = is_instance('CWUser')
- def cell_call(self, row, col, **kwargs):
- entity = self.cw_rset.get_entity(row, col)
+ def entity_call(self, entity, **kwargs):
self.w(tags.a(entity.login, href=entity.absolute_url()))
--- a/web/views/urlrewrite.py Fri Sep 16 10:36:46 2011 +0200
+++ b/web/views/urlrewrite.py Fri Sep 16 12:48:26 2011 +0200
@@ -20,6 +20,7 @@
import re
from cubicweb import typed_eid
+from cubicweb.uilib import domid
from cubicweb.appobject import AppObject
@@ -96,7 +97,10 @@
('/error', dict(vid='error')),
('/sparql', dict(vid='sparql')),
('/processinfo', dict(vid='processinfo')),
- (rgx('/cwuser', re.I), dict(vid='cw.user-management')),
+ (rgx('/cwuser', re.I), dict(vid='cw.users-and-groups-management',
+ tab=domid('cw.users-management'))),
+ (rgx('/cwgroup', re.I), dict(vid='cw.users-and-groups-management',
+ tab=domid('cw.groups-management'))),
(rgx('/cwsource', re.I), dict(vid='cw.source-management')),
# XXX should be case insensitive as 'create', but I would like to find another way than
# relying on the etype_selector