164 __regid__ = 'cwuser' # see rewrite rule /cwuser |
164 __regid__ = 'cwuser' # see rewrite rule /cwuser |
165 title = _('users and groups') |
165 title = _('users and groups') |
166 category = 'manage' |
166 category = 'manage' |
167 |
167 |
168 |
168 |
|
169 class UsersAndGroupsManagementView(tabs.TabsMixin, StartupView): |
|
170 __regid__ = 'cw.users-and-groups-management' |
|
171 __select__ = StartupView.__select__ & match_user_groups('managers') |
|
172 title = _('Users and groups management') |
|
173 tabs = [_('cw.users-management'), _('cw.groups-management'),] |
|
174 default_tab = 'cw.users-management' |
|
175 |
|
176 def call(self, **kwargs): |
|
177 """The default view representing the instance's management""" |
|
178 self.w(u'<h1>%s</h1>' % self._cw._(self.title)) |
|
179 self.render_tabs(self.tabs, self.default_tab) |
|
180 |
|
181 |
169 class CWUserManagementView(StartupView): |
182 class CWUserManagementView(StartupView): |
170 __regid__ = 'cw.user-management' |
183 __regid__ = 'cw.users-management' |
|
184 __select__ = StartupView.__select__ & match_user_groups('managers') |
|
185 cache_max_age = 0 # disable caching |
171 # XXX one could wish to display for instance only user's firstname/surname |
186 # XXX one could wish to display for instance only user's firstname/surname |
172 # for non managers but filtering out NULL cause crash with an ldapuser |
187 # for non managers but filtering out NULL cause crash with an ldapuser |
173 # source. |
188 # source. |
174 __select__ = StartupView.__select__ & match_user_groups('managers') |
189 rql = ('Any U,US,F,S,U,UAA,UDS, L,UAA,USN,UDSN ORDERBY L WHERE U is CWUser, ' |
175 rql = ('Any U,USN,F,S,U,UAA,UDS, L,UAA,UDSN ORDERBY L WHERE U is CWUser, ' |
|
176 'U login L, U firstname F, U surname S, ' |
190 'U login L, U firstname F, U surname S, ' |
177 'U in_state US, US name USN, ' |
191 'U in_state US, US name USN, ' |
178 'U primary_email UA?, UA address UAA, ' |
192 'U primary_email UA?, UA address UAA, ' |
179 'U cw_source UDS, US name UDSN') |
193 'U cw_source UDS, US name UDSN') |
180 title = _('users and groups management') |
194 |
|
195 def call(self, **kwargs): |
|
196 add_button(self, 'CWUser') |
|
197 self.w(u'<div class="clear"></div>') |
|
198 self.wview('cw.users-table', self._cw.execute(self.rql)) |
|
199 |
|
200 |
|
201 class CWGroupsManagementView(StartupView): |
|
202 __regid__ = 'cw.groups-management' |
|
203 __select__ = StartupView.__select__ & match_user_groups('managers') |
181 cache_max_age = 0 # disable caching |
204 cache_max_age = 0 # disable caching |
182 |
205 rql = ('Any G,COUNT(U), GN GROUPBY G,GN ORDERBY GN ' |
183 def call(self, **kwargs): |
206 'WHERE G is CWGroup, U? in_group G, G name GN, NOT G name "owners"') |
184 self.w('<h1>%s</h1>' % self._cw._(self.title)) |
207 headers = [None, None] |
185 for etype in ('CWUser', 'CWGroup'): |
208 cellvids = {} |
186 eschema = self._cw.vreg.schema.eschema(etype) |
209 |
187 if eschema.has_perm(self._cw, 'add'): |
210 def call(self, **kwargs): |
188 self.w(u'<a href="%s" class="addButton right">%s</a>' % ( |
211 add_button(self, 'CWGroup') |
189 self._cw.build_url('add/%s' % eschema), |
|
190 self._cw.__('New %s' % etype).capitalize())) |
|
191 self.w(u'<div class="clear"></div>') |
212 self.w(u'<div class="clear"></div>') |
192 self.wview('cw.user-table', self._cw.execute(self.rql)) |
213 self.wview('editable-table', self._cw.execute(self.rql), |
193 |
214 headers=self.headers, cellvids=self.cellvids) |
194 |
215 |
195 class CWUserTable(tableview.EditableTableView): |
216 |
196 __regid__ = 'cw.user-table' |
217 def add_button(self, etype): |
|
218 eschema = self._cw.vreg.schema.eschema(etype) |
|
219 if eschema.has_perm(self._cw, 'add'): |
|
220 self.w(u'<a href="%s" class="addButton right">%s</a>' % ( |
|
221 self._cw.build_url('add/%s' % eschema), |
|
222 self._cw.__('New %s' % etype).capitalize())) |
|
223 |
|
224 |
|
225 class CWUsersTable(tableview.EditableTableView): |
|
226 __regid__ = 'cw.users-table' |
197 __select__ = is_instance('CWUser') |
227 __select__ = is_instance('CWUser') |
198 |
228 |
199 def call(self, **kwargs): |
229 def call(self, **kwargs): |
200 headers = (display_name(self._cw, 'CWUser', 'plural'), |
230 headers = (display_name(self._cw, 'CWUser', 'plural'), |
201 display_name(self._cw, 'in_state'), |
231 display_name(self._cw, 'in_state'), |
202 self._cw._('firstname'), self._cw._('surname'), |
232 self._cw._('firstname'), self._cw._('surname'), |
203 display_name(self._cw, 'CWGroup', 'plural'), |
233 display_name(self._cw, 'CWGroup', 'plural'), |
204 display_name(self._cw, 'primary_email'), |
234 display_name(self._cw, 'primary_email'), |
205 display_name(self._cw, 'CWSource')) |
235 display_name(self._cw, 'CWSource')) |
206 super(CWUserTable, self).call( |
236 super(CWUsersTable, self).call( |
207 paginate=True, displayfilter=True, |
237 paginate=True, displayfilter=True, |
208 cellvids={0: 'cw.user.login', |
238 cellvids={0: 'cw.user.login', |
209 4: 'cw.user-table.group-cell'}, |
239 4: 'cw.users-table.group-cell'}, |
210 headers=headers, **kwargs) |
240 headers=headers, **kwargs) |
211 |
241 |
212 |
242 |
213 class CWUserGroupCell(EntityView): |
243 class CWUserGroupCell(EntityView): |
214 __regid__ = 'cw.user-table.group-cell' |
244 __regid__ = 'cw.users-table.group-cell' |
215 __select__ = is_instance('CWUser') |
245 __select__ = is_instance('CWUser') |
216 |
246 |
217 def cell_call(self, row, col, **kwargs): |
247 def entity_call(self, entity, **kwargs): |
218 entity = self.cw_rset.get_entity(row, col) |
|
219 self.w(entity.view('reledit', rtype='in_group', role='subject')) |
248 self.w(entity.view('reledit', rtype='in_group', role='subject')) |
|
249 |
220 |
250 |
221 class CWUserLoginCell(EntityView): |
251 class CWUserLoginCell(EntityView): |
222 __regid__ = 'cw.user.login' |
252 __regid__ = 'cw.user.login' |
223 __select__ = is_instance('CWUser') |
253 __select__ = is_instance('CWUser') |
224 |
254 |
225 def cell_call(self, row, col, **kwargs): |
255 def entity_call(self, entity, **kwargs): |
226 entity = self.cw_rset.get_entity(row, col) |
|
227 self.w(tags.a(entity.login, href=entity.absolute_url())) |
256 self.w(tags.a(entity.login, href=entity.absolute_url())) |