[Checkins] SVN: Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/ Add new ITypeConstructionFilter adapter hook to allow extra type construction filters to be defined.

Wichert Akkerman wichert at wiggy.net
Tue Jun 2 07:55:02 EDT 2009


Log message for revision 100585:
  Add new ITypeConstructionFilter adapter hook to allow extra type construction filters to be defined.
  

Changed:
  U   Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/CHANGES.txt
  U   Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/TypesTool.py
  U   Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/interfaces/_tools.py
  U   Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/tests/test_TypesTool.py

-=-
Modified: Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/CHANGES.txt
===================================================================
--- Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/CHANGES.txt	2009-06-02 11:48:42 UTC (rev 100584)
+++ Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/CHANGES.txt	2009-06-02 11:55:02 UTC (rev 100585)
@@ -4,6 +4,9 @@
 2.2.0 (unreleased)
 ------------------
 
+- Add new ITypeConstructionFilter adapter hook to allow extra type
+  construction filters to be defined.
+
 - Fixed typo in the acquisition wrapping of the found utility in
   getToolByName.
 

Modified: Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/TypesTool.py
===================================================================
--- Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/TypesTool.py	2009-06-02 11:48:42 UTC (rev 100584)
+++ Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/TypesTool.py	2009-06-02 11:55:02 UTC (rev 100585)
@@ -29,6 +29,7 @@
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from zope.app.container.contained import ObjectAddedEvent
 from zope.app.container.contained import notifyContainerModified
+from zope.component import getAdapters
 from zope.component import getUtility
 from zope.component import queryUtility
 from zope.component.interfaces import IFactory
@@ -45,6 +46,7 @@
 from Products.CMFCore.interfaces import IAction
 from Products.CMFCore.interfaces import ITypeInformation
 from Products.CMFCore.interfaces import ITypesTool
+from Products.CMFCore.interfaces import ITypeConstructionFilter
 from Products.CMFCore.permissions import AccessContentsInformation
 from Products.CMFCore.permissions import AddPortalContent
 from Products.CMFCore.permissions import ManagePortal
@@ -509,9 +511,14 @@
 
         if not ti_check:
             return False
-        else :
-            return self._checkWorkflowAllowed(container)
 
+        for name, filter in getAdapters((self, container), ITypeConstructionFilter):
+            if not filter.allowed():
+                return False
+
+        return self._checkWorkflowAllowed(container)
+
+
     security.declarePrivate('_constructInstance')
     def _constructInstance(self, container, id, *args, **kw):
         """Build a bare instance of the appropriate type.

Modified: Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/interfaces/_tools.py
===================================================================
--- Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/interfaces/_tools.py	2009-06-02 11:48:42 UTC (rev 100584)
+++ Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/interfaces/_tools.py	2009-06-02 11:55:02 UTC (rev 100585)
@@ -1436,7 +1436,25 @@
         Returns:  Method ID or default value
         """
 
+class ITypeConstructionFilter(Interface):
 
+    """ Extra content construction filters.
+    
+    This adapter adds filters that are in the tests done by the construction
+    logic in the types tool.
+
+    """
+
+    def __init__(fti, container):
+        """Adapt on the FTI of the new and the target container."""
+
+    def allowed():
+        """Check if construction is allowed.
+         
+        o Return True if creation of a new object is allowed.
+        """
+
+
 class ITypesTool(Interface):
 
     """ Register content types for the site.

Modified: Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/tests/test_TypesTool.py
===================================================================
--- Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/tests/test_TypesTool.py	2009-06-02 11:48:42 UTC (rev 100584)
+++ Products.CMFCore/branches/wichert-constructionfilter/Products/CMFCore/tests/test_TypesTool.py	2009-06-02 11:55:02 UTC (rev 100585)
@@ -468,6 +468,18 @@
     def test_isConstructionAllowed_w_Role(self):
         self.failUnless(self.ti.isConstructionAllowed(self.f))
 
+    def test_isConstructionAllowed_w_Filter(self):
+        from Products.CMFCore.interfaces import ITypeConstructionFilter
+        from zope.component import provideAdapter
+        class Block:
+            def __init__(self, fti, container):
+                pass
+            def allowed(self):
+                return False
+        provideAdapter(Block, (None, None), ITypeConstructionFilter, "test")
+        self.failIf(self.ti.isConstructionAllowed(self.f))
+
+
     def test_isConstructionAllowed_wo_Role(self):
         from AccessControl.SecurityManagement import newSecurityManager
         from Products.CMFCore.tests.base.security import UserWithRoles



More information about the Checkins mailing list