[Zope3-checkins] CVS: Zope3/src/zope/app/securitypolicy/browser - manage_access.pt:1.3 manage_permissionform.pt:1.3 principal_permission_edit.pt:1.2 principal_role_association.pt:1.3 principalpermissionview.py:1.4 principalroleview.py:1.4 rolepermissionview.py:1.4

Stephan Richter srichter at cosmos.phy.tufts.edu
Mon Mar 8 07:06:37 EST 2004


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

Modified Files:
	manage_access.pt manage_permissionform.pt 
	principal_permission_edit.pt principal_role_association.pt 
	principalpermissionview.py principalroleview.py 
	rolepermissionview.py 
Log Message:


Adjusted code to use the new APIs for permissions and principals. Also, use
the utility service instead of the permission registry to look up permissions.




=== Zope3/src/zope/app/securitypolicy/browser/manage_access.pt 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/browser/manage_access.pt:1.2	Fri Mar  5 13:39:07 2004
+++ Zope3/src/zope/app/securitypolicy/browser/manage_access.pt	Mon Mar  8 07:06:05 2004
@@ -60,13 +60,13 @@
           <div class="list-item">
              <a href="RolesWithPermission.html"
                 tal:attributes="href 
-           string:RolesWithPermission.html?permission_to_manage=${perm/getId}"
-                tal:content="perm/getTitle"
+           string:RolesWithPermission.html?permission_to_manage=${perm/id}"
+                tal:content="perm/title"
                 >Access Transient Objects</a>
              <input type="hidden" name="r0" value=""
                  tal:attributes="
                  name string:p${repeat/perm/index};
-                 value  string:${perm/getId}" />
+                 value  string:${perm/id}" />
           </div>
         </td>
         <td align="center" tal:repeat="setting perm/roleSettings">


=== Zope3/src/zope/app/securitypolicy/browser/manage_permissionform.pt 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/browser/manage_permissionform.pt:1.2	Fri Mar  5 13:39:07 2004
+++ Zope3/src/zope/app/securitypolicy/browser/manage_permissionform.pt	Mon Mar  8 07:06:05 2004
@@ -30,16 +30,16 @@
 
     <p class="form-text" i18n:translate="">
       Roles assigned to the permission
-      <strong tal:content="perm/getTitle" 
+      <strong tal:content="perm/title" 
           i18n:name="perm_title">Change DTML Methods</strong>
-      (id: <strong tal:content="perm/getId" 
+      (id: <strong tal:content="perm/id" 
           i18n:name="perm_id">Zope.Some.Permission</strong>)
     </p>
 
     <form action="AllRolePermissions.html" method="post">
 
       <input type="hidden" name="permission_id" value="Permission Name"
-          tal:attributes="value perm/getId" />
+          tal:attributes="value perm/id" />
 
         <div class="form-element">
 


=== Zope3/src/zope/app/securitypolicy/browser/principal_permission_edit.pt 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/principal_permission_edit.pt:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/principal_permission_edit.pt	Mon Mar  8 07:06:05 2004
@@ -4,7 +4,7 @@
   tal:define="rprincipal_id python:request['principal_id']">
 
   <h1 i18n:translate="">Permission settings for
-    <span tal:replace="python:view.get_principal(rprincipal_id).getTitle()" 
+    <span tal:replace="python:view.get_principal(rprincipal_id).title" 
           i18n:name="principal_title"/>
   </h1>
 
@@ -21,8 +21,8 @@
             </tr>
             <tr tal:repeat="perm 
        python:view.get_set_permissions_for_principal(rprincipal_id, 'Allow')">
-              <td><input type="checkbox" tal:attributes="name perm/getId"/></td>
-              <td tal:content="perm/getTitle">Permission1</td>
+              <td><input type="checkbox" tal:attributes="name perm/id"/></td>
+              <td tal:content="perm/title">Permission1</td>
             </tr>
             <tr tal:replace="nothing">
               <td><input type="checkbox" name="permission_ids" /></td>
@@ -47,9 +47,9 @@
             <tr tal:repeat="perm 
        python:view.get_set_permissions_for_principal(rprincipal_id, 'Deny')">
               <td>
-                <input type="checkbox" tal:attributes="name perm/getId" />
+                <input type="checkbox" tal:attributes="name perm/id" />
               </td>
-              <td tal:content="perm/getTitle">Permission1</td>
+              <td tal:content="perm/title">Permission1</td>
             </tr>
             <tr tal:replace="nothing">
               <td><input type="checkbox" name="permission_ids" /></td>
@@ -80,8 +80,8 @@
             <option 
               tal:repeat="perm 
                 python:view.get_unset_permissions_for_principal(rprincipal_id)"
-              tal:attributes="value perm/getId"
-              tal:content="perm/getTitle">Perm1</option>
+              tal:attributes="value perm/id"
+              tal:content="perm/title">Perm1</option>
             <option tal:replace="nothing">Perm2</option>
             <option tal:replace="nothing">Perm3</option>
           </select>


=== Zope3/src/zope/app/securitypolicy/browser/principal_role_association.pt 1.2 => 1.3 ===
--- Zope3/src/zope/app/securitypolicy/browser/principal_role_association.pt:1.2	Fri Mar  5 13:39:07 2004
+++ Zope3/src/zope/app/securitypolicy/browser/principal_role_association.pt	Mon Mar  8 07:06:05 2004
@@ -17,8 +17,8 @@
        <span i18n:translate="">Principal(s)</span>:
        <select name="principals:list" multiple="multiple">
          <option tal:repeat="principal view/getAllPrincipals"
-                 tal:attributes="value principal/getId"
-                 tal:content="principal/getTitle">my title</option>
+                 tal:attributes="value principal/id"
+                 tal:content="principal/title">my title</option>
        </select>
 
        <span i18n:translate="">Role(s)</span>:
@@ -58,17 +58,17 @@
            </tr>
 
            <tr class="principalRoleRow" tal:repeat="principal listPrincipals">
-             <td class="principalLabel" tal:content="string:${principal/getLogin} (${principal/getTitle|principal/getLogin})">
+             <td class="principalLabel" tal:content="string:${principal/getLogin} (${principal/title|principal/getLogin})">
                Principal Id
              </td>
 
              <td class="principalRole" tal:repeat="role listRoles">
                <select name="grid.role.principal:records"
                        tal:attributes="
-                           name string:grid.${role/id}.${principal/getId}"
+                           name string:grid.${role/id}.${principal/id}"
                        tal:define="selectedValue
                                    python:principalRoleGrid.getValue(
-                                              principal.getId(),
+                                              principal.id,
                                               role.id
                                               )" >
                  <option value="" tal:repeat="defaultValue listValues"
@@ -87,7 +87,7 @@
 
          <input type="hidden" name="principals:list"
                 tal:repeat="principal listPrincipals"
-                tal:attributes="value principal/getId" />
+                tal:attributes="value principal/id" />
 
          <input type="hidden" name="roles:list"
                 tal:repeat="role listRoles"


=== Zope3/src/zope/app/securitypolicy/browser/principalpermissionview.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/securitypolicy/browser/principalpermissionview.py:1.3	Sat Mar  6 11:50:29 2004
+++ Zope3/src/zope/app/securitypolicy/browser/principalpermissionview.py	Mon Mar  8 07:06:05 2004
@@ -21,8 +21,9 @@
 
 from zope.app import zapi
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.app.services.servicenames import Authentication
+from zope.app.security.interfaces import IPermission
 from zope.app.security.settings import Allow, Deny, Unset
-from zope.app.services.servicenames import Permissions, Authentication
 
 from zope.app.securitypolicy.interfaces import IPrincipalPermissionManager
 from zope.app.securitypolicy.interfaces import IPrincipalPermissionMap
@@ -32,9 +33,6 @@
 
     index = ViewPageTemplateFile('principal_permission_edit.pt')
 
-    def get_permission_service(self):
-        return zapi.getService(self.context, Permissions)
-
     def get_principal(self, principal_id):
         return zapi.getService(self.context,
                           Authentication
@@ -42,12 +40,11 @@
 
     def unsetPermissions(self, principal_id, permission_ids, REQUEST=None):
         """Form action unsetting a principals permissions"""
-        permission_service = self.get_permission_service()
         principal = self.get_principal(principal_id)
         ppm = IPrincipalPermissionManager(self.context)
 
         for perm_id in permission_ids:
-            permission = permission_service.getPermission(perm_id)
+            permission = zapi.getUtility(self.context, IPermission, perm_id)
             ppm.unsetPermissionForPrincipal(permission , principal)
 
         if REQUEST is not None:
@@ -56,12 +53,11 @@
 
     def grantPermissions(self, principal_id, permission_ids, REQUEST=None):
         """Form action granting a list of permissions to a principal"""
-        permission_service = self.get_permission_service()
         principal = self.get_principal(principal_id)
         ppm = IPrincipalPermissionManager(self.context)
 
         for perm_id in permission_ids:
-            permission = permission_service.getPermission(perm_id)
+            permission = zapi.getUtility(self.context, IPermission, perm_id)
             ppm.grantPermissionToPrincipal(permission , principal)
         if REQUEST is not None:
             return self.index(message="Settings changed at %s"
@@ -69,12 +65,11 @@
 
     def denyPermissions(self, principal_id, permission_ids, REQUEST=None):
         """Form action denying a list of permissions for a principal"""
-        permission_service = self.get_permission_service()
         principal = self.get_principal(principal_id)
         ppm = IPrincipalPermissionManager(self.context)
 
         for perm_id in permission_ids:
-            permission = permission_service.getPermission(perm_id)
+            permission = zapi.getUtility(self.context, IPermission, perm_id)
             ppm.denyPermissionToPrincipal(permission , principal)
         if REQUEST is not None:
             return self.index(message="Settings changed at %s"
@@ -83,12 +78,10 @@
     # Methods only called from the zpt view
     def getUnsetPermissionsForPrincipal(self, principal_id):
         """Returns all unset permissions for this principal"""
-
         ppmap = IPrincipalPermissionMap(self.context)
         principal = self.get_principal(principal_id)
-        perm_serv = zapi.getService(self.context, Permissions)
         result = []
-        for perm in perm_serv.getPermissions():
+        for perm in zapi.getUtilitiesFor(self.context, IPermission):
             if ppmap.getSetting(perm, principal) == Unset:
                 result.append(perm)
 


=== Zope3/src/zope/app/securitypolicy/browser/principalroleview.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/securitypolicy/browser/principalroleview.py:1.3	Sat Mar  6 11:50:29 2004
+++ Zope3/src/zope/app/securitypolicy/browser/principalroleview.py	Mon Mar  8 07:06:05 2004
@@ -106,7 +106,7 @@
         for role in roles:
             rid = role.id
             for principal in principals:
-                pid = principal.getId()
+                pid = principal.id
                 setting = map.getSetting(rid, pid)
                 self._grid[(pid, rid)] = setting.getName()
 
@@ -114,7 +114,7 @@
         return self._principals
 
     def principalIds(self):
-        return [p.getId() for p in self._principals]
+        return [p.id for p in self._principals]
 
     def roles(self):
         return self._roles


=== Zope3/src/zope/app/securitypolicy/browser/rolepermissionview.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/securitypolicy/browser/rolepermissionview.py:1.3	Sat Mar  6 11:50:29 2004
+++ Zope3/src/zope/app/securitypolicy/browser/rolepermissionview.py	Mon Mar  8 07:06:05 2004
@@ -20,10 +20,9 @@
 from zope.app import zapi
 from zope.app.i18n import ZopeMessageIDFactory as _
 from zope.app.security.settings import Unset, Allow, Deny
-from zope.app.services.servicenames import Permissions
+from zope.app.security.interfaces import IPermission
 
-from zope.app.securitypolicy.interfaces import IRole
-from zope.app.securitypolicy.interfaces import IRolePermissionManager
+from zope.app.securitypolicy.interfaces import IRole, IRolePermissionManager
 from zope.app.securitypolicy.permissionroles import PermissionRoles
 from zope.app.securitypolicy.rolepermission import RolePermissions
 
@@ -39,9 +38,9 @@
     def permissions(self):
         permissions = getattr(self, '_permissions', None)
         if permissions is None:
-            permissions = self._permissions = zapi.getService(
-                self.context, Permissions
-                ).getPermissions()
+            permissions = self._permissions = \
+              [perm for name, perm in zapi.getUtilitiesFor(self.context,
+                                                           IPermission)]
         return permissions
 
     def availableSettings(self, noacquire=False):
@@ -64,17 +63,14 @@
                 for permission in self.permissions()]
 
     def permissionForID(self, pid):
-        context = self.context
         roles = self.roles()
-        perm = zapi.getService(context, Permissions
-                          ).getPermission(pid)
-        return PermissionRoles(perm, context, roles)
+        perm = zapi.getUtility(self.context, IPermission, pid)
+        return PermissionRoles(perm, self.context, roles)
 
     def roleForID(self, rid):
-        context = self.context
         permissions = self.permissions()
-        role = zapi.getUtility(context, IRole, name=rid)
-        return RolePermissions(role, context, permissions)
+        role = zapi.getUtility(self.context, IRole, name=rid)
+        return RolePermissions(role, self.context, permissions)
 
 
     def update(self, testing=None):
@@ -83,7 +79,7 @@
 
         if 'SUBMIT' in self.request:
             roles       = [r.id for r in self.roles()]
-            permissions = [p.getId() for p in self.permissions()]
+            permissions = [p.id for p in self.permissions()]
             prm         = IRolePermissionManager(self.context)
             for ip in range(len(permissions)):
                 rperm = self.request.get("p%s" % ip)
@@ -127,7 +123,7 @@
             allowed = self.request.get(Allow.getName(), ())
             denied = self.request.get(Deny.getName(), ())
             for permission in self.permissions():
-                rperm = permission.getId()
+                rperm = permission.id
                 if rperm in allowed and rperm in denied:
                     raise ValueError("Incorrect setting for %s" % rperm)
                 if rperm in allowed:




More information about the Zope3-Checkins mailing list