[Zope3-checkins] SVN: Zope3/trunk/ Added support for removing a principal from a principal registry. We're using this to update principal info (via replace) for a management tool that lets an admin change his or her login/password without reprocessing ZCML.

Garrett Smith garrett at mojave-corp.com
Fri Mar 11 12:43:25 EST 2005


Log message for revision 29445:
  Added support for removing a principal from a principal registry. We're using this to update principal info (via replace) for a management tool that lets an admin change his or her login/password without reprocessing ZCML.

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/security/principalregistry.py
  U   Zope3/trunk/src/zope/app/security/tests/test_principalregistry.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-03-11 17:25:03 UTC (rev 29444)
+++ Zope3/trunk/doc/CHANGES.txt	2005-03-11 17:43:24 UTC (rev 29445)
@@ -9,7 +9,7 @@
   Some future release (Zope X3 3.1.0)
 
     New features
-    
+
       - zope.app.form.utility setUpEditWidgets, when given a source
         that is security proxied and asked to set up edit widgets
         for fields that will raise Unauthorized when set, now raises
@@ -24,9 +24,9 @@
 
         Added a layer argument to the menu directives and made sure that all
         browser directives specify the layer for the menu directives.
-    
-      - Implemented issue 292: Add factory to browser:resource directive 
 
+      - Implemented issue 292: Add factory to browser:resource directive
+
       - Implemented issue 309: <schemadisplay> should support <widget>
 
       - Developed a generic browser:form directive. It is pretty much the same
@@ -34,7 +34,7 @@
         on some context or adapted context but sent as a dictionary to special
         method (by default). By default these methods are named `getData()` and
         `setData(data)`.
- 
+
       - When raising the Unauthorized exception, the security checker
         now passes the object in question in addition to the attribute
         name and missing permission.  This should make debugging easier.
@@ -301,6 +301,11 @@
         zope.app.container.constraints.containers) that greatly simplify
         expressing containment constraints.
 
+      - Added `removePrincipal` to the principal registry. The applications for
+        this are pretty limited, but it can be used to replace a ZCML-defined
+        principal in the event its login or password has changed (e.g. when
+        using a GUI management tool, etc.)
+
     Restructuring
 
       - Applied changes suggested in issue 339: Improvements to generated forms
@@ -318,7 +323,7 @@
 
         Deprecated `zope:defaultView` directive and removed unused default
         view handler in `zope.app.publisher.browser.viewmeta`. Added a `layer`
-        attribute to the `browser:defaultView` directive. 
+        attribute to the `browser:defaultView` directive.
 
       - zope.component.createObject no longer accepts a positional
         context argument.  A context can be provided as a keyword argument.
@@ -505,18 +510,18 @@
 
     Bug Fixes
 
-      - Fixed issue #345: Using response.write should not involve unicode 
+      - Fixed issue #345: Using response.write should not involve unicode
                           conversion
 
       - Fixed issue #371: OrderedMultiSelectWidget ignores setRenderedValue
 
       - Fixed issue #360: MultiSelectWidget configured for ISet but creates
                           list
-                          
+
         The correct type of the collection field is now discovered and used.
 
-      - Addressed issue #348: ZCML hides import errors 
- 
+      - Addressed issue #348: ZCML hides import errors
+
         I tried really hard to get a better error message, but it is not
         possible, so I just prepended "ImportError:" to the error message.
 

Modified: Zope3/trunk/src/zope/app/security/principalregistry.py
===================================================================
--- Zope3/trunk/src/zope/app/security/principalregistry.py	2005-03-11 17:25:03 UTC (rev 29444)
+++ Zope3/trunk/src/zope/app/security/principalregistry.py	2005-03-11 17:43:24 UTC (rev 29445)
@@ -106,6 +106,11 @@
 
         return p
 
+    def removePrincipal(self, id):
+        p = self.__principalsById[id]
+        del self.__principalsById[id]
+        del self.__principalsByLogin[p.getLogin()]
+
     def registerGroup(self, group):
         id = group.id
         if id in self.__principalsById or id == self.__defaultid:
@@ -167,4 +172,4 @@
 class EverybodyGroup(Group):
 
     implements(interfaces.IEveryoneGroup)
-    
+

Modified: Zope3/trunk/src/zope/app/security/tests/test_principalregistry.py
===================================================================
--- Zope3/trunk/src/zope/app/security/tests/test_principalregistry.py	2005-03-11 17:25:03 UTC (rev 29444)
+++ Zope3/trunk/src/zope/app/security/tests/test_principalregistry.py	2005-03-11 17:43:24 UTC (rev 29445)
@@ -147,7 +147,25 @@
         self.assertRaises(DuplicateId, self.reg.definePrincipal,
                           "anybody", "title")
 
+    def testRemovePrincipal(self):
+        p = self.reg.definePrincipal('3', 'Frank', 'Frank Popp', 'frank', '321')
+        self.assert_(p is self.reg.getPrincipal('3'))
+        self.assert_(p is self.reg.getPrincipalByLogin('frank'))
+        self.reg.removePrincipal('3')
+        try:
+            self.reg.getPrincipal('3')
+        except KeyError:
+            pass
+        else:
+            self.fail()
+        try:
+            self.reg.getPrincipalByLogin('frank')
+        except KeyError:
+            pass
+        else:
+            self.fail()
 
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(Test),



More information about the Zope3-Checkins mailing list