src/pyams_content/shared/common/interfaces/__init__.py
changeset 0 7c0001cacf8e
child 11 20bb3019612a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/common/interfaces/__init__.py	Thu Oct 08 13:37:29 2015 +0200
@@ -0,0 +1,196 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+from pyams_utils.schema import TextLineListField
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.interfaces import IBaseContent, MANAGE_CONTENT_PERMISSION
+from pyams_content.root.interfaces import ISiteRoot
+from pyams_workflow.interfaces import IWorkflowManagedContent
+from zope.container.interfaces import IContainer
+
+# import packages
+from pyams_i18n.schema import I18nTextField
+from pyams_security.schema import Principal, PrincipalsSet
+from zope.container.constraints import containers, contains
+from zope.interface import Interface, Attribute
+from zope.schema import Choice, Bool, Text, Datetime
+
+from pyams_content import _
+
+
+class ISharedToolContainer(IBaseContent, IContainer):
+    """Shared tools container"""
+
+    containers(ISiteRoot)
+    contains('.ISharedTool')
+
+
+class ISharedTool(IBaseContent, IContainer):
+    """Shared tool interface"""
+
+    containers(ISharedToolContainer)
+    contains('.ISharedData')
+
+    shared_content_type = Attribute("Shared data content type")
+    shared_content_factory = Attribute("Shared data factory")
+
+    shared_content_workflow = Choice(title=_("Workflow name"),
+                                     description=_("Name of workflow utility used to manage tool contents"),
+                                     vocabulary="PyAMS workflows",
+                                     default="PyAMS default workflow")
+
+
+class ISharedToolRoles(Interface):
+    """Shared tool roles interface"""
+
+    webmasters = PrincipalsSet(title=_("Webmasters"),
+                               description=_("Webmasters can handle all contents, including published ones"),
+                               role_id='pyams.Webmaster',
+                               required=False)
+
+    pilots = PrincipalsSet(title=_("Pilots"),
+                           description=_("Pilots can handle tool configuration, manage access rules, grant users "
+                                         "roles and manage managers restrictions"),
+                           role_id='pyams.Pilot',
+                           required=False)
+
+    managers = PrincipalsSet(title=_("Managers"),
+                             description=_("Managers can handle main operations in tool's workflow, like publish "
+                                           "or retire contents"),
+                             role_id='pyams.Manager',
+                             required=False)
+
+    contributors = PrincipalsSet(title=_("Contributors"),
+                                 description=_("Contributors are users which are allowed to create new contents"),
+                                 role_id='pyams.Contributor',
+                                 required=False)
+
+
+class IWfSharedContent(IBaseContent):
+    """Shared content interface"""
+
+    content_type = Attribute("Content data type")
+    content_name = Attribute("Content name")
+
+    creator = Principal(title=_("Version creator"),
+                        description=_("Name of content's version creator. "
+                                      "The creator of the first version is also it's owner."),
+                        required=True)
+
+    first_owner = Principal(title=_("First owner"),
+                            description=_("Name of content's first version owner"),
+                            required=True,
+                            readonly=True)
+
+    modifiers = PrincipalsSet(title=_("Version modifiers"),
+                              description=_("List of principals who modified this content"),
+                              required=False)
+
+    description = I18nTextField(title=_("Description"),
+                                description=_("The content's description is 'hidden' into HTML's page headers; but it "
+                                              "can be seen, for example, in some search engines results as content's "
+                                              "description"),
+                                required=False)
+
+    keywords = TextLineListField(title=_("Keywords"),
+                                 description=_("They will be included into HTML pages metadata"),
+                                 required=False)
+
+    notepad = Text(title=_("Notepad"),
+                   description=_("Internal information to be known about this content"),
+                   required=False)
+
+
+class IWfSharedContentRoles(Interface):
+    """Shared content roles"""
+
+    owner = PrincipalsSet(title=_("Content owner"),
+                          description=_("The owner is the creator of content's first version, except if it was "
+                                        "transferred afterwards to another owner"),
+                          role_id='pyams.Owner',
+                          required=True,
+                          max_length=1)
+
+    managers = PrincipalsSet(title=_("Managers"),
+                             description=_("Managers can handle main operations in tool's workflow, like publish "
+                                           "or retire contents"),
+                             role_id='pyams.Manager',
+                             required=False)
+
+    contributors = PrincipalsSet(title=_("Contributors"),
+                                 description=_("Contributors are users which are allowed to update this content in "
+                                               "addition to it's owner"),
+                                 role_id='pyams.Contributor',
+                                 required=False)
+
+    readers = PrincipalsSet(title=_("Readers"),
+                            description=_("Readers are users which are asked to verify and comment contents before "
+                                          "they are published"),
+                            role_id='pyams.Reader',
+                            required=False)
+
+    guests = PrincipalsSet(title=_("Guests"),
+                           description=_("Guests are users which are allowed to view contents with restricted access"),
+                           role_id='pyams.Guest',
+                           required=False)
+
+
+class ISharedContent(IWorkflowManagedContent):
+    """Workflow managed shared content interface"""
+
+
+#
+# Shared tool manager security restrictions
+#
+
+MANAGER_RESTRICTIONS_KEY = 'pyams_content.manager.restrictions'
+
+
+class IManagerRestrictionInfo(Interface):
+    """Shared content manager restrictions"""
+
+    principal_id = Principal(title=_("Principal ID"),
+                             required=True)
+
+    restriction_interface = Attribute("Restrictions interface")
+
+    restricted_contents = Bool(title=_("Restricted contents"),
+                               description=_("If 'yes', this manager will get restricted access to manage contents "
+                                             "based on selected settings"),
+                               required=False,
+                               default=True)
+
+    owners = PrincipalsSet(title=_("Selected owners"),
+                           description=_("Manager will have access to contents owned by these principals"),
+                           required=False)
+
+    def check_access(self, context, permission=MANAGE_CONTENT_PERMISSION, request=None):
+        """Check if principal is granted access to given content"""
+
+
+class IManagerRestrictionsFactory(Interface):
+    """Manager restrictions factory interface"""
+
+
+class IManagerRestrictions(Interface):
+    """Manager restrictions"""
+
+    def get_restrictions(self, principal):
+        """Get manager restrictions for given principal"""
+
+    def set_restrictions(self, principal, restrictions):
+        """Set manager restrictions for given principal"""