[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture - metaConfigure.py:1.4

Viktorija Zaksiene ryzaja@codeworks.lt
Mon, 25 Nov 2002 10:23:50 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv7564/ComponentArchitecture

Modified Files:
	metaConfigure.py 
Log Message:
Added check for undefined permissions on configuration time.


=== Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py:1.3	Tue Nov 19 18:15:14 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py	Mon Nov 25 10:23:20 2002
@@ -20,6 +20,7 @@
 from Zope.Configuration.Action import Action
 from Zope.Security.Checker \
      import InterfaceChecker, CheckerPublic, NamesChecker, Checker
+from Zope.App.Security.Registries.PermissionRegistry import permissionRegistry
 from Zope.ComponentArchitecture.GlobalServiceManager \
      import UndefinedService
 
@@ -32,14 +33,21 @@
 # But these services aren't placeful! And we need to get at things that
 # normal service clients don't need!   Jim
 
+
 def handler(serviceName, methodName, *args, **kwargs):
     method=getattr(getService(None, serviceName), methodName)
     method(*args, **kwargs)
-
+    
 # We can't use the handler for serviceType, because serviceType needs
 # the interface service.
 from Zope.App.ComponentArchitecture.InterfaceService import provideInterface
 
+def checkingHandler(permission=None, *args, **kw):
+    """Check if permission is defined"""
+    if permission is not None:
+        permissionRegistry.ensurePermissionDefined(permission)
+    handler(*args, **kw)
+
 def managerHandler(methodName, *args, **kwargs):
     method=getattr(getServiceManager(None), methodName)
     method(*args, **kwargs)
@@ -55,10 +63,11 @@
         checker = InterfaceChecker(provides, permission)
         factory.append(lambda c: Proxy(c, checker))
     actions=[
-         Action(
+        Action(
             discriminator = ('adapter', for_, provides),
-            callable = handler,
-            args = ('Adapters', 'provideAdapter', for_, provides, factory),
+            callable = checkingHandler,
+            args = (permission, 'Adapters', 'provideAdapter', 
+                    for_, provides, factory),
                ),
         Action(
             discriminator = None,
@@ -102,8 +111,9 @@
     return [
         Action(
             discriminator = ('utility', provides),
-            callable = handler,
-            args = ('Utilities', 'provideUtility', provides, component),
+            callable = checkingHandler,
+            args = (permission, 'Utilities', 'provideUtility',
+                    provides, component),
             ),
         Action(
             discriminator = None,
@@ -175,8 +185,8 @@
     return [
         Action(
             discriminator = ('resource', name, type, layer),
-            callable = handler,
-            args = ('Resources','provideResource',
+            callable = checkingHandler,
+            args = (permission, 'Resources','provideResource',
                     name, type, factory, layer),
             ),
         Action(
@@ -217,8 +227,9 @@
     actions=[
         Action(
             discriminator = ('view', for_, name, type, layer),
-            callable = handler,
-            args = ('Views','provideView',for_, name, type, factory, layer),
+            callable = checkingHandler,
+            args = (permission, 'Views','provideView', for_, name,
+                    type, factory, layer),
             ),
         Action(
             discriminator = None,