# HG changeset patch # User Damien Correia # Date 1524235956 -7200 # Node ID b156fba7e4fe7f69fea6d02264a44da52ca66bfd # Parent e8ebdd1417eaa3819d26ba6511bbc1e848b40a35# Parent 288ab38cdb567134d3faab63bc6c75317ccdf8ed merge default diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/shared/common/interfaces/__init__.py --- a/src/pyams_content/shared/common/interfaces/__init__.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/shared/common/interfaces/__init__.py Fri Apr 20 16:52:36 2018 +0200 @@ -84,6 +84,9 @@ containers(ISharedToolContainer) + shared_content_menu = Attribute("Boolean flag indicating if tool is displayed into 'Shared contents' or " + "Shared tools' menu") + shared_content_workflow = Choice(title=_("Workflow name"), description=_("Name of workflow utility used to manage tool contents"), vocabulary="PyAMS workflows", diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/shared/common/manager.py --- a/src/pyams_content/shared/common/manager.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/shared/common/manager.py Fri Apr 20 16:52:36 2018 +0200 @@ -58,6 +58,7 @@ title = FieldProperty(IBaseSharedTool['title']) short_name = FieldProperty(IBaseSharedTool['short_name']) + shared_content_menu = True shared_content_workflow = FieldProperty(IBaseSharedTool['shared_content_workflow']) diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/shared/common/security.py --- a/src/pyams_content/shared/common/security.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/shared/common/security.py Fri Apr 20 16:52:36 2018 +0200 @@ -22,7 +22,7 @@ # import packages from persistent import Persistent -from pyams_security.interfaces import IPrincipalInfo, IRevokedRoleEvent +from pyams_security.interfaces import IPrincipalInfo, IRevokedRoleEvent, IGrantedRoleEvent from pyams_utils.adapter import adapter_config, ContextAdapter from pyams_utils.request import check_request from pyams_utils.traversing import get_parent @@ -94,13 +94,22 @@ del restrictions_folder[principal] -@subscriber(IRevokedRoleEvent) +@subscriber(IGrantedRoleEvent, role_selector=MANAGER_ROLE) +def handle_added_manager_role(event): + """Handle added manager role""" + shared_tool = event.object.__parent__ + manager_restrictions = IManagerRestrictions(shared_tool, None) + if manager_restrictions: + restrictions = IManagerRestrictionsFactory(shared_tool)(event.principal_id) + manager_restrictions.set_restrictions(event.principal_id, restrictions) + + +@subscriber(IRevokedRoleEvent, role_selector=MANAGER_ROLE) def handle_revoked_manager_role(event): """Handle revoked manager role""" - if event.role_id == MANAGER_ROLE: - restrictions = IManagerRestrictions(event.object.__parent__, None) - if restrictions: - restrictions.drop_restrictions(event.principal_id) + restrictions = IManagerRestrictions(event.object.__parent__, None) + if restrictions: + restrictions.drop_restrictions(event.principal_id) @adapter_config(context=IWfSharedContent, provides=IManagerRestrictions) diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/shared/common/zmi/security.py --- a/src/pyams_content/shared/common/zmi/security.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/shared/common/zmi/security.py Fri Apr 20 16:52:36 2018 +0200 @@ -191,7 +191,7 @@ @cached_property def principal_id(self): principal_id = self.request.params.get('principal_id') or \ - self.request.params.get('{0}{1}principal_id'.format(self.prefix, self.widgets.prefix)) + self.request.params.get('{0}widgets.principal_id'.format(self.prefix)) if not principal_id: raise NotFound return principal_id diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/shared/form/manager.py --- a/src/pyams_content/shared/form/manager.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/shared/form/manager.py Fri Apr 20 16:52:36 2018 +0200 @@ -37,6 +37,7 @@ """Forms manager class""" shared_content_type = FORM_CONTENT_TYPE + shared_content_menu = False @utility_config(provides=IFormsManagerFactory) diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/shared/imagemap/manager.py --- a/src/pyams_content/shared/imagemap/manager.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/shared/imagemap/manager.py Fri Apr 20 16:52:36 2018 +0200 @@ -37,6 +37,7 @@ """Image maps manager class""" shared_content_type = IMAGEMAP_CONTENT_TYPE + shared_content_menu = False @utility_config(provides=IImageMapManagerFactory) diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/shared/logo/manager.py --- a/src/pyams_content/shared/logo/manager.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/shared/logo/manager.py Fri Apr 20 16:52:36 2018 +0200 @@ -37,6 +37,7 @@ """Logos manager class""" shared_content_type = LOGO_CONTENT_TYPE + shared_content_menu = False @utility_config(provides=ILogosManagerFactory) diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/shared/view/manager.py --- a/src/pyams_content/shared/view/manager.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/shared/view/manager.py Fri Apr 20 16:52:36 2018 +0200 @@ -38,6 +38,7 @@ """Views manager class""" shared_content_type = VIEW_CONTENT_TYPE + shared_content_menu = False @utility_config(provides=IViewsManagerFactory) diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/skin/zmi/viewlet/toplinks/__init__.py --- a/src/pyams_content/skin/zmi/viewlet/toplinks/__init__.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/skin/zmi/viewlet/toplinks/__init__.py Fri Apr 20 16:52:36 2018 +0200 @@ -57,20 +57,41 @@ self.viewlets.append(menu) -@viewlet_config(name='shared-tools.menu', layer=IAdminLayer, manager=ITopLinksViewletManager, weight=30) -class SharedToolsMenu(TopLinksViewlet): - """Shared tools menu""" +@viewlet_config(name='shared-contents.menu', layer=IAdminLayer, manager=ITopLinksViewletManager, weight=30) +class SharedContentsMenu(TopLinksViewlet): + """Shared contents menu""" label = '' css_class = 'top-menu bordered margin-top-10' dropdown_label = _("Shared contents") def update(self): + super(SharedContentsMenu, self).update() + registry = get_local_registry() + for tool in sorted(registry.getAllUtilitiesRegisteredFor(IBaseSharedTool), + key=lambda x: II18n(x).query_attribute('title', request=self.request) or ''): + if ISharedSite.providedBy(tool) or (not tool.shared_content_menu): + continue + menu = TopLinksMenu(self.context, self.request, self.__parent__, self) + menu.label = II18n(tool).query_attribute('title', request=self.request) or tool.__name__ + menu.url = absolute_url(tool, self.request, 'admin#dashboard.html') + self.viewlets.append(menu) + + +@viewlet_config(name='shared-tools.menu', layer=IAdminLayer, manager=ITopLinksViewletManager, weight=40) +class SharedToolsMenu(TopLinksViewlet): + """Shared tools menu""" + + label = '' + css_class = 'top-menu bordered margin-top-10' + dropdown_label = _("Shared tools") + + def update(self): super(SharedToolsMenu, self).update() registry = get_local_registry() for tool in sorted(registry.getAllUtilitiesRegisteredFor(IBaseSharedTool), key=lambda x: II18n(x).query_attribute('title', request=self.request) or ''): - if ISharedSite.providedBy(tool): + if ISharedSite.providedBy(tool) or tool.shared_content_menu: continue menu = TopLinksMenu(self.context, self.request, self.__parent__, self) menu.label = II18n(tool).query_attribute('title', request=self.request) or tool.__name__ diff -r e8ebdd1417ea -r b156fba7e4fe src/pyams_content/workflow/notify.py --- a/src/pyams_content/workflow/notify.py Thu Apr 12 11:44:04 2018 +0200 +++ b/src/pyams_content/workflow/notify.py Fri Apr 20 16:52:36 2018 +0200 @@ -61,20 +61,21 @@ notified_roles = self.context.user_data['transition'].user_data['notify_roles'] if '*' in notified_roles: return {} + notification_source = self.context.context principals = set() - for context in lineage(self.context.context): + for context in lineage(notification_source): protection = IProtectedObject(context, None) if protection is not None: for role_id in notified_roles: for principal in protection.get_principals(role_id): if role_id == MANAGER_ROLE: - if principal in self.context.context.managers: + if principal in notification_source.managers: principals.add(principal) else: - restrictions = IManagerRestrictions(self.context.context, None) + restrictions = IManagerRestrictions(notification_source, None) if restrictions is not None: principal_restrictions = restrictions.get_restrictions(principal) - if principal_restrictions.check_access(self.context.context, + if principal_restrictions.check_access(notification_source, MANAGE_CONTENT_PERMISSION): principals.add(principal) else: