16 # import standard library |
16 # import standard library |
17 from datetime import datetime |
17 from datetime import datetime |
18 |
18 |
19 # import interfaces |
19 # import interfaces |
20 from pyams_security.interfaces import IUsersFolderPlugin, ISecurityManager, ILocalUser, IUserRegistrationInfo |
20 from pyams_security.interfaces import IUsersFolderPlugin, ISecurityManager, ILocalUser, IUserRegistrationInfo |
21 from pyams_security.zmi.interfaces import ISecurityManagerToolbarAddingMenu, ISecurityManagerMenu |
21 from pyams_security.zmi.interfaces import ISecurityManagerToolbarAddingMenu |
22 from pyams_skin.interfaces.viewlet import IMenuItem, IToolbarViewletManager |
22 from pyams_skin.interfaces.viewlet import IToolbarViewletManager |
23 from pyams_skin.interfaces import IPageHeader |
23 from pyams_skin.interfaces import IPageHeader |
24 from pyams_skin.layer import IPyAMSLayer |
24 from pyams_skin.layer import IPyAMSLayer |
25 from pyams_utils.interfaces.data import IObjectData |
|
26 from pyams_zmi.layer import IAdminLayer |
25 from pyams_zmi.layer import IAdminLayer |
27 from z3c.form.interfaces import DISPLAY_MODE, IDataExtractedEvent |
26 from z3c.form.interfaces import DISPLAY_MODE, IDataExtractedEvent |
28 from z3c.table.interfaces import IColumn |
27 from z3c.table.interfaces import IColumn |
29 from zope.component.interfaces import ISite |
28 from zope.component.interfaces import ISite |
30 from zope.dublincore.interfaces import IZopeDublinCore |
29 from zope.dublincore.interfaces import IZopeDublinCore |
34 from pyams_form.search import SearchView, SearchResultsView |
33 from pyams_form.search import SearchView, SearchResultsView |
35 from pyams_pagelet.pagelet import pagelet_config |
34 from pyams_pagelet.pagelet import pagelet_config |
36 from pyams_security.plugin.userfolder import UsersFolder, User |
35 from pyams_security.plugin.userfolder import UsersFolder, User |
37 from pyams_security.zmi.utility import SecurityManagerPluginsTable |
36 from pyams_security.zmi.utility import SecurityManagerPluginsTable |
38 from pyams_skin.skin import apply_skin |
37 from pyams_skin.skin import apply_skin |
39 from pyams_skin.viewlet.menu import MenuItem |
38 from pyams_skin.table import I18nColumn |
40 from pyams_skin.viewlet.toolbar import ToolbarMenuItem, ToolbarAction |
39 from pyams_skin.viewlet.toolbar import ToolbarMenuItem, ToolbarAction |
41 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
40 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter |
42 from pyams_utils.date import format_datetime |
41 from pyams_utils.date import format_datetime |
43 from pyams_utils.registry import query_utility |
42 from pyams_utils.registry import query_utility |
44 from pyams_utils.url import absolute_url |
43 from pyams_utils.url import absolute_url |
47 from pyams_zmi.view import AdminView |
46 from pyams_zmi.view import AdminView |
48 from pyramid.events import subscriber |
47 from pyramid.events import subscriber |
49 from pyramid.view import view_config |
48 from pyramid.view import view_config |
50 from z3c.form import field |
49 from z3c.form import field |
51 from z3c.table.column import GetAttrColumn |
50 from z3c.table.column import GetAttrColumn |
52 from zope.interface import implementer, Interface, Invalid |
51 from zope.interface import Invalid |
53 |
52 |
54 from pyams_security import _ |
53 from pyams_security import _ |
55 |
54 |
|
55 |
|
56 # |
|
57 # Users folder views |
|
58 # |
56 |
59 |
57 @viewlet_config(name='add-users-folder.menu', context=ISite, layer=IAdminLayer, |
60 @viewlet_config(name='add-users-folder.menu', context=ISite, layer=IAdminLayer, |
58 view=SecurityManagerPluginsTable, manager=ISecurityManagerToolbarAddingMenu, |
61 view=SecurityManagerPluginsTable, manager=ISecurityManagerToolbarAddingMenu, |
59 permission='system.manage', weight=10) |
62 permission='system.manage', weight=10) |
60 class UsersFolderAddMenu(ToolbarMenuItem): |
63 class UsersFolderAddMenu(ToolbarMenuItem): |
75 legend = _("Add local users folder plug-in") |
78 legend = _("Add local users folder plug-in") |
76 icon_css_class = 'fa fa-fw fa-user' |
79 icon_css_class = 'fa fa-fw fa-user' |
77 |
80 |
78 fields = field.Fields(IUsersFolderPlugin).omit('__name__', '__parent__') |
81 fields = field.Fields(IUsersFolderPlugin).omit('__name__', '__parent__') |
79 ajax_handler = 'add-users-folder.json' |
82 ajax_handler = 'add-users-folder.json' |
80 edit_permission = None |
83 edit_permission = 'system.manage' |
81 |
84 |
82 def create(self, data): |
85 def create(self, data): |
83 return UsersFolder() |
86 return UsersFolder() |
84 |
87 |
85 def add(self, plugin): |
88 def add(self, plugin): |
121 permission='system.manage', renderer='json', xhr=True) |
124 permission='system.manage', renderer='json', xhr=True) |
122 class UsersFolderAJAXEditForm(AJAXEditForm, UsersFolderEditForm): |
125 class UsersFolderAJAXEditForm(AJAXEditForm, UsersFolderEditForm): |
123 """Users folder plug-in edit form, AJAX handler""" |
126 """Users folder plug-in edit form, AJAX handler""" |
124 |
127 |
125 |
128 |
126 @adapter_config(name='security.menu', context=(IUsersFolderPlugin, IAdminLayer, Interface, ISecurityManagerMenu), |
129 # |
127 provides=IMenuItem) |
130 # Users folder search views |
128 @implementer(IObjectData) |
131 # |
129 class UsersFolderContentsMenu(MenuItem): |
|
130 """Users folder contents menu""" |
|
131 |
|
132 url = 'contents.html' |
|
133 object_data = {'ams-target': '#content'} |
|
134 |
|
135 @property |
|
136 def label(self): |
|
137 return self.context.title |
|
138 |
|
139 |
132 |
140 @pagelet_config(name='search.html', context=IUsersFolderPlugin, layer=IPyAMSLayer, permission='system.view') |
133 @pagelet_config(name='search.html', context=IUsersFolderPlugin, layer=IPyAMSLayer, permission='system.view') |
141 class UsersFolderSearchView(AdminView, SearchView): |
134 class UsersFolderSearchView(AdminView, SearchView): |
142 """Users folder search view""" |
135 """Users folder search view""" |
143 |
136 |
147 |
140 |
148 @adapter_config(context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchView), provides=IPageHeader) |
141 @adapter_config(context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchView), provides=IPageHeader) |
149 class UsersFolderSearchViewHeaderAdapter(ContextRequestViewAdapter): |
142 class UsersFolderSearchViewHeaderAdapter(ContextRequestViewAdapter): |
150 """Users folder search view header adapter""" |
143 """Users folder search view header adapter""" |
151 |
144 |
|
145 back_url = '#security-manager.html' |
152 icon_class = 'fa fa-fw fa-user' |
146 icon_class = 'fa fa-fw fa-user' |
153 |
147 |
154 @property |
148 @property |
155 def title(self): |
149 def title(self): |
156 return self.context.title |
150 return self.context.title |
172 apply_skin(self.request, 'PyAMS admin skin') |
166 apply_skin(self.request, 'PyAMS admin skin') |
173 |
167 |
174 |
168 |
175 @adapter_config(name='login', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
169 @adapter_config(name='login', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
176 provides=IColumn) |
170 provides=IColumn) |
177 class LoginColumn(GetAttrColumn): |
171 class LoginColumn(I18nColumn, GetAttrColumn): |
178 """Users login column""" |
172 """Users login column""" |
179 |
173 |
180 _header = _("Login") |
174 _header = _("Login") |
181 attrName = 'login' |
175 attrName = 'login' |
182 weight = 5 |
176 weight = 5 |
183 |
177 |
184 @property |
|
185 def header(self): |
|
186 return self.request.localizer.translate(self._header) |
|
187 |
|
188 |
178 |
189 @adapter_config(name='name', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
179 @adapter_config(name='name', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
190 provides=IColumn) |
180 provides=IColumn) |
191 class NameColumn(GetAttrColumn): |
181 class NameColumn(I18nColumn, GetAttrColumn): |
192 """Users name column""" |
182 """Users name column""" |
193 |
183 |
194 _header = _("Name") |
184 _header = _("Name") |
195 attrName = 'title' |
185 attrName = 'title' |
196 weight = 10 |
186 weight = 10 |
197 |
187 |
198 @property |
|
199 def header(self): |
|
200 return self.request.localizer.translate(self._header) |
|
201 |
|
202 |
188 |
203 @adapter_config(name='email', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
189 @adapter_config(name='email', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
204 provides=IColumn) |
190 provides=IColumn) |
205 class EmailColumn(GetAttrColumn): |
191 class EmailColumn(I18nColumn, GetAttrColumn): |
206 """Users email column""" |
192 """Users email column""" |
207 |
193 |
208 _header = _("E-mail address") |
194 _header = _("E-mail address") |
209 attrName = 'email' |
195 attrName = 'email' |
210 weight = 20 |
196 weight = 20 |
211 |
197 |
212 @property |
|
213 def header(self): |
|
214 return self.request.localizer.translate(self._header) |
|
215 |
|
216 |
198 |
217 @adapter_config(name='registration_date', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
199 @adapter_config(name='registration_date', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
218 provides=IColumn) |
200 provides=IColumn) |
219 class RegistrationDateColumn(GetAttrColumn): |
201 class RegistrationDateColumn(I18nColumn, GetAttrColumn): |
220 """Users registration date column""" |
202 """Users registration date column""" |
221 |
203 |
222 _header = _("Registration date") |
204 _header = _("Registration date") |
223 weight = 30 |
205 weight = 30 |
224 |
206 |
227 if dc is not None: |
209 if dc is not None: |
228 return format_datetime(dc.created) |
210 return format_datetime(dc.created) |
229 else: |
211 else: |
230 return '--' |
212 return '--' |
231 |
213 |
232 @property |
|
233 def header(self): |
|
234 return self.request.localizer.translate(self._header) |
|
235 |
|
236 |
214 |
237 @adapter_config(name='activation_date', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
215 @adapter_config(name='activation_date', context=(IUsersFolderPlugin, IAdminLayer, UsersFolderSearchResultsView), |
238 provides=IColumn) |
216 provides=IColumn) |
239 class ConfirmationDateColumn(GetAttrColumn): |
217 class ConfirmationDateColumn(I18nColumn, GetAttrColumn): |
240 """Users activation date column""" |
218 """Users activation date column""" |
241 |
219 |
242 _header = _("Activation date") |
220 _header = _("Activation date") |
243 weight = 40 |
221 weight = 40 |
244 |
222 |
246 if obj.activation_date: |
224 if obj.activation_date: |
247 return format_datetime(obj.activation_date) |
225 return format_datetime(obj.activation_date) |
248 else: |
226 else: |
249 return '--' |
227 return '--' |
250 |
228 |
251 @property |
229 |
252 def header(self): |
230 # |
253 return self.request.localizer.translate(self._header) |
231 # Users views |
254 |
232 # |
255 |
233 |
256 @viewlet_config(name='users-folder.toolbar.adding', context=IUsersFolderPlugin, |
234 @viewlet_config(name='users-folder.toolbar.adding', context=IUsersFolderPlugin, |
257 view=UsersFolderSearchView.search_form_factory, layer=IAdminLayer, |
235 view=UsersFolderSearchView.search_form_factory, layer=IAdminLayer, |
258 manager=IToolbarViewletManager, permission='system.manage') |
236 manager=IToolbarViewletManager, permission='system.manage') |
259 class UsersFolderAddAction(ToolbarAction): |
237 class LocalUserAddAction(ToolbarAction): |
260 """Users folder adding action""" |
238 """Users folder adding action""" |
261 |
239 |
262 label = _("Add user") |
240 label = _("Add user") |
263 url = 'add-user.html' |
241 url = 'add-user.html' |
264 modal_target = True |
242 modal_target = True |