[Zope3-checkins] CVS: Zope3/src/zope/app/services - configure.zcml:1.40.2.1 role.py:1.6.2.1

Martijn Faassen m.faassen@vet.uu.nl
Mon, 23 Jun 2003 14:34:45 -0400


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

Modified Files:
      Tag: faassen-roleservice_confusion-branch
	configure.zcml role.py 
Log Message:
Work on the local role service. It still doesn't work..


=== Zope3/src/zope/app/services/configure.zcml 1.40 => 1.40.2.1 ===
--- Zope3/src/zope/app/services/configure.zcml:1.40	Sun Jun 22 16:23:26 2003
+++ Zope3/src/zope/app/services/configure.zcml	Mon Jun 23 14:34:44 2003
@@ -129,26 +129,22 @@
 
 <!-- Role Templates -->
 
-<content class="zope.app.services.role.RoleService">
+<content class="zope.app.services.role.LocalRoleService">
   <factory
-      id="RoleService"
+      id="LocalRoleService"
       permission="zope.ManageServices"
       />
   <require
       permission="zope.Security"
-      interface="zope.app.interfaces.security.IRoleService"
-      />
-  <require
-      permission="zope.ManageServices"
-      interface="zope.app.interfaces.container.IContainer"
+      interface="zope.app.interfaces.services.role.ILocalRoleService"
       />
 </content>
 
-<content class="zope.app.services.role.Role">
-  <factory />
+<content class="zope.app.services.role.LocalRoleData">
+  <factory id="zope.app.services.roledata" permission="zope.ManageServices" />
   <require
       permission="zope.Security"
-      interface="zope.app.interfaces.security.IRole"
+      interface="zope.app.interfaces.services.role.ILocalRoleData"
       />
 </content>
 


=== Zope3/src/zope/app/services/role.py 1.6 => 1.6.2.1 ===
--- Zope3/src/zope/app/services/role.py:1.6	Thu Jun  5 08:03:17 2003
+++ Zope3/src/zope/app/services/role.py	Mon Jun 23 14:34:44 2003
@@ -17,43 +17,69 @@
 $Id$
 """
 
+from zope.context import getWrapperData
+from zope.app.context import Wrapper
+from zope.app.interfaces.services.role import ILocalRoleData, ILocalRoleRegistration
 from persistence import Persistent
-from zope.app.security.registries.roleregistry import Role
-from zope.app.container.btree import BTreeContainer
-from zope.app.interfaces.security import IRoleService
+from zope.app.services.registration import NameComponentRegistry
+from zope.app.services.registration import ComponentRegistration
+from zope.app.services.registration import RegistrationStatusProperty
+from zope.app.interfaces.security import IRoleService, IRole
 from zope.app.interfaces.container import IContainer
 from zope.context import ContextMethod
 from zope.app.component.nextservice import getNextService
 from zope.app.interfaces.services.service import ISimpleService
 from zope.interface import implements
 
-class Role(Role, Persistent):
-    "Persistent Role"
+class LocalRoleData(Persistent):
+    implements(ILocalRoleData)
+    
+class LocalRoleDecorator(Wrapper):
+    implements(IRole)
+    
+    def getId(self):
+        return getWrapperData(self)['rid']
+
+    def getTitle(self):
+        return "%s title" % self.getId()
+
+    def getDescription(self):
+        return "%s description" % self.getId()
+
+class LocalRoleService(NameComponentRegistry):
+    
+    implements(IRoleService, ISimpleService)
 
-class ILocalRoleService(IRoleService, IContainer):
-    """TTW manageable role service"""
-
-class RoleService(BTreeContainer):
-
-    implements(ILocalRoleService, ISimpleService)
-
-    def getRole(wrapped_self, rid):
+    def getRole(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
+        roledata = self.queryActiveComponent(rid)
+        if roledata is not None:
+            return LocalRoleDecorator(roledata, self, rid=rid)
+        return getNextService(self, 'Roles').getRole(rid)
     getRole = ContextMethod(getRole)
 
-    def getRoles(wrapped_self):
+    def getRoles(self):
         '''See interface IRoleService'''
-        roles = list(wrapped_self.values())
-        roleserv = getNextService(wrapped_self, 'Roles')
-        if roleserv:
-            roles.extend(roleserv.getRoles())
-        return roles
+        result = {}
+        next = getNextService(self, 'Roles')
+        for role in next.getRoles():
+            result[role.getId()] = role
+        for rid in self.listRegistrationNames():
+            roledata = self.queryActiveComponent(rid)
+            if roledata is not None:
+                result[rid] = LocalRoleDecorator(roledata, self, rid=rid)
+        return result.values()
+    
     getRoles = ContextMethod(getRoles)
+
+class LocalRoleRegistration(ComponentRegistration):
+    implements(ILocalRoleRegistration)
+
+    serviceType = "Roles"
+
+    status = RegistrationStatusProperty()
+
+    def __init__(self, rid, component_path, permission=None):
+        ComponentRegistration.__init__(self, component_path, permission)
+        self.rid = rid
+