Added portlet settings permission checker
authorThierry Florac <thierry.florac@onf.fr>
Fri, 15 Jun 2018 15:37:41 +0200
changeset 112 cba761272ab8
parent 111 39373f182ee4
child 113 1e56d5e23150
Added portlet settings permission checker
src/pyams_portal/portlet.py
--- a/src/pyams_portal/portlet.py	Fri Jun 15 14:32:43 2018 +0200
+++ b/src/pyams_portal/portlet.py	Fri Jun 15 15:37:41 2018 +0200
@@ -19,8 +19,6 @@
 
 import venusian
 
-from inspect import isclass
-
 # import interfaces
 from pyams_form.interfaces.form import IFormContextPermissionChecker
 from pyams_portal.interfaces import IPortlet, IPortletSettings, IPortletConfiguration, IPortletPreviewer, \
@@ -32,7 +30,7 @@
 from persistent import Persistent
 from persistent.mapping import PersistentMapping
 from pyams_utils.adapter import adapter_config, ContextAdapter, get_adapter_weight, get_annotation_adapter
-from pyams_utils.factory import get_object_factory
+from pyams_utils.factory import get_object_factory, is_interface
 from pyams_utils.request import check_request
 from pyams_utils.vocabulary import vocabulary_config
 from pyams_viewlet.viewlet import ViewContentProvider
@@ -219,7 +217,7 @@
 
     __name__ = '++settings++'
 
-    def __init__(self, configuration):
+    def __init__(self, configuration=None):
         self.__parent__ = configuration
 
     @property
@@ -256,6 +254,18 @@
     def configuration(self):
         return self.__parent__
 
+    @configuration.setter
+    def configuration(self, value):
+        if self.__parent__ is None:
+            self.__parent__ = value
+
+
+@adapter_config(context=IPortletSettings, provides=IFormContextPermissionChecker)
+class PortletSettingsPermissionChecker(ContextAdapter):
+    """Portlet settings permission checker"""
+
+    edit_permission = MANAGE_TEMPLATE_PERMISSION
+
 
 @adapter_config(context=IPortletSettings, provides=IPortletRendererSettings)
 def portlet_renderer_settings_adapter(context):
@@ -285,10 +295,12 @@
     def __init__(self, portlet):
         self.portlet_name = portlet.name
         factory = portlet.settings_factory
-        if isclass(factory) and issubclass(factory, Interface):
+        if is_interface(factory):
             factory = get_object_factory(factory)
         assert factory is not None, "Missing portlet settings factory"
-        self._settings = factory(self)
+        settings = factory()
+        settings.configuration = self
+        self._settings = settings
 
     @property
     def can_inherit(self):
@@ -359,9 +371,7 @@
 class PortletConfigurationPermissionChecker(ContextAdapter):
     """Portlet configuration permission checker"""
 
-    @property
-    def edit_permission(self):
-        return MANAGE_TEMPLATE_PERMISSION
+    edit_permission = MANAGE_TEMPLATE_PERMISSION
 
 
 #