[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ContentDirective - ContentDirective.py:1.10

Jim Fulton jim@zope.com
Mon, 11 Nov 2002 15:13:50 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/ContentDirective
In directory cvs.zope.org:/tmp/cvs-serv14433

Modified Files:
	ContentDirective.py 
Log Message:
Added a schema_set attribute for the content require directive to
allow a permission for setting attributes defined by a schema to be
set. Any interface can be provided. Only fields in the interface are
used. Methods and other attributes are ignored.


=== Zope3/lib/python/Zope/App/ContentDirective/ContentDirective.py 1.9 => 1.10 ===
--- Zope3/lib/python/Zope/App/ContentDirective/ContentDirective.py:1.9	Wed Nov  6 17:30:21 2002
+++ Zope3/lib/python/Zope/App/ContentDirective/ContentDirective.py	Mon Nov 11 15:13:49 2002
@@ -27,6 +27,7 @@
     import protectLikeUnto, protectName, checkPermission, protectSetAttribute
 from Zope.Security.Proxy import ProxyFactory
 from Zope.Security.Checker import NamesChecker
+from Zope.Schema.IField import IField
 
 PublicPermission = 'Zope.Public'
 
@@ -63,7 +64,7 @@
 
     def require(self, _context,
                 permission=None, attributes=None, interface=None,
-                like_class=None, set_attributes=None):
+                like_class=None, set_attributes=None, set_schema=None):
         """Require a the permission to access a specific aspect"""
 
         if like_class:
@@ -71,7 +72,7 @@
         else:
             r = []
 
-        if not (interface or attributes or set_attributes):
+        if not (interface or attributes or set_attributes or set_schema):
             if r:
                 return r
             raise ConfigurationError("Nothing required")
@@ -86,6 +87,8 @@
             self.__protectNames(attributes, permission, r)
         if set_attributes:
             self.__protectSetAttributes(set_attributes, permission, r)
+        if set_schema:
+            self.__protectSetSchema(set_schema, permission, r)
 
 
         return r
@@ -129,6 +132,16 @@
             r.append((
                 ('protectSetAttribute', self.__class, name),
                 protectSetAttribute, (self.__class, name, permission_id)))
+            
+    def __protectSetSchema(self, schema, permission_id, r):
+        "Set a permission on a bunch of names."
+        schema = self.__context.resolve(schema)
+        for name in schema:
+            field = schema[name]
+            if IField.isImplementedBy(field):
+                r.append((
+                    ('protectSetAttribute', self.__class, name),
+                    protectSetAttribute, (self.__class, name, permission_id)))
 
 
     def __call__(self):