[Checkins] SVN: z3c.password/trunk/ - Feature: ``passwordOptionsUtilityName`` property on the ``PrincipalMixIn``.

Adam Groszer agroszer at gmail.com
Thu Jul 2 05:32:39 EDT 2009


Log message for revision 101379:
  - Feature: ``passwordOptionsUtilityName`` property on the ``PrincipalMixIn``.
    This allows to set different options for a set of users instead of storing
    the direct values on the principal.

Changed:
  U   z3c.password/trunk/CHANGES.txt
  U   z3c.password/trunk/src/z3c/password/principal.py
  U   z3c.password/trunk/src/z3c/password/principal.txt

-=-
Modified: z3c.password/trunk/CHANGES.txt
===================================================================
--- z3c.password/trunk/CHANGES.txt	2009-07-02 09:19:46 UTC (rev 101378)
+++ z3c.password/trunk/CHANGES.txt	2009-07-02 09:32:38 UTC (rev 101379)
@@ -5,7 +5,9 @@
 0.8.0 (unreleased)
 ------------------
 
-- ...
+- Feature: ``passwordOptionsUtilityName`` property on the ``PrincipalMixIn``.
+  This allows to set different options for a set of users instead of storing
+  the direct values on the principal.
 
 
 0.7.0 (2009-06-22)

Modified: z3c.password/trunk/src/z3c/password/principal.py
===================================================================
--- z3c.password/trunk/src/z3c/password/principal.py	2009-07-02 09:19:46 UTC (rev 101378)
+++ z3c.password/trunk/src/z3c/password/principal.py	2009-07-02 09:32:38 UTC (rev 101379)
@@ -38,6 +38,8 @@
     disallowPasswordReuse = None
     previousPasswords = None
 
+    passwordOptionsUtilityName = None
+
     def _checkDisallowedPreviousPassword(self, password):
         if self._disallowPasswordReuse():
             if self.previousPasswords is not None:
@@ -160,6 +162,11 @@
         return self.passwordSetOn + expires
 
     def _optionsUtility(self):
+        if self.passwordOptionsUtilityName:
+            #if we have a utility name, then it must be there
+            return zope.component.getUtility(
+                interfaces.IPasswordOptionsUtility,
+                name=self.passwordOptionsUtilityName)
         return zope.component.queryUtility(
             interfaces.IPasswordOptionsUtility, default=None)
 

Modified: z3c.password/trunk/src/z3c/password/principal.txt
===================================================================
--- z3c.password/trunk/src/z3c/password/principal.txt	2009-07-02 09:19:46 UTC (rev 101378)
+++ z3c.password/trunk/src/z3c/password/principal.txt	2009-07-02 09:32:38 UTC (rev 101379)
@@ -58,6 +58,14 @@
   Previous (encoded) password stored when required for
   ``disallowPasswordReuse``
 
+- ``passwordOptionsUtilityName``
+
+  Allows to specify an IPasswordOptionsUtility name to look up instead of
+  the default. This utility must be registered otherwise there will be an
+  exception.
+  This allows to set different options for a set of users instead of storing
+  the direct values on the principal.
+
 There is the IPasswordOptionsUtility utility, with which you can provide
 options for some features.
 Strategy is that if the same option/property exists on the principal
@@ -653,7 +661,42 @@
   >>> user.setPassword('789789')
 
 
+``passwordOptionsUtilityName``
+------------------------------
 
+  >>> user = MyPrincipal('srichter', '123123', u'Stephan Richter')
+
+Until the property is None, the user will get the options from the default
+utility:
+
+  >>> user._optionsUtility() is poptions
+  True
+
+A wrong (that means the named utility is not registered) name causes an
+exception:
+
+  >>> user.passwordOptionsUtilityName = 'foobar'
+
+  >>> user._optionsUtility() is poptions
+  Traceback (most recent call last):
+  ...
+  ComponentLookupError: (<InterfaceClass z3c.password.interfaces.IPasswordOptionsUtility>, 'foobar')
+
+Providing a new utility with a name:
+
+  >>> namedOptions = PasswordOptionsUtility()
+  >>> zope.component.provideUtility(namedOptions, name='otherPasswordOptions')
+
+And setting the name on the user:
+
+  >>> user.passwordOptionsUtilityName = 'otherPasswordOptions'
+
+Works:
+
+  >>> user._optionsUtility() is namedOptions
+  True
+
+
 Edge cases
 ----------
 



More information about the Checkins mailing list