[Checkins] SVN: z3c.dobbin/trunk/src/z3c/dobbin/ For concrete classes, security is now inherited to the mapper.

Malthe Borch mborch at gmail.com
Sun Jun 8 19:20:19 EDT 2008


Log message for revision 87244:
  For concrete classes, security is now inherited to the mapper.

Changed:
  U   z3c.dobbin/trunk/src/z3c/dobbin/README.txt
  U   z3c.dobbin/trunk/src/z3c/dobbin/mapper.py

-=-
Modified: z3c.dobbin/trunk/src/z3c/dobbin/README.txt
===================================================================
--- z3c.dobbin/trunk/src/z3c/dobbin/README.txt	2008-06-08 16:20:32 UTC (rev 87243)
+++ z3c.dobbin/trunk/src/z3c/dobbin/README.txt	2008-06-08 23:20:17 UTC (rev 87244)
@@ -323,7 +323,30 @@
 elements to its list.
 
     >>> _ = create(ICollection)
+
+Security
+--------
+
+The security model from Zope is applied to mappers.
+
+    >>> from zope.security.checker import getCheckerForInstancesOf
+
+Our ``Vinyl`` class does not have a security checker defined.
     
+    >>> mapper = getMapper(Vinyl)
+    >>> getCheckerForInstancesOf(mapper) is None
+    True
+
+Let's set a checker and regenerate the mapper.
+
+    >>> from zope.security.checker import defineChecker, CheckerPublic
+    >>> defineChecker(Vinyl, CheckerPublic)
+    
+    >>> from z3c.dobbin.mapper import createMapper
+    >>> mapper = createMapper(Vinyl)
+    >>> getCheckerForInstancesOf(mapper) is CheckerPublic
+    True    
+    
 Known limitations
 -----------------
 

Modified: z3c.dobbin/trunk/src/z3c/dobbin/mapper.py
===================================================================
--- z3c.dobbin/trunk/src/z3c/dobbin/mapper.py	2008-06-08 16:20:32 UTC (rev 87243)
+++ z3c.dobbin/trunk/src/z3c/dobbin/mapper.py	2008-06-08 23:20:17 UTC (rev 87244)
@@ -4,7 +4,7 @@
 
 from zope.dottedname.resolve import resolve
 from zope.security.interfaces import IChecker
-from zope.security.checker import defineChecker
+from zope.security.checker import defineChecker, getCheckerForInstancesOf
 
 from interfaces import IMapper
 from interfaces import IMapped
@@ -293,6 +293,10 @@
         checker = component.queryAdapter(spec, IChecker)
         if checker is not None:
             defineChecker(Mapper, checker)
+    # if not, assign the checker from the specification to the mapper.
+    else:
+        checker = getCheckerForInstancesOf(spec)
+        defineChecker(Mapper, checker)
         
     # set class representation method if not defined
     if not isinstance(Mapper.__repr__, types.MethodType):



More information about the Checkins mailing list