[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - PrincipalPermissionView.py:1.1.2.4.4.1 PrincipalRegistry.py:1.1.2.14.14.1 PrincipalRoleView.py:1.1.2.5.4.1 RolePermissionView.py:1.1.2.10.4.1 Zope3RoleManagement.py:1.1.2.2.14.1 ZopeSecurityPolicy.py:1.1.2.26.8.1

Jim Fulton jim@zope.com
Wed, 29 May 2002 11:10:17 -0400


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

Modified Files:
      Tag: Zope3InWonderland-branch
	PrincipalPermissionView.py PrincipalRegistry.py 
	PrincipalRoleView.py RolePermissionView.py 
	Zope3RoleManagement.py ZopeSecurityPolicy.py 
Log Message:
- Added permission_id attribute to adapter and utility directives.

- Got rid of old getView, getResource, and getDefaultViewName.
  Renamed getRequestView to getView (and so on).

  Changed view interface to use context, rather than getContext.

  Introduced notion of presentation types (e.g. IBrowserPresentation, 
  which is cleaner than IBrowserPublisher).

- Began converting to get/queryFoo, which is much nicer.

- Many formatting fixups.



=== Zope3/lib/python/Zope/App/Security/PrincipalPermissionView.py 1.1.2.4 => 1.1.2.4.4.1 ===
 
 from Zope.App.PageTemplate import ViewPageTemplateFile
-from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
+from Zope.Publisher.Browser.BrowserView import BrowserView
 from Zope.ComponentArchitecture.ContextDependent import ContextDependent
 from Zope.ComponentArchitecture import getService, getAdapter
 from IPrincipalPermissionMap import IPrincipalPermissionMap
 from IPrincipalPermissionManager import IPrincipalPermissionManager
 from Settings import Allow, Deny, Unset
 
-class PrincipalPermissionView(AttributePublisher, ContextDependent):
+class PrincipalPermissionView(BrowserView):
 
     index = ViewPageTemplateFile('pt/principal_permission_edit.pt')
 
     def get_permission_service(self):
-        return getService(self.getContext(), 'PermissionService')
+        return getService(self.context, 'PermissionService')
 
     def get_principal(self, principal_id):
-        return getService(self.getContext(),
+        return getService(self.context,
                           'AuthenticationService'
                           ).getPrincipal(principal_id)
 
@@ -41,7 +41,7 @@
         """Form action unsetting a principals permissions"""
         permission_service = self.get_permission_service()
         principal = self.get_principal(principal_id)
-        ppm = getAdapter(self.getContext(), IPrincipalPermissionManager)
+        ppm = getAdapter(self.context, IPrincipalPermissionManager)
 
         for perm_id in permission_ids:
             permission = permission_service.getPermission(perm_id)
@@ -55,7 +55,7 @@
         """Form action granting a list of permissions to a principal"""
         permission_service = self.get_permission_service()
         principal = self.get_principal(principal_id)
-        ppm = getAdapter(self.getContext(), IPrincipalPermissionManager)
+        ppm = getAdapter(self.context, IPrincipalPermissionManager)
 
         for perm_id in permission_ids:
             permission = permission_service.getPermission(perm_id)
@@ -68,7 +68,7 @@
         """Form action denying a list of permissions for a principal"""
         permission_service = self.get_permission_service()
         principal = self.get_principal(principal_id)
-        ppm = getAdapter(self.getContext(), IPrincipalPermissionManager)
+        ppm = getAdapter(self.context, IPrincipalPermissionManager)
 
         for perm_id in permission_ids:
             permission = permission_service.getPermission(perm_id)
@@ -81,9 +81,9 @@
     def getUnsetPermissionsForPrincipal(self, principal_id):
         """Returns all unset permissions for this principal"""
 
-        ppmap = getAdapter(self.getContext(), IPrincipalPermissionMap)
+        ppmap = getAdapter(self.context, IPrincipalPermissionMap)
         principal = self.get_principal(principal_id)
-        perm_serv = getService(self.getContext(), 'PermissionService')
+        perm_serv = getService(self.context, 'PermissionService')
         result = []
         for perm in perm_serv.getPermissions():
             if ppmap.getSetting(perm, principal) == Unset:
@@ -98,7 +98,7 @@
            Return empty list if there are no permissions.
         """
     
-        ppmap = getAdapter(self.getContext(), IPrincipalPermissionMap)
+        ppmap = getAdapter(self.context, IPrincipalPermissionMap)
         principal = self.get_principal(principal_id)
         
         permission_settings = ppmap.getPermissionsForPrincipal(principal)


=== Zope3/lib/python/Zope/App/Security/PrincipalRegistry.py 1.1.2.14 => 1.1.2.14.14.1 ===
 from Zope.Exceptions import NotFoundError
 from ILoginPassword import ILoginPassword
-from Zope.ComponentArchitecture import getAdapter
+from Zope.ComponentArchitecture import getAdapter, queryAdapter
 
 class DuplicateLogin(Exception): pass
 class DuplicateId(Exception): pass
@@ -33,7 +33,7 @@
     # Methods implementing IAuthenticationService
     
     def authenticate(self, request):
-        a = getAdapter(request, ILoginPassword, None)
+        a = queryAdapter(request, ILoginPassword, None)
         if a is not None:
             login = a.getLogin()
             if login is not None:


=== Zope3/lib/python/Zope/App/Security/PrincipalRoleView.py 1.1.2.5 => 1.1.2.5.4.1 ===
 import time
 from Zope.App.PageTemplate import ViewPageTemplateFile
-from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
+from Zope.Publisher.Browser.BrowserView import BrowserView
 from Zope.ComponentArchitecture.ContextDependent import ContextDependent
 from Zope.ComponentArchitecture import getService, getAdapter
 
@@ -29,7 +29,7 @@
 from Zope.App.Security.IPermission import IPermission
 from Zope.App.Security.IRole import IRole
 
-class PrincipalRoleView(AttributePublisher, ContextDependent):
+class PrincipalRoleView(BrowserView):
 
     index = ViewPageTemplateFile('pt/principal_role_association.pt')
 
@@ -39,7 +39,7 @@
 
         if principals is None:
             principals = self._principals = getService(
-                self.getContext(), 'AuthenticationService'
+                self.context, 'AuthenticationService'
                 ).getPrincipals()
 
         return principals
@@ -49,8 +49,7 @@
         roles = getattr(self, '_roles', None)
 
         if roles is None:
-            roles = self._roles = getService(
-                self.getContext(), 'RoleService'
+            roles = self._roles = getService(self.context, 'RoleService'
                 ).getRoles()
 
         return roles
@@ -63,7 +62,7 @@
         if not roles:
             roles = self.getAllRoles()
 
-        return PrincipalRoleGrid( principals, roles, self.getContext() )
+        return PrincipalRoleGrid( principals, roles, self.context )
         
     def action(self, principals, roles, mapping, testing=None):
 


=== Zope3/lib/python/Zope/App/Security/RolePermissionView.py 1.1.2.10 => 1.1.2.10.4.1 ===
 import os, time
 from Zope.App.PageTemplate import ViewPageTemplateFile
-from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
+from Zope.Publisher.Browser.BrowserView import BrowserView
 from Zope.ComponentArchitecture.ContextDependent import ContextDependent
 from Zope.ComponentArchitecture import getService, getAdapter
 from Zope.App.Security.IRolePermissionManager import IRolePermissionManager
@@ -26,7 +26,7 @@
 from Zope.App.Security.IRole import IRole
 from Zope.App.Security.Settings import Allow, Assign
 
-class RolePermissionView(AttributePublisher, ContextDependent):
+class RolePermissionView(BrowserView):
 
     index = ViewPageTemplateFile('pt/manage_access.pt')
     manage_permissionForm = ViewPageTemplateFile('pt/manage_permissionForm.pt')
@@ -36,7 +36,7 @@
         roles = getattr(self, '_roles', None)
         if roles is None:
             roles = self._roles = getService(
-                self.getContext(), 'RoleService'
+                self.context, 'RoleService'
                 ).getRoles()
         return roles
 
@@ -44,26 +44,26 @@
         permissions = getattr(self, '_permissions', None)
         if permissions is None:
             permissions = self._permissions = getService(
-                self.getContext(), 'PermissionService'
+                self.context, 'PermissionService'
                 ).getPermissions()
         return permissions
 
         
     def permissionRoles(self):
-        context = self.getContext()
+        context = self.context
         roles = self.roles()
         return [PermissionRoles(permission, context, roles)
                 for permission in self.permissions()]
 
     def permissionForID(self, pid):
-        context = self.getContext()
+        context = self.context
         roles = self.roles()
         perm = getService(context, 'PermissionService'
                           ).getPermission(pid)
         return PermissionRoles(perm, context, roles)
 
     def roleForID(self, rid):
-        context = self.getContext()
+        context = self.context
         permissions = self.permissions()
         role = getService(context, 'RoleService'
                           ).getRole(rid)
@@ -73,7 +73,7 @@
     def action(self, REQUEST, testing=None):
         roles       = [r.getId() for r in self.roles()]
         permissions = [p.getId() for p in self.permissions()]
-        prm         = getAdapter(self.getContext(), IRolePermissionManager)
+        prm         = getAdapter(self.context, IRolePermissionManager)
         for ip in range(len(permissions)):
             rperm = REQUEST.get("p%s" % ip)
             if rperm not in permissions: continue
@@ -92,7 +92,7 @@
 
     def update_permission(self, REQUEST, permission_id,
                           roles=(), testing=None):
-        prm = getAdapter(self.getContext(), IRolePermissionManager)
+        prm = getAdapter(self.context, IRolePermissionManager)
 
         for ir in [r.getId() for r in self.roles()]:
             if ir in roles:
@@ -107,7 +107,7 @@
 
     def update_role(self, REQUEST, role_id,
                     permissions=(), testing=None):
-        prm = getAdapter(self.getContext(), IRolePermissionManager)
+        prm = getAdapter(self.context, IRolePermissionManager)
 
         for ip in [p.getId() for p in self.permissions()]:
             if ip in permissions:


=== Zope3/lib/python/Zope/App/Security/Zope3RoleManagement.py 1.1.2.2 => 1.1.2.2.14.1 ===
     """
 
-    __implements__ = ( IRoleManagement, )
+    __implements__ = (IRoleManagement, )
 
-    def __init__( self, context ):
-        self._context = context
+    def __init__(self, context):
+        self.context = context
 
-    
-    def getContext( self ):
-        return self._context
 
     def _getContextBindings( self ):
         """
             Find or create the permission-role bindings for our context.
         """
-        bindings = getattr( self._context, SPECIAL_ATTRIBUTE_NAME, None )
+        bindings = getattr( self.context, SPECIAL_ATTRIBUTE_NAME, None )
 
         if bindings is None:
             bindings = _PermissionRoleBindings()
-            setattr( self._context, SPECIAL_ATTRIBUTE_NAME, bindings )
+            setattr( self.context, SPECIAL_ATTRIBUTE_NAME, bindings )
 
         return bindings
 


=== Zope3/lib/python/Zope/App/Security/ZopeSecurityPolicy.py 1.1.2.26 => 1.1.2.26.8.1 ===
 __version__='$Revision$'[11:-2]
 
-from Zope.ComponentArchitecture import getAdapter
+from Zope.ComponentArchitecture import queryAdapter
 from Zope.Proxy.ContextWrapper import ContainmentIterator
 from Zope.Exceptions import Unauthorized, Forbidden
 from Zope.App.Security.IRolePermissionManager import IRolePermissionManager
@@ -83,7 +83,7 @@
         # Check the placeful principal permissions and aggregate the
         # Roles in this context
         for c in ContainmentIterator(object):
-            ppm = getAdapter(c, IPrincipalPermissionManager, None, globalContext)
+            ppm = queryAdapter(c, IPrincipalPermissionManager, None, globalContext)
             if ppm is not None: 
                 for principal in principals.keys():
                     setting = ppm.getSetting(permission, principal)
@@ -92,7 +92,7 @@
                     elif setting is Allow:
                         return 1 # Explicit allow on principal
                     
-            prm = getAdapter(c, IPrincipalRoleManager, None, globalContext)
+            prm = queryAdapter(c, IPrincipalRoleManager, None, globalContext)
             if prm is not None:
                 for principal in principals.keys():
                     for role, setting in prm.getRolesForPrincipal(principal):
@@ -121,7 +121,7 @@
                         
         # Check the placeful role permissions, checking anonymous first
         for c in ContainmentIterator(object):
-            rpm = getAdapter(c, IRolePermissionManager, None, globalContext)
+            rpm = queryAdapter(c, IRolePermissionManager, None, globalContext)
             if rpm is not None:
                 for role in ['Anonymous'] + assigned_roles.keys():
                     setting = rpm.getSetting(permission, role)