[Zope3-checkins] CVS: Zope3/src/zope/app/securitypolicy/browser - __init__.py:1.2 configure.zcml:1.2 manage_access.pt:1.2 manage_permissionform.pt:1.2 manage_roleform.pt:1.2 principal_role_association.pt:1.2 principalpermissionview.py:1.2 principalroleview.py:1.2 rolepermissionview.py:1.2 addrole.pt:NONE role_service.gif:NONE

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


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

Modified Files:
	__init__.py configure.zcml manage_access.pt 
	manage_permissionform.pt manage_roleform.pt 
	principal_role_association.pt principalpermissionview.py 
	principalroleview.py rolepermissionview.py 
Removed Files:
	addrole.pt role_service.gif 
Log Message:


Make all the security code use role utilities and the new fields instead of
the methods.


=== Zope3/src/zope/app/securitypolicy/browser/__init__.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/__init__.py:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/__init__.py	Fri Mar  5 13:39:07 2004
@@ -1,34 +1 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-""" Define view component for service manager contents.
-
-$Id$
-"""
-from zope.app.browser.container.contents import Contents
-from zope.app.securitypolicy.role import Role, ILocalRoleService
-
-class Add:
-    "Provide a user interface for adding a role"
-    __used_for__ = ILocalRoleService
-
-    def action(self, id, title, description):
-        "Add a contact"
-        role = Role(id, title, description)
-        self.context[id] = role
-        self.request.response.redirect('.')
-
-
-class Contents(Contents):
-    # XXX: What the heck is that? I guess another dead chicken.
-    pass
+# Security Policy Browser Package


=== Zope3/src/zope/app/securitypolicy/browser/configure.zcml 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/configure.zcml:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/configure.zcml	Fri Mar  5 13:39:07 2004
@@ -3,34 +3,51 @@
    xmlns="http://namespaces.zope.org/browser"
    i18n_domain="zope">
 
-<!-- Role Service -->
+<!-- Role Utility -->
 
-  <icon
-      name="zmi_icon" 
-      for="zope.app.securitypolicy.role.ILocalRoleService"
-      file="role_service.gif" />
-
-  <pages 
-     permission="zope.ManageServices" 
-     for="zope.app.securitypolicy.role.IRoleService"
-     class=".Contents">
-
-     <page name="index.html" attribute="contents"
-           menu="zmi_views" title="Contents" />
-     <page name="removeObjects.html" attribute="removeObjects" />
-
-  </pages>
-
-  <pages 
-     permission="zope.ManageServices" 
-     for="zope.app.securitypolicy.role.IRoleService"
-     class=".Add">
-
-    <page name="+" template="addrole.pt" 
-          menu="zmi_actions" title="Add" />
-    <page name="action.html" attribute="action" />
+  <addform
+      label="New Role"
+      name="addRole.html"
+      schema="zope.app.securitypolicy.interfaces.IRole"
+      permission="zope.Security"
+      content_factory="zope.app.securitypolicy.role.PersistentRole"
+      arguments="title"
+      keyword_arguments="description"
+      fields="title description"
+      usage="addingdialog" />
+
+  <editform
+      schema="zope.app.securitypolicy.interfaces.IRole"
+      name="edit.html"
+      menu="zmi_views" title="Edit"
+      permission="zope.ManageContent"/>
+
+  <defaultView
+      for="zope.app.securitypolicy.interfaces.IRole"
+      name="edit.html" />
+
+  <!-- Menu entry for "Add Utility" menu -->
+  <addMenuItem
+      class="zope.app.securitypolicy.role.PersistentRole"
+      title="Role"
+      description="A Persistent Role"
+      permission="zope.Security"
+      view="addRole.html"
+      />
 
-  </pages>
+  <!-- Custom Role registration screen -->
+  <addform
+      label="New Role Registration"
+      for="zope.app.securitypolicy.interfaces.IRole"
+      name="addRegistration.html"
+      schema="zope.app.interfaces.services.utility.IUtilityRegistration"
+      class="zope.app.browser.services.utility.AddRegistration"
+      permission="zope.ManageServices"
+      content_factory="zope.app.securitypolicy.role.RoleRegistration"
+      arguments="name interface componentPath"
+      set_after_add="status"
+      fields="name interface componentPath permission status"
+      usage="addingdialog" />
 
 
 <!-- Role Permissions -->
@@ -63,6 +80,7 @@
       class=".principalroleview.PrincipalRoleView"
       template="principal_role_association.pt" />
       <!-- menu="zmi_actions" title="Principal Roles" / -->
+
 
 <!-- Principal Permission (not working) -->
 


=== Zope3/src/zope/app/securitypolicy/browser/manage_access.pt 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/manage_access.pt:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/manage_access.pt	Fri Mar  5 13:39:07 2004
@@ -41,12 +41,12 @@
           <div class="list-item">
             <a href="RolePermissions.html"
               tal:attributes="
-              href string:RolePermissions.html?role_to_manage=${role/getId}" 
-              tal:content="role/getTitle">Anonymous</a>
+              href string:RolePermissions.html?role_to_manage=${role/id}" 
+              tal:content="role/title">Anonymous</a>
             <input type="hidden" name="r0" value=""
               tal:attributes="
               name string:r${repeat/role/index};
-              value  string:${role/getId}" />
+              value  string:${role/id}" />
   
           </div>
         </td>


=== Zope3/src/zope/app/securitypolicy/browser/manage_permissionform.pt 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/manage_permissionform.pt:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/manage_permissionform.pt	Fri Mar  5 13:39:07 2004
@@ -65,7 +65,7 @@
           python:path('repeat/setting/even') and 'row-normal' or 'row-hilite'">
               <td align="left" valign="top"
                   tal:define="ir repeat/setting/index"
-                  tal:content="python:path('view/roles')[ir].getId()">
+                  tal:content="python:path('view/roles')[ir].id">
                 Manager
               </td>
               <td>


=== Zope3/src/zope/app/securitypolicy/browser/manage_roleform.pt 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/manage_roleform.pt:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/manage_roleform.pt	Fri Mar  5 13:39:07 2004
@@ -15,16 +15,16 @@
 
     <p class="form-text" i18n:translate="">
       Permissions assigned to the role
-      <strong tal:content="role/getTitle" 
+      <strong tal:content="role/title" 
               i18n:name="role_title">Great Master Guru</strong>
-      (id: <strong tal:content="role/getId" 
+      (id: <strong tal:content="role/id" 
               i18n:name="role_id">Zope.Some.Role</strong>)
     </p>
 
 
     <form action="AllRolePermissions.html" method="get">
       <input type="hidden" name="role_id" value="Role ID"
-             tal:attributes="value role/getId" />
+             tal:attributes="value role/id" />
 
       <table width="100%" cellspacing="0" cellpadding="2" border="0" 
              nowrap="nowrap"


=== Zope3/src/zope/app/securitypolicy/browser/principal_role_association.pt 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/principal_role_association.pt:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/principal_role_association.pt	Fri Mar  5 13:39:07 2004
@@ -24,8 +24,8 @@
        <span i18n:translate="">Role(s)</span>:
        <select name="roles:list" multiple="multiple">
          <option tal:repeat="role view/getAllRoles"
-                 tal:attributes="value role/getId"
-                 tal:content="role/getTitle">my title</option>
+                 tal:attributes="value role/id"
+                 tal:content="role/title">my title</option>
        </select>
 
        <input type="submit" name="Filter" value="Filter"
@@ -52,8 +52,8 @@
                &nbsp;
              </td>
              <td class="role" tal:repeat="role listRoles"
-                              tal:content="role/getTitle">
-               Role Id
+                              tal:content="role/title">
+               Role Title
              </td>
            </tr>
 
@@ -65,11 +65,11 @@
              <td class="principalRole" tal:repeat="role listRoles">
                <select name="grid.role.principal:records"
                        tal:attributes="
-                           name string:grid.${role/getId}.${principal/getId}"
+                           name string:grid.${role/id}.${principal/getId}"
                        tal:define="selectedValue
                                    python:principalRoleGrid.getValue(
                                               principal.getId(),
-                                              role.getId()
+                                              role.id
                                               )" >
                  <option value="" tal:repeat="defaultValue listValues"
                          tal:attributes="
@@ -91,7 +91,7 @@
 
          <input type="hidden" name="roles:list"
                 tal:repeat="role listRoles"
-                tal:attributes="value role/getId" />
+                tal:attributes="value role/id" />
 
 	 <metal:block define-slot="buttons">
 


=== Zope3/src/zope/app/securitypolicy/browser/principalpermissionview.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/principalpermissionview.py:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/principalpermissionview.py	Fri Mar  5 13:39:07 2004
@@ -17,9 +17,9 @@
 """
 import time
 
-from zope.component import getService, getAdapter
 from zope.publisher.browser import BrowserView
 
+from zope.app import zapi
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 from zope.app.security.settings import Allow, Deny, Unset
 from zope.app.services.servicenames import Permissions, Authentication
@@ -33,10 +33,10 @@
     index = ViewPageTemplateFile('principal_permission_edit.pt')
 
     def get_permission_service(self):
-        return getService(self.context, Permissions)
+        return zapi.getService(self.context, Permissions)
 
     def get_principal(self, principal_id):
-        return getService(self.context,
+        return zapi.getService(self.context,
                           Authentication
                           ).getPrincipal(principal_id)
 
@@ -44,7 +44,7 @@
         """Form action unsetting a principals permissions"""
         permission_service = self.get_permission_service()
         principal = self.get_principal(principal_id)
-        ppm = getAdapter(self.context, IPrincipalPermissionManager)
+        ppm = zapi.getAdapter(self.context, IPrincipalPermissionManager)
 
         for perm_id in permission_ids:
             permission = permission_service.getPermission(perm_id)
@@ -58,7 +58,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.context, IPrincipalPermissionManager)
+        ppm = zapi.getAdapter(self.context, IPrincipalPermissionManager)
 
         for perm_id in permission_ids:
             permission = permission_service.getPermission(perm_id)
@@ -71,7 +71,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.context, IPrincipalPermissionManager)
+        ppm = zapi.getAdapter(self.context, IPrincipalPermissionManager)
 
         for perm_id in permission_ids:
             permission = permission_service.getPermission(perm_id)
@@ -84,9 +84,9 @@
     def getUnsetPermissionsForPrincipal(self, principal_id):
         """Returns all unset permissions for this principal"""
 
-        ppmap = getAdapter(self.context, IPrincipalPermissionMap)
+        ppmap = zapi.getAdapter(self.context, IPrincipalPermissionMap)
         principal = self.get_principal(principal_id)
-        perm_serv = getService(self.context, Permissions)
+        perm_serv = zapi.getService(self.context, Permissions)
         result = []
         for perm in perm_serv.getPermissions():
             if ppmap.getSetting(perm, principal) == Unset:
@@ -101,7 +101,7 @@
            Return empty list if there are no permissions.
         """
 
-        ppmap = getAdapter(self.context, IPrincipalPermissionMap)
+        ppmap = zapi.getAdapter(self.context, IPrincipalPermissionMap)
         principal = self.get_principal(principal_id)
 
         permission_settings = ppmap.getPermissionsForPrincipal(principal)


=== Zope3/src/zope/app/securitypolicy/browser/principalroleview.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/principalroleview.py:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/principalroleview.py	Fri Mar  5 13:39:07 2004
@@ -12,17 +12,18 @@
 #
 ##############################################################################
 """Management view component for principal-role management (Zope2's
-"local roles").
+'local roles').
 
 $Id$
 """
 from datetime import datetime
 
-from zope.component import getService, getAdapter
+from zope.app import zapi
 from zope.app.i18n import ZopeMessageIDFactory as _
 from zope.app.security.settings import Unset, Deny, Allow
 from zope.app.services.servicenames import Authentication
 
+from zope.app.securitypolicy.interfaces import IRole
 from zope.app.securitypolicy.interfaces import IPrincipalRoleManager
 from zope.app.securitypolicy.interfaces import IPrincipalRoleMap
 
@@ -31,7 +32,7 @@
     def getAllPrincipals(self):
         principals = getattr(self, '_principals', None)
         if principals is None:
-            principals = self._principals = getService(
+            principals = self._principals = zapi.getService(
                 self.context, Authentication
                 ).getPrincipals('')
         return principals
@@ -39,8 +40,8 @@
     def getAllRoles(self):
         roles = getattr(self, '_roles', None)
         if roles is None:
-            roles = self._roles = getService(self.context, "Roles"
-                ).getRoles()
+            roles = self._roles = \
+              [role for name, role in zapi.getUtilitiesFor(self.context, IRole)]
         return roles
 
     def createGrid(self, principals=None, roles=None):
@@ -50,7 +51,7 @@
                 principals = self.getAllPrincipals()
             else:
                 # Ugh, we have ids, but we want objects
-                auth_service = getService(self.context, Authentication)
+                auth_service = zapi.getService(self.context, Authentication)
                 principals = [auth_service.getPrincipal(principal)
                               for principal in principals]
 
@@ -60,11 +61,9 @@
             if roles is None:
                 roles = self.getAllRoles()
             else:
-                # Ugh, we have ids, but we want objects
                 # XXX This code path needs a test
-                role_service = getService(self.context, 'Roles')
-                roles = [role_service.getRole(role)
-                         for role in roles]
+                utils = zapi.getUtilitiesFor(self.context, IRole)
+                roles = [role for name, role in utils if name in roles]
 
         return PrincipalRoleGrid(principals, roles, self.context)
 
@@ -74,7 +73,7 @@
         if 'APPLY' in self.request:
             principals = self.request.get('principals')
             roles = self.request.get('roles')
-            prm = getAdapter(self.context, IPrincipalRoleManager)
+            prm = zapi.getAdapter(self.context, IPrincipalRoleManager)
             for role in roles:
                 for principal in principals:
                     name = 'grid.%s.%s' % (role, principal)
@@ -102,10 +101,10 @@
         self._roles = roles
         self._grid = {}
 
-        map = getAdapter(context, IPrincipalRoleMap)
+        map = zapi.getAdapter(context, IPrincipalRoleMap)
 
         for role in roles:
-            rid = role.getId()
+            rid = role.id
             for principal in principals:
                 pid = principal.getId()
                 setting = map.getSetting(rid, pid)
@@ -121,7 +120,7 @@
         return self._roles
 
     def roleIds(self):
-        return [r.getId() for r in self._roles]
+        return [r.id for r in self._roles]
 
     def getValue(self, principal_id, role_id):
         return self._grid[(principal_id, role_id)]


=== Zope3/src/zope/app/securitypolicy/browser/rolepermissionview.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/securitypolicy/browser/rolepermissionview.py:1.1	Fri Feb 27 07:46:31 2004
+++ Zope3/src/zope/app/securitypolicy/browser/rolepermissionview.py	Fri Mar  5 13:39:07 2004
@@ -17,11 +17,12 @@
 """
 from datetime import datetime
 
-from zope.component import getService, getAdapter
+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.securitypolicy.interfaces import IRole
 from zope.app.securitypolicy.interfaces import IRolePermissionManager
 from zope.app.securitypolicy.permissionroles import PermissionRoles
 from zope.app.securitypolicy.rolepermission import RolePermissions
@@ -31,15 +32,14 @@
     def roles(self):
         roles = getattr(self, '_roles', None)
         if roles is None:
-            roles = self._roles = getService(
-                self.context, "Roles"
-                ).getRoles()
+            roles = self._roles = \
+              [role for name, role in zapi.getUtilitiesFor(self.context, IRole)]
         return roles
 
     def permissions(self):
         permissions = getattr(self, '_permissions', None)
         if permissions is None:
-            permissions = self._permissions = getService(
+            permissions = self._permissions = zapi.getService(
                 self.context, Permissions
                 ).getPermissions()
         return permissions
@@ -66,15 +66,14 @@
     def permissionForID(self, pid):
         context = self.context
         roles = self.roles()
-        perm = getService(context, Permissions
+        perm = zapi.getService(context, Permissions
                           ).getPermission(pid)
         return PermissionRoles(perm, context, roles)
 
     def roleForID(self, rid):
         context = self.context
         permissions = self.permissions()
-        role = getService(context, "Roles"
-                          ).getRole(rid)
+        role = zapi.getUtility(context, IRole, name=rid)
         return RolePermissions(role, context, permissions)
 
 
@@ -83,9 +82,9 @@
         changed = False
 
         if 'SUBMIT' in self.request:
-            roles       = [r.getId() for r in self.roles()]
+            roles       = [r.id for r in self.roles()]
             permissions = [p.getId() for p in self.permissions()]
-            prm         = getAdapter(self.context, IRolePermissionManager)
+            prm         = zapi.getAdapter(self.context, IRolePermissionManager)
             for ip in range(len(permissions)):
                 rperm = self.request.get("p%s" % ip)
                 if rperm not in permissions: continue
@@ -105,12 +104,12 @@
             changed = True
 
         if 'SUBMIT_PERMS' in self.request:
-            prm = getAdapter(self.context, IRolePermissionManager)
+            prm = zapi.getAdapter(self.context, IRolePermissionManager)
             roles = self.roles()
             rperm = self.request.get('permission_id')
             settings = self.request.get('settings', ())
             for ir in range(len(roles)):
-                rrole = roles[ir].getId()
+                rrole = roles[ir].id
                 setting = settings[ir]
                 if setting == Unset.getName():
                     prm.unsetPermissionFromRole(rperm, rrole)
@@ -124,7 +123,7 @@
 
         if 'SUBMIT_ROLE' in self.request:
             role_id = self.request.get('role_id')
-            prm = getAdapter(self.context, IRolePermissionManager)
+            prm = zapi.getAdapter(self.context, IRolePermissionManager)
             allowed = self.request.get(Allow.getName(), ())
             denied = self.request.get(Deny.getName(), ())
             for permission in self.permissions():

=== Removed File Zope3/src/zope/app/securitypolicy/browser/addrole.pt ===

=== Removed File Zope3/src/zope/app/securitypolicy/browser/role_service.gif ===




More information about the Zope3-Checkins mailing list