merge default doc-dc
authorDamien Correia
Fri, 20 Apr 2018 16:52:36 +0200
branchdoc-dc
changeset 648 b156fba7e4fe
parent 647 e8ebdd1417ea (current diff)
parent 531 288ab38cdb56 (diff)
child 649 06ab962b04c5
merge default
--- 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",
--- 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'])
 
 
--- 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)
--- 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
--- 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)
--- 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)
--- 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)
--- 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)
--- 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__
--- 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: