[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Security - protectClass.py:1.4

Jim Fulton jim@zope.com
Tue, 1 Oct 2002 08:48:20 -0400


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

Modified Files:
	protectClass.py 
Log Message:
Added the ability to provide permissions for setting selected
attributes.



=== Zope3/lib/python/Zope/App/Security/protectClass.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/Security/protectClass.py:1.3	Thu Jun 20 11:54:59 2002
+++ Zope3/lib/python/Zope/App/Security/protectClass.py	Tue Oct  1 08:47:50 2002
@@ -33,17 +33,35 @@
     
     checker = getCheckerForInstancesOf(class_)
     if checker is None:
-        checker = Checker({}.get)
+        checker = Checker({}.get, {}.get)
         defineChecker(class_, checker)
 
     if permission == 'Zope.Public':
         # Translate public permission to CheckerPublic
         permission = CheckerPublic
 
-    # OK, so it's a hack.
+    # We know a dictionart get method was used because we set it
     protections = checker.getPermission_func().__self__    
     protections[name] = permission
 
+def protectSetAttribute(class_, name, permission):
+    "Set a permission on a particular name."
+    
+    checkPermission(permission)
+    
+    checker = getCheckerForInstancesOf(class_)
+    if checker is None:
+        checker = Checker({}.get, {}.get)
+        defineChecker(class_, checker)
+
+    if permission == 'Zope.Public':
+        # Translate public permission to CheckerPublic
+        permission = CheckerPublic
+
+    # We know a dictionart get method was used because we set it
+    protections = checker.getSetattrPermission_func().__self__    
+    protections[name] = permission
+
 def protectLikeUnto(class_, like_unto):
     """Use the protections from like_unto for class_
     """
@@ -52,7 +70,7 @@
     if unto_checker is None:
         return
 
-    # OK, so it's a hack.
+    # We know a dictionart get method was used because we set it
     unto_protections = unto_checker.getPermission_func().__self__
     
     checker = getCheckerForInstancesOf(class_)