[Zope3-checkins] CVS: Zope3/src/zope/app/securitypolicy - role.py:1.3

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Mar 5 13:38:50 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/securitypolicy
In directory cvs.zope.org:/tmp/cvs-serv11176/src/zope/app/securitypolicy

Modified Files:
	role.py 
Log Message:


Global and local roles are implemented quiet differently now. Both are in this
module. Also, we need a special registration for the local role, since the id
of the role needs to be set upon activation.




=== Zope3/src/zope/app/securitypolicy/role.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/role.py:1.2	Wed Mar  3 05:38:51 2004
+++ Zope3/src/zope/app/securitypolicy/role.py	Fri Mar  5 13:38:49 2004
@@ -11,51 +11,53 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
+"""Role implementation
+
 $Id$
 """
-
 from persistence import Persistent
 from zope.interface import implements
-from zope.component import getService
 
-from zope.app.container.btree import BTreeContainer
-from zope.app.container.interfaces import IContainer
-from zope.app.component.nextservice import getNextService
-from zope.app.interfaces.services.service import ISimpleService
-
-from zope.app.securitypolicy.roleregistry import Role
-from zope.app.securitypolicy.interfaces import IRoleService
-
-class Role(Role, Persistent):
-    "Persistent Role"
-
-class ILocalRoleService(IRoleService, IContainer):
-    """TTW manageable role service"""
-
-class RoleService(BTreeContainer):
-
-    implements(ILocalRoleService, ISimpleService)
-
-    def getRole(wrapped_self, rid):
-        '''See interface IRoleService'''
-        try:
-            return wrapped_self[rid]
-        except KeyError:
-            # We failed locally: delegate to a higher-level service.
-            sv = getNextService(wrapped_self, 'Roles')
-            if sv:
-                return sv.getRole(rid)
-            raise # will be original Key Error
-
-    def getRoles(wrapped_self):
-        '''See interface IRoleService'''
-        roles = list(wrapped_self.values())
-        roleserv = getNextService(wrapped_self, 'Roles')
-        if roleserv:
-            roles.extend(roleserv.getRoles())
-        return roles
+from zope.app import zapi
+from zope.app.container.contained import Contained
+from zope.app.securitypolicy.interfaces import IRole
+from zope.app.services.utility import UtilityRegistration
+
+
+class Role(object):
+    implements(IRole)
+
+    def __init__(self, id, title, description=""):
+        self.id = id
+        self.title = title
+        self.description = description
+
+
+class PersistentRole(Contained, Persistent):
+    implements(IRole)
+
+    def __init__(self, title, description=""):
+        self.id = '<role not activated>'
+        self.title = title
+        self.description = description
+
+
+class RoleRegistration(UtilityRegistration):
+    """Role Registration
+
+    We have a custom registration here, since we want active registrations to
+    set the id of the role.
+    """
+    def activated(self):
+        role = self.getComponent()
+        role.id = self.name
+
+    def deactivated(self):
+        role = self.getComponent()
+        role.id = '<role not activated>'
+    
 
 def checkRole(context, role_id):
-    if not getService(context, 'Roles').getRole(role_id):
+    names = [name for name, util in zapi.getUtilitiesFor(context, IRole)]
+    if not role_id in names:
         raise ValueError("Undefined role id", role_id)




More information about the Zope3-Checkins mailing list