[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ Changed the UI for granting roles or permissions to principals to the

Jim Fulton jim at zope.com
Tue Oct 19 15:16:04 EDT 2004


Log message for revision 28216:
  Changed the UI for granting roles or permissions to principals to the
  combined UI developed at the Isar sprint.
  
  Moved the UI for granting permissions to roles to the site-management
  UI, since only site managers or programmers ought to do this.
  

Changed:
  U   Zope3/trunk/src/zope/app/securitypolicy/browser/configure.zcml
  U   Zope3/trunk/src/zope/app/securitypolicy/browser/ftests.py
  A   Zope3/trunk/src/zope/app/securitypolicy/browser/granting_ftest.txt
  D   Zope3/trunk/src/zope/app/securitypolicy/browser/principal_permission_edit.pt
  D   Zope3/trunk/src/zope/app/securitypolicy/browser/principal_role_association.pt
  D   Zope3/trunk/src/zope/app/securitypolicy/browser/principalpermissionview.py
  D   Zope3/trunk/src/zope/app/securitypolicy/browser/principalroleview.py
  U   Zope3/trunk/src/zope/app/securitypolicy/browser/rolepermissionview.py
  D   Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_principalpermissionview.py
  D   Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_principalroleview.py
  U   Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py
  U   Zope3/trunk/src/zope/app/tests/functional.py

-=-
Modified: Zope3/trunk/src/zope/app/securitypolicy/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/configure.zcml	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/configure.zcml	2004-10-19 19:16:04 UTC (rev 28216)
@@ -57,25 +57,23 @@
 
 <!-- Role Permissions -->
 
+  <!-- Note that we've moved this to the site manager! -->
+  <!-- The role-permission mapping is really the domain of programmers -->
+
   <pages
-      for="zope.app.annotation.interfaces.IAnnotatable"
+      for="zope.app.site.interfaces.ISiteManager"
       permission="zope.Security"
       class=".rolepermissionview.RolePermissionView">
 
-    <page name="AllRolePermissions.html" template="manage_access.pt" />
+    <page name="AllRolePermissions.html" template="manage_access.pt" 
+          menu="zmi_actions" title="Role-Permissions"
+    />
           <!-- menu="zmi_actions" title="Role Permissions" / -->
     <page name="RolePermissions.html" template="manage_roleform.pt" />
     <page name="RolesWithPermission.html" template="manage_permissionform.pt"/>
 
   </pages>
 
-  <page
-    for="zope.app.annotation.interfaces.IAnnotatable"
-    name="grant.html"
-    permission="zope.Security"
-    template="grant.pt" 
-    menu="zmi_actions" title="Grant" />
-
   <zope:class class=".rolepermissionview.PermissionRoles">
     <zope:require permission="zope.Security"
                   attributes="roles rolesInfo id title description" />
@@ -87,38 +85,15 @@
         attributes="permissions permissionsInfo id title description" />
   </zope:class>
 
-<!-- Principal Roles -->
-
-  <page
-      name="PrincipalRoles.html" 
-      for="zope.app.annotation.interfaces.IAnnotatable"
-      permission="zope.Security"
-      class=".principalroleview.PrincipalRoleView"
-      template="principal_role_association.pt" />
-      <!-- menu="zmi_actions" title="Principal Roles" / -->
-
-
-<!-- Principal Permission (not working) -->
-
-  <!-- browser:page
-      name="PrincipalPermissionsManagement"
-      for="zope.app.annotation.interfaces.IAnnotatable"
-      class=".principalpermissionview.PrincipalPermissionView" 
-      permission="zope.Security"
-      allow_attributes="index get_principal unsetPermissions denyPermissions
-                        grantPermissions getUnsetPermissionsForPrincipal
-                        getPermissionsForPrincipal" 
-      /  -->
-
 <!-- Granting Roles and Permissions to Principals -->
 
   <page
     for="zope.app.annotation.interfaces.IAnnotatable"
-    name="granting.html"
+    name="grant.html"
     permission="zope.Security"
     template="granting.pt" 
     class=".granting.Granting"
-    menu="zmi_actions" title="Granting" />
+    menu="zmi_actions" title="Grant" />
 
 
 </zope:configure>

Modified: Zope3/trunk/src/zope/app/securitypolicy/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/ftests.py	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/ftests.py	2004-10-19 19:16:04 UTC (rev 28216)
@@ -18,24 +18,11 @@
 import unittest
 from zope.app.tests.functional import BrowserTestCase
 
-class GrantTest(BrowserTestCase):
-
-    def testGrant(self):
-        response = self.publish(
-            '/@@grant.html',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Grant permissions to roles' in body)
-        self.assert_('Grant roles to principals' in body)
-        self.checkForBrokenLinks(body, '/@@grant.html', 'mgr:mgrpw')
-
-
 class RolePermissionsTest(BrowserTestCase):
 
     def testAllRolePermissionsForm(self):
         response = self.publish(
-            '/@@AllRolePermissions.html',
+            '/++etc++site/@@AllRolePermissions.html',
             basic='mgr:mgrpw')
         self.assertEqual(response.getStatus(), 200)
         body = response.getBody()
@@ -46,12 +33,13 @@
         self.assert_('Site Manager' in body)
         self.assert_('Site Member' in body)
         self.failIf(_result in body)
-        self.checkForBrokenLinks(body, '/@@AllRolePermissions.html',
+        self.checkForBrokenLinks(body,
+                                 '/++etc++site/@@AllRolePermissions.html',
                                  'mgr:mgrpw')
 
     def testAllRolePermissions(self):
         response = self.publish(
-            '/@@AllRolePermissions.html',
+            '/++etc++site/@@AllRolePermissions.html',
             form={'p0r0': 'Allow',
                   'p0': 'zope.ManageContent',
                   'r0': 'zope.Manager',
@@ -64,7 +52,8 @@
 
     def testRolesWithPermissionsForm(self):
         response = self.publish(
-            '/@@RolesWithPermissions.html?permission_to_manage=zope.View',
+            '/++etc++site/@@RolesWithPermissions.html'
+            '?permission_to_manage=zope.View',
             basic='mgr:mgrpw')
         self.assertEqual(response.getStatus(), 200)
         body = response.getBody()
@@ -77,7 +66,7 @@
 
     def testRolesWithPermissionsForm(self):
         response = self.publish(
-            '/@@RolePermissions.html?role_to_manage=zope.Manager',
+            '/++etc++site/@@RolePermissions.html?role_to_manage=zope.Manager',
             basic='mgr:mgrpw')
         self.assertEqual(response.getStatus(), 200)
         body = response.getBody()
@@ -86,7 +75,7 @@
             in body)
         self.assert_('Allow' in body)
         self.assert_('Deny' in body)
-        self.checkForBrokenLinks(body, '/@@RolesPermissions.html',
+        self.checkForBrokenLinks(body, '/++etc++site/@@RolesPermissions.html',
                                  'mgr:mgrpw')
 
 _result = '''\
@@ -95,60 +84,11 @@
             <option value="Deny">-</option>
 '''
 
-class PrincipalRolesTest(BrowserTestCase):
-
-    def testPrincipalRolesForm(self):
-        response = self.publish(
-            '/@@PrincipalRoles.html',
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Apply filter' in body)
-        self.assert_('Principal(s)' in body)
-        self.assert_('Role(s)' in body)
-        self.assert_('"Filter"' in body)
-        self.checkForBrokenLinks(body, '/@@PrincipalRoles.html',
-                                 'mgr:mgrpw')
-
-    def testPrincipalRoles(self):
-        response = self.publish(
-            '/@@PrincipalRoles.html',
-            form={'principals': ['zope.mgr'],
-                  'roles': ['zope.Member', 'zope.Manager'],
-                  'Filter': 'Filter'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('zope.mgr' in body)
-        self.assert_('zope.Member' in body)
-        self.assert_('"APPLY"' in body)
-        self.failIf(_result in body)
-        self.checkForBrokenLinks(body, '/@@PrincipalRoles.html',
-                                 'mgr:mgrpw')
-
-    def testPrincipalRolesApply(self):
-        response = self.publish(
-            '/@@PrincipalRoles.html',
-            form={'principals': ['zope.mgr'],
-                  'roles': ['zope.Member', 'zope.Manager'],
-                  'grid.zope.Member.zope.mgr': 'Allow', 
-                  'APPLY': 'Apply'},
-            basic='mgr:mgrpw')
-        self.assertEqual(response.getStatus(), 200)
-        body = response.getBody()
-        self.assert_('Apply filter' in body)
-        self.assert_('Principal(s)' in body)
-        self.assert_('Role(s)' in body)
-        self.assert_('"Filter"' in body)
-        self.checkForBrokenLinks(body, '/@@PrincipalRoles.html',
-                                 'mgr:mgrpw')
-
-
 def test_suite():
+    import zope.app.tests.functional
     return unittest.TestSuite((
-        unittest.makeSuite(GrantTest),
         unittest.makeSuite(RolePermissionsTest),
-        unittest.makeSuite(PrincipalRolesTest),
+        zope.app.tests.functional.FunctionalDocFileSuite('granting_ftest.txt'),
         ))
 
 if __name__ == '__main__':

Added: Zope3/trunk/src/zope/app/securitypolicy/browser/granting_ftest.txt
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/granting_ftest.txt	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/granting_ftest.txt	2004-10-19 19:16:04 UTC (rev 28216)
@@ -0,0 +1,125 @@
+Granting Example
+================
+
+In this example, we look at granting (or denying) principals (or
+roles) to principals.
+
+To make grants, we visit grant.html.  This doesn't display any 
+grant information until we select a principal.
+
+  >>> print http(r"""
+  ... GET /@@grant.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Referer: http://localhost:8081/@@contents.html
+  ... """)
+  HTTP/1.1 200 Ok
+  ...
+
+If we submit a search request, we'll get a list of principals, from
+which we can choose:
+
+  >>> print http(r"""
+  ... POST /@@grant.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 117
+  ... Content-Type: application/x-www-form-urlencoded
+  ... Referer: http://localhost:8081/@@grant.html
+  ... 
+  ... field.principal.displayed=y"""
+  ... """&field.principal.MA__.query.searchstring="""
+  ... """&field.principal.MA__.query.search=Search""")
+  HTTP/1.1 200 Ok
+  ...
+  <option value="em9wZS5tZ3I_">Manager</option>
+  ...
+
+We can then choose one.  If we do so, we get output that includes form
+elements for inputing security settings:
+
+  >>> print http(r"""
+  ... POST /@@grant.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 169
+  ... Content-Type: application/x-www-form-urlencoded
+  ... Referer: http://localhost:8081/@@grant.html
+  ... 
+  ... field.principal.displayed=y"""
+  ... """&field.principal.MA__.query.searchstring="""
+  ... """&field.principal.MA__.selection=em9wZS5tZ3I_"""
+  ... """&field.principal.MA__.apply=Apply""")
+  HTTP/1.1 200 Ok
+  ...
+  <select name="field.em9wZS5tZ3I_.role.zope.Member" size="1" >
+  <option value="allow">Allow</option>
+  <option selected="selected" value="unset">Unset</option>
+  <option value="deny">Deny</option>
+  </select>
+  ...
+  <select name="field.em9wZS5tZ3I_.permission.zope.ManageCode" size="1" >
+  <option value="allow">Allow</option>
+  <option selected="selected" value="unset">Unset</option>
+  <option value="deny">Deny</option>
+  </select>
+  ...
+
+Before we submit any data, there are no grants for the root object
+except for a one made by the testing framework that grants the manager
+role to the test manager:
+
+  >>> root = getRootFolder()
+  >>> import zope.app.securitypolicy.interfaces
+  >>> grants = zope.app.securitypolicy.interfaces.IGrantInfo(root) 
+  >>> grants.principalPermissionGrant('zope.mgr', 'zope.ManageCode')
+  PermissionSetting: Unset
+  >>> list(grants.getRolesForPrincipal('zope.mgr'))
+  [('zope.Manager', PermissionSetting: Allow)]
+
+Now, we can submit changes. (I've actually reduced the form input
+to just the things we want to change to both limit the text here and
+to reduce dependencies on specific roles and permissions:
+
+
+  >>> print http(r"""
+  ... POST /@@grant.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 6311
+  ... Content-Type: application/x-www-form-urlencoded
+  ... Referer: http://localhost:8081/@@grant.html
+  ... 
+  ... field.principal=em9wZS5tZ3I_"""
+  ... """&field.principal.displayed=y"""
+  ... """&field.principal.MA__.query.searchstring="""
+  ... """&field.em9wZS5tZ3I_.role.zope.Member=allow"""
+  ... """&field.em9wZS5tZ3I_.role.zope.Member-empty-marker=1"""
+  ... """&field.em9wZS5tZ3I_.permission.zope.ManageCode=deny"""
+  ... """&field.em9wZS5tZ3I_.permission.zope.ManageCode-empty-marker=1"""
+  ... """&GRANT_SUBMIT=Change""")
+  HTTP/1.1 200 Ok
+  ...
+  <select name="field.em9wZS5tZ3I_.role.zope.Member" size="1" >
+  <option selected="selected" value="allow">Allow</option>
+  <option value="unset">Unset</option>
+  <option value="deny">Deny</option>
+  </select>
+  ...
+  <select name="field.em9wZS5tZ3I_.permission.zope.ManageCode" size="1" >
+  <option value="allow">Allow</option>
+  <option value="unset">Unset</option>
+  <option selected="selected" value="deny">Deny</option>
+  </select>
+  ...
+
+And, if we check the grants, we see the changes:
+
+  >>> grants = zope.app.securitypolicy.interfaces.IGrantInfo(root) 
+
+  >>> grants.principalPermissionGrant('zope.mgr', 'zope.ManageCode')
+  PermissionSetting: Deny
+
+  >>> role_grants = list(grants.getRolesForPrincipal('zope.mgr'))
+  >>> role_grants.sort()
+  >>> role_grants
+  ... # doctest: +NORMALIZE_WHITESPACE
+  [('zope.Manager', PermissionSetting: Allow), 
+   ('zope.Member', PermissionSetting: Allow)]
+  


Property changes on: Zope3/trunk/src/zope/app/securitypolicy/browser/granting_ftest.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Deleted: Zope3/trunk/src/zope/app/securitypolicy/browser/principal_permission_edit.pt
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/principal_permission_edit.pt	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/principal_permission_edit.pt	2004-10-19 19:16:04 UTC (rev 28216)
@@ -1,105 +0,0 @@
-<html metal:use-macro="context/@@standard_macros/page">
-<body>
-<div metal:fill-slot="body"
-  tal:define="rprincipal_id python:request['principal_id']">
-
-  <h1 i18n:translate="">Permission settings for
-    <span tal:replace="python:view.get_principal(rprincipal_id).title" 
-          i18n:name="principal_title"/>
-  </h1>
-
-  <form action="unsetPermissions.html" method="post">
-    <h2 i18n:translate="">Permission Settings</h2>
-
-    <table>
-      <tr>
-        <td valign="top">
-          <table border="0">
-            <tr>
-              <th colspan="2" align="center" 
-                  i18n:translate="">Allowed Permissions</th>
-            </tr>
-            <tr tal:repeat="perm 
-       python:view.get_set_permissions_for_principal(rprincipal_id, 'Allow')">
-              <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>
-              <td>Permission2</td>
-            </tr>
-            <tr tal:replace="nothing">
-              <td><input type="checkbox" name="permission_ids" /></td>
-              <td>Permission3</td>
-            </tr>
-            <tr tal:replace="nothing">
-              <td><input type="checkbox" name="permission_ids" /></td>
-              <td>Permission5</td>
-            </tr>
-          </table>
-        </td>
-        <td valign="top"> 
-          <table border="0">
-            <tr >
-              <th colspan="2" align="center" 
-                  i18n:translate="">Denied Permissions</th>
-            </tr>
-            <tr tal:repeat="perm 
-       python:view.get_set_permissions_for_principal(rprincipal_id, 'Deny')">
-              <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>
-              <td>Permission2</td>
-            </tr>
-          </table>
-        </td>
-      </tr>
-      <tr>
-        <td colspan="2" align="center">
-          <input type="submit" name="unset" 
-                 value="Remove selected permission settings" 
-                 i18n:attributes="value"/>
-        </td>
-      </tr>
-    </table>
-  </form>
-
-  <p>&nbsp;</p>
-
-  <form action="./" method="post">
-    <h2 i18n:translate="">Add permission settings</h2>
-
-    <table>
-      <tr>
-        <td>
-          <select name="permissions" multiple="multiple">
-            <option 
-              tal:repeat="perm 
-                python:view.get_unset_permissions_for_principal(rprincipal_id)"
-              tal:attributes="value perm/id"
-              tal:content="perm/title">Perm1</option>
-            <option tal:replace="nothing">Perm2</option>
-            <option tal:replace="nothing">Perm3</option>
-          </select>
-        </td>        
-        <td valign="center">
-          <p>
-            <input type="submit" name="grantPermissions.html:method" 
-                   value="Grant" i18n:attributes="value grant-button"/>
-          </p>
-          <p>
-            <input type="submit" name="denyPermissions.html:method"
-                   value="Deny" i18n:attributes="value grant-button"/>
-          </p>
-        </td>
-      </tr>
-    </table>
-  </form>
-
-</div>
-</body>
-</html>

Deleted: Zope3/trunk/src/zope/app/securitypolicy/browser/principal_role_association.pt
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/principal_role_association.pt	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/principal_role_association.pt	2004-10-19 19:16:04 UTC (rev 28216)
@@ -1,112 +0,0 @@
-<html metal:use-macro="context/@@standard_macros/dialog">
-<body>
-<div metal:fill-slot="body">
-
-   <p tal:define="status view/update"
-      tal:condition="status"
-      tal:content="status" />
-
-   <metal:block define-macro="formbody"
-      tal:define="hasFilter python:request.get('Filter', None)">
-
-   <div tal:condition="not: hasFilter">
-     <span class="message" i18n:translate="">Apply filter</span>
-     <form action="@@PrincipalRoles.html"
-           method="POST"
-           tal:attributes="action request/URL">
-       <span i18n:translate="">Principal(s)</span>:
-       <select name="principals:list" multiple="multiple">
-         <option tal:repeat="principal view/getAllPrincipals"
-                 tal:attributes="value principal/id"
-                 tal:content="principal/title">my title</option>
-       </select>
-
-       <span i18n:translate="">Role(s)</span>:
-       <select name="roles:list" multiple="multiple">
-         <option tal:repeat="role view/getAllRoles"
-                 tal:attributes="value role/id"
-                 tal:content="role/title">my title</option>
-       </select>
-
-       <input type="submit" name="Filter" value="Filter"
-              i18n:attributes="value filter-button"/>
-     </form>
-
-   </div>
-
-   <div tal:condition="hasFilter">
-     <div class="principalRolesGrid"
-          tal:define="principalRoleGrid view/createGrid">
-
-       <span tal:define="
-           global listPrincipals principalRoleGrid/principals;
-           global listRoles principalRoleGrid/roles;
-           global listValues principalRoleGrid/listAvailableValues" />
-
-       <form action="@@PrincipalRoles.html"
-             method="POST"
-             tal:attributes="action request/URL">
-         <table>
-           <tr class="roleHeading">
-             <td class="principal">
-               &nbsp;
-             </td>
-             <td class="role" tal:repeat="role listRoles"
-                              tal:content="role/title">
-               Role Title
-             </td>
-           </tr>
-
-           <tr class="principalRoleRow" tal:repeat="principal listPrincipals">
-             <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/id}"
-                       tal:define="selectedValue
-                                   python:principalRoleGrid.getValue(
-                                              principal.id,
-                                              role.id
-                                              )" >
-                 <option value="" tal:repeat="defaultValue listValues"
-                         tal:attributes="
-                             selected python:defaultValue==selectedValue;
-                             value defaultValue;
-                             debugsel selectedValue"
-                        tal:content="defaultValue">
-                   &nbsp;
-                 </option>
-               </select>
-             </td>
-           </tr>
-
-         </table>
-
-         <input type="hidden" name="principals:list"
-                tal:repeat="principal listPrincipals"
-                tal:attributes="value principal/id" />
-
-         <input type="hidden" name="roles:list"
-                tal:repeat="role listRoles"
-                tal:attributes="value role/id" />
-
-	 <metal:block define-slot="buttons">
-
-	 <input type="submit" name="APPLY" value="Apply"
-                i18n:attributes="value apply-button"/>
-
-	 </metal:block>
-
-       </form>
-
-     </div>
-   </div>
-
-   </metal:block>
-
-</div>
-</body>
-</html>

Deleted: Zope3/trunk/src/zope/app/securitypolicy/browser/principalpermissionview.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/principalpermissionview.py	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/principalpermissionview.py	2004-10-19 19:16:04 UTC (rev 28216)
@@ -1,107 +0,0 @@
-##############################################################################
-#
-# 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.1 (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.
-#
-##############################################################################
-"""Principal Permission View Classes
-
-$Id$
-"""
-import time
-
-from zope.app.publisher.browser import BrowserView
-
-from zope.app import zapi
-from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
-from zope.app.servicenames import Authentication
-from zope.app.security.interfaces import IPermission
-from zope.app.security.settings import Allow, Deny, Unset
-
-from zope.app.securitypolicy.interfaces import IPrincipalPermissionManager
-from zope.app.securitypolicy.interfaces import IPrincipalPermissionMap
-
-
-class PrincipalPermissionView(BrowserView):
-
-    index = ViewPageTemplateFile('principal_permission_edit.pt')
-
-    def get_principal(self, principal_id):
-        return zapi.getService(Authentication).getPrincipal(principal_id)
-
-    def unsetPermissions(self, principal_id, permission_ids, REQUEST=None):
-        """Form action unsetting a principals permissions"""
-        principal = self.get_principal(principal_id)
-        ppm = IPrincipalPermissionManager(self.context)
-
-        for perm_id in permission_ids:
-            permission = zapi.getUtility(IPermission, perm_id)
-            ppm.unsetPermissionForPrincipal(permission , principal)
-
-        if REQUEST is not None:
-            return self.index(message="Settings changed at %s"
-                                        % time.ctime(time.time()))
-
-    def grantPermissions(self, principal_id, permission_ids, REQUEST=None):
-        """Form action granting a list of permissions to a principal"""
-        principal = self.get_principal(principal_id)
-        ppm = IPrincipalPermissionManager(self.context)
-
-        for perm_id in permission_ids:
-            permission = zapi.getUtility(IPermission, perm_id)
-            ppm.grantPermissionToPrincipal(permission , principal)
-        if REQUEST is not None:
-            return self.index(message="Settings changed at %s"
-                                        % time.ctime(time.time()))
-
-    def denyPermissions(self, principal_id, permission_ids, REQUEST=None):
-        """Form action denying a list of permissions for a principal"""
-        principal = self.get_principal(principal_id)
-        ppm = IPrincipalPermissionManager(self.context)
-
-        for perm_id in permission_ids:
-            permission = zapi.getUtility(IPermission, perm_id)
-            ppm.denyPermissionToPrincipal(permission , principal)
-        if REQUEST is not None:
-            return self.index(message="Settings changed at %s"
-                                        % time.ctime(time.time()))
-
-    # 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)
-        result = []
-        for perm in zapi.getUtilitiesFor(IPermission):
-            if ppmap.getSetting(perm, principal) == Unset:
-                result.append(perm)
-
-        return result
-
-    def getPermissionsForPrincipal(self, principal_id, setting_name):
-        """Return a list of permissions with the given setting_name
-           string for the principal.
-
-           Return empty list if there are no permissions.
-        """
-
-        ppmap = IPrincipalPermissionMap(self.context)
-        principal = self.get_principal(principal_id)
-
-        permission_settings = ppmap.getPermissionsForPrincipal(principal)
-        setting_map = {'Deny': Deny, 'Allow':Allow}
-        asked_setting = setting_map[setting_name]
-
-        result = []
-        for permission, setting in permission_settings:
-            if asked_setting == setting:
-                result.append(permission)
-
-        return result

Deleted: Zope3/trunk/src/zope/app/securitypolicy/browser/principalroleview.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/principalroleview.py	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/principalroleview.py	2004-10-19 19:16:04 UTC (rev 28216)
@@ -1,129 +0,0 @@
-##############################################################################
-#
-# 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.1 (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.
-#
-##############################################################################
-"""Management view component for principal-role management (Zope2's
-'local roles').
-
-$Id$
-"""
-from datetime import datetime
-
-from zope.app import zapi
-from zope.app.i18n import ZopeMessageIDFactory as _
-from zope.app.security.settings import Unset, Deny, Allow
-from zope.app.servicenames import Authentication
-
-from zope.app.securitypolicy.interfaces import IRole
-from zope.app.securitypolicy.interfaces import IPrincipalRoleManager
-from zope.app.securitypolicy.interfaces import IPrincipalRoleMap
-
-class PrincipalRoleView(object):
-
-    def getAllPrincipals(self):
-        principals = getattr(self, '_principals', None)
-        if principals is None:
-            auth = zapi.getService(Authentication)
-            principals = self._principals = auth.getPrincipals('')
-        return principals
-
-    def getAllRoles(self):
-        roles = getattr(self, '_roles', None)
-        if roles is None:
-            roles = self._roles = \
-              [role
-               for name, role in zapi.getUtilitiesFor(IRole)]
-        return roles
-
-    def createGrid(self, principals=None, roles=None):
-        if principals is None:
-            principals = self.request.get('principals')
-            if principals is None:
-                principals = self.getAllPrincipals()
-            else:
-                # Ugh, we have ids, but we want objects
-                auth_service = zapi.getService(Authentication)
-                principals = [auth_service.getPrincipal(principal)
-                              for principal in principals]
-
-
-        if roles is None:
-            roles = self.request.get('roles')
-            if roles is None:
-                roles = self.getAllRoles()
-            else:
-                # XXX This code path needs a test
-                utils = zapi.getUtilitiesFor(IRole)
-                roles = [role for name, role in utils if name in roles]
-
-        return PrincipalRoleGrid(principals, roles, self.context)
-
-    def update(self, testing=None):
-        status = ''
-
-        if 'APPLY' in self.request:
-            principals = self.request.get('principals')
-            roles = self.request.get('roles')
-            prm = IPrincipalRoleManager(self.context)
-            for role in roles:
-                for principal in principals:
-                    name = 'grid.%s.%s' % (role, principal)
-                    setting = self.request.get(name, 'Unset')
-                    if setting == 'Unset':
-                        prm.unsetRoleForPrincipal(role, principal)
-                    elif setting == 'Allow':
-                        prm.assignRoleToPrincipal(role, principal)
-                    elif setting == 'Deny':
-                        prm.removeRoleFromPrincipal(role, principal)
-                    else:
-                        raise ValueError("Incorrect setting %s" % setting)
-
-            formatter = self.request.locale.dates.getFormatter(
-                'dateTime', 'medium')
-            status = _("Settings changed at ${date_time}")
-            status.mapping = {'date_time': formatter.format(datetime.utcnow())}
-
-        return status
-
-class PrincipalRoleGrid(object):
-
-    def __init__(self, principals, roles, context):
-        self._principals = principals
-        self._roles = roles
-        self._grid = {}
-
-        map = IPrincipalRoleMap(context)
-
-        for role in roles:
-            rid = role.id
-            for principal in principals:
-                pid = principal.id
-                setting = map.getSetting(rid, pid)
-                self._grid[(pid, rid)] = setting.getName()
-
-    def principals(self):
-        return self._principals
-
-    def principalIds(self):
-        return [p.id for p in self._principals]
-
-    def roles(self):
-        return self._roles
-
-    def roleIds(self):
-        return [r.id for r in self._roles]
-
-    def getValue(self, principal_id, role_id):
-        return self._grid[(principal_id, role_id)]
-
-    def listAvailableValues(self):
-        return (Unset.getName(), Allow.getName(), Deny.getName())

Modified: Zope3/trunk/src/zope/app/securitypolicy/browser/rolepermissionview.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/rolepermissionview.py	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/rolepermissionview.py	2004-10-19 19:16:04 UTC (rev 28216)
@@ -68,7 +68,7 @@
             return [aq]+rest
 
     def permissionRoles(self):
-        context = self.context
+        context = self.context.__parent__
         roles = self.roles()
         return [PermissionRoles(permission, context, roles)
                 for permission in self.permissions()]
@@ -76,12 +76,12 @@
     def permissionForID(self, pid):
         roles = self.roles()
         perm = zapi.getUtility(IPermission, pid)
-        return PermissionRoles(perm, self.context, roles)
+        return PermissionRoles(perm, self.context.__parent__, roles)
 
     def roleForID(self, rid):
         permissions = self.permissions()
         role = zapi.getUtility(IRole, rid)
-        return RolePermissions(role, self.context, permissions)
+        return RolePermissions(role, self.context.__parent__, permissions)
 
 
     def update(self, testing=None):
@@ -91,7 +91,7 @@
         if 'SUBMIT' in self.request:
             roles       = [r.id for r in self.roles()]
             permissions = [p.id for p in self.permissions()]
-            prm         = IRolePermissionManager(self.context)
+            prm         = IRolePermissionManager(self.context.__parent__)
             for ip in range(len(permissions)):
                 rperm = self.request.get("p%s" % ip)
                 if rperm not in permissions: continue
@@ -111,7 +111,7 @@
             changed = True
 
         if 'SUBMIT_PERMS' in self.request:
-            prm = IRolePermissionManager(self.context)
+            prm = IRolePermissionManager(self.context.__parent__)
             roles = self.roles()
             rperm = self.request.get('permission_id')
             settings = self.request.get('settings', ())
@@ -130,7 +130,7 @@
 
         if 'SUBMIT_ROLE' in self.request:
             role_id = self.request.get('role_id')
-            prm = IRolePermissionManager(self.context)
+            prm = IRolePermissionManager(self.context.__parent__)
             allowed = self.request.get(Allow.getName(), ())
             denied = self.request.get(Deny.getName(), ())
             for permission in self.permissions():

Deleted: Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_principalpermissionview.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_principalpermissionview.py	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_principalpermissionview.py	2004-10-19 19:16:04 UTC (rev 28216)
@@ -1,341 +0,0 @@
-##############################################################################
-#
-# 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.1 (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.
-#
-##############################################################################
-"""Principal Permission View Tests
-
-$Id$
-"""
-import unittest
-
-from zope.interface import implements
-
-from zope.app import zapi
-from zope.app.tests import ztapi
-from zope.app.site.interfaces import ISimpleService
-from zope.app.annotation.interfaces import IAttributeAnnotatable, IAnnotations
-from zope.app.security.interfaces import IAuthenticationService, IPrincipal
-from zope.app.security.interfaces import IPermission
-from zope.app.servicenames import Authentication
-from zope.app.annotation.attribute import AttributeAnnotations
-from zope.app.security.settings import Allow, Deny, Unset
-from zope.app.site.tests.placefulsetup import PlacefulSetup
-
-from zope.app.securitypolicy.interfaces import IPrincipalPermissionManager
-from zope.app.securitypolicy.interfaces import IPrincipalPermissionMap
-from zope.app.securitypolicy.browser.principalpermissionview \
-     import PrincipalPermissionView
-
-class DummyContext(object):
-    implements(IAttributeAnnotatable)
-
-
-class DummyAuthenticationService(object):
-    implements(IAuthenticationService, ISimpleService)
-
-    def __init__(self, principals):
-        pr = {}
-        for principal in principals:
-            pr[principal.id] = principal
-        self.principals = pr
-
-    def getPrincipal(self, principal_id):
-        return self.principals[principal_id]
-
-
-class DummyPrincipal(object):
-    implements(IPrincipal)
-
-    def __init__(self, id, title):
-        self.id = id
-        self.title = title
-
-
-class DummyAdapter(object):
-    implements(IPrincipalPermissionManager, IPrincipalPermissionMap)
-
-    def __init__(self, context):
-        self._context = context
-        if not hasattr(self._context,'principals'):
-            self._context.principals = {}
-
-    def grantPermissionToPrincipal(self, permission, principal):
-        if not (principal in self._context.principals):
-            self._context.principals[principal]={}
-
-        self._context.principals[principal][permission]=Allow
-
-    def denyPermissionToPrincipal(self, permission, principal):
-        if not (principal in self._context.principals):
-            self._context.principals[principal]={}
-
-        self._context.principals[principal][permission]=Deny
-
-    def unsetPermissionForPrincipal(self, permission, principal):
-        if not (principal in self._context.principals):
-            return
-        try:
-            del self._context.principals[principal][permission]
-        except KeyError:
-            pass
-
-    def getSetting(self, permission, principal):
-        try:
-            setting =  self._context.principals[principal][permission]
-
-        except KeyError:
-            setting = Unset
-
-        return setting
-
-    def getPrincipalsForPermission(self, permission):
-        ret = []
-        for principal, permissions in self._context.principals.items():
-            if permissions in permissions:
-                ret.append((principal, permissions[permission]))
-        return ret
-
-    def getPermissionsForPrincipal(self, principal):
-        try:
-            return self._context.principals[principal].items()
-        except KeyError:
-            return []
-
-class DummyPermission(object):
-    implements(IPermission)
-    
-    def __init__(self, id, title):
-        self.id = id
-        self.title = title
-
-
-class Test(PlacefulSetup, unittest.TestCase):
-
-    def setUp(self):
-        PlacefulSetup.setUp(self)
-        sm = zapi.getGlobalServices()
-        self._permissions = []
-        self._permissions.append(DummyPermission('qux', 'Qux'))
-        self._permissions.append(DummyPermission('baz', 'Baz'))
-        
-        for perm in self._permissions:
-            ztapi.provideUtility(IPermission, perm, perm.id)
-
-        sm.defineService(Authentication, IAuthenticationService)
-
-        self._principals = []
-        self._principals.append(DummyPrincipal('foo', 'Foo'))
-        self._principals.append(DummyPrincipal('bar', 'Bar'))
-
-        sm.provideService(Authentication,
-            DummyAuthenticationService(principals = self._principals))
-        ztapi.provideAdapter(IAttributeAnnotatable,
-                       IPrincipalPermissionManager, DummyAdapter)
-        ztapi.provideAdapter(
-            IAttributeAnnotatable, IAnnotations, AttributeAnnotations)
-
-    def _makeOne(self):
-        return PrincipalPermissionView(DummyContext(), None)
-
-    def testGrantPermissions(self):
-        view = self._makeOne()
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        denied_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Deny')
-
-        self.assertEqual(len(allowed_perms), 0, 'List not empty')
-        self.assertEqual(len(denied_perms), 0, 'List not empty')
-        view.grantPermissions(self._principals[0].id,
-                              [self._permissions[0].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Allow'),
-                         [self._permissions[0]])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Deny'),
-                         [])
-
-        view.grantPermissions(self._principals[0].id,
-                              [self._permissions[1].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Allow').sort(),
-                         self._permissions.sort())
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Deny'),
-                         [])
-
-        view.grantPermissions(self._principals[1].id,
-                              [self._permissions[0].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[1].id,'Allow'),
-                         [self._permissions[0]])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[1].id,'Deny'),
-                         [])
-
-        view.grantPermissions(self._principals[1].id,
-                              [self._permissions[1].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[1].id,'Allow').sort(),
-                         self._permissions.sort())
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[1].id,'Deny'),
-                         [])
-
-    def testDenyPermissions(self):
-        view = self._makeOne()
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        denied_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Deny')
-
-        self.assertEqual(len(allowed_perms), 0, 'List not empty')
-        self.assertEqual(len(denied_perms), 0, 'List not empty')
-        view.denyPermissions(self._principals[0].id,
-                             [self._permissions[0].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Deny'),
-                         [self._permissions[0]])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Allow'),
-                         [])
-
-        view.denyPermissions(self._principals[0].id,
-                             [self._permissions[1].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Deny').sort(),
-                         self._permissions.sort())
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Allow'),
-                         [])
-
-        view.denyPermissions(self._principals[1].id, [
-            self._permissions[0].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[1].id,'Deny'),
-                         [self._permissions[0]])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[1].id,'Allow'),
-                         [])
-
-        view.denyPermissions(self._principals[1].id,
-                             [self._permissions[1].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[1].id,'Deny').sort(),
-                         self._permissions.sort())
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[1].id,'Allow'),
-                         [])
-
-    def testAllowDenyPermissions(self):
-        view = self._makeOne()
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        denied_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Deny')
-
-        self.assertEqual(len(allowed_perms), 0, 'List not empty')
-        self.assertEqual(len(denied_perms), 0, 'List not empty')
-
-        view.grantPermissions(self._principals[0].id,
-                              [self._permissions[0].id])
-
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Allow'),
-                         [self._permissions[0]])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Deny'),
-                         [])
-
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        self.assertEqual(len(allowed_perms), 1, 'List has wrong length')
-
-        # Now change it to deny
-        view.denyPermissions(self._principals[0].id,
-                             [self._permissions[0].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Deny'),
-                         [self._permissions[0]])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Allow'),
-                         [])
-
-        view.grantPermissions(self._principals[0].id,
-                              [self._permissions[1].id])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Deny'),  [self._permissions[0]])
-        self.assertEqual(view.getPermissionsForPrincipal(
-            self._principals[0].id,'Allow'), [self._permissions[1]])
-
-    def testUnsetPermissions(self):
-        view = self._makeOne()
-
-        view.grantPermissions(self._principals[0].id,
-                              [self._permissions[0].id])
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        self.assertEqual(len(allowed_perms), 1, 'List has wrong length')
-
-        view.unsetPermissions(self._principals[0].id,
-                              [self._permissions[0].id])
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        self.assertEqual(len(allowed_perms), 0, 'Permission not unset')
-
-        # Deleting mutiple in one step
-        view.grantPermissions(self._principals[0].id,
-                              [self._permissions[0].id,
-                               self._permissions[1].id])
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        self.assertEqual(len(allowed_perms), 2, 'List has wrong length')
-
-        view.unsetPermissions(self._principals[0].id,
-                              [self._permissions[0].id,
-                               self._permissions[1].id])
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        self.assertEqual(len(allowed_perms), 0, 'Some permissions not unset')
-
-        # Deleting in a row
-        view.grantPermissions(self._principals[0].id,
-                              [self._permissions[0].id,
-                               self._permissions[1].id])
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        self.assertEqual(len(allowed_perms), 2, 'List has wrong length')
-
-        view.unsetPermissions(self._principals[0].id,
-                              [self._permissions[0].id])
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        self.assertEqual(len(allowed_perms), 1, 'Some permissions not unset')
-
-        view.unsetPermissions(self._principals[0].id,
-                              [self._permissions[1].id])
-        allowed_perms = view.getPermissionsForPrincipal(
-            self._principals[0].id, 'Allow')
-        self.assertEqual(len(allowed_perms), 0, 'Not all permissions unset')
-
-        # Ask for another way of getting the unset permisssions
-        unset_perms = view.getUnsetPermissionsForPrincipal(
-            self._principals[0].id)
-        # the permissions include zope.Public
-        self.assertEqual(len(unset_perms), 3, 'Not all permissions unset')
-
-def test_suite():
-    loader=unittest.TestLoader()
-    return loader.loadTestsFromTestCase(Test)
-
-if __name__=='__main__':
-    unittest.TextTestRunner().run(test_suite())

Deleted: Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_principalroleview.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_principalroleview.py	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_principalroleview.py	2004-10-19 19:16:04 UTC (rev 28216)
@@ -1,152 +0,0 @@
-##############################################################################
-#
-# 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.1 (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.
-#
-##############################################################################
-"""Principal-Role View Tests
-
-$Id$
-"""
-import unittest
-
-from zope.interface import implements
-from zope.publisher.browser import TestRequest
-from zope.app.publisher.browser import BrowserView
-
-from zope.app import zapi
-from zope.app.tests import ztapi
-from zope.app.security.interfaces import IAuthenticationService, IPrincipal
-from zope.app.security.interfaces import IPermission
-from zope.app.security.permission import Permission
-from zope.app.site.interfaces import ISimpleService
-from zope.app.servicenames import Authentication
-from zope.app.site.tests.placefulsetup import PlacefulSetup
-
-from zope.app.securitypolicy.role import Role
-from zope.app.securitypolicy.interfaces import IRole
-from zope.app.securitypolicy.interfaces import IPrincipalRoleManager
-from zope.app.securitypolicy.browser.principalroleview import \
-     PrincipalRoleView
-
-class PrincipalRoleView(PrincipalRoleView, BrowserView):
-    """Adding BrowserView to Utilities; this is usually done by ZCML."""
-
-class DummySetting(object):
-    def __init__(self, name):
-        self._name = name
-    def getName(self):
-        return self._name
-
-class DummyManager(object):
-
-    implements(IPrincipalRoleManager)
-
-    def getSetting(self, role, principal):
-        return DummySetting('%r:%r' % (role, principal))
-
-class DummyAuthenticationService(object):
-
-    implements(IAuthenticationService, ISimpleService)
-
-    def __init__(self, principals):
-        self._principals = principals
-
-    def getPrincipals(self, name):
-        return self._principals
-
-class DummyPrincipal(object):
-    implements(IPrincipal)
-
-    def __init__(self, id, title):
-        self.id = id
-        self.title = title
-
-
-def defineRole(id, title=None, description=None):
-    role = Role(id, title, description)
-    ztapi.provideUtility(IRole, role, name=role.id)
-    return role
-
-
-class Test(PlacefulSetup, unittest.TestCase):
-
-    def setUp(self):
-        PlacefulSetup.setUp(self)
-
-        self._roles = [defineRole('qux', 'Qux'), defineRole('baz', 'Baz')]
-
-        sm = zapi.getGlobalServices()
-
-        sm.defineService(Authentication, IAuthenticationService)
-
-        self._principals = []
-        self._principals.append(DummyPrincipal('foo', 'Foo'))
-        self._principals.append(DummyPrincipal('bar', 'Bar'))
-
-        sm.provideService(Authentication,
-            DummyAuthenticationService(principals = self._principals))
-
-    def _makeOne(self):
-        return PrincipalRoleView(DummyManager(), TestRequest())
-
-    def testRoles(self):
-        view = self._makeOne()
-        roles = list(view.getAllRoles())
-        self.assertEqual(len(roles), 2)
-
-        ids = [role.id for role in self._roles]
-
-        for role in roles:
-            self.failUnless(role.id in ids)
-
-    def testPrincipals(self):
-        view = self._makeOne()
-        principals = list(view.getAllPrincipals())
-        self.assertEqual(len(principals), 2)
-
-        ids = [p.id for p in self._principals]
-
-        for principal in principals:
-            self.failUnless(principal.id in ids, (principal, ids))
-
-    def testPrincipalRoleGrid(self):
-        view = self._makeOne()
-
-        grid = view.createGrid()
-
-        p_ids = [p.id for p in view.getAllPrincipals()]
-        r_ids = [r.id for r in view.getAllRoles()]
-
-        self.failUnless(grid.listAvailableValues())
-
-        for p in grid.principalIds():
-            self.failUnless(p in p_ids)
-
-        for r in grid.roleIds():
-            self.failUnless(r in r_ids)
-
-        map = DummyManager()
-
-        grid_entries = [(r, p, map.getSetting(r, p).getName())
-                        for r in grid.roleIds()
-                        for p in grid.principalIds()
-                        ]
-
-        for r, p, setting in grid_entries:
-            self.assertEquals(setting, grid.getValue(p, r))
-
-
-def test_suite():
-    loader=unittest.TestLoader()
-    return loader.loadTestsFromTestCase(Test)
-
-if __name__=='__main__':
-    unittest.TextTestRunner().run(test_suite())

Modified: Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py	2004-10-19 19:16:04 UTC (rev 28216)
@@ -61,6 +61,11 @@
     ztapi.provideUtility(IPermission, permission, name=permission.id)
     return permission
 
+class FakeSiteManager:
+
+    def __init__(self, site):
+        self.__parent__ = site
+
 class Test(PlacefulSetup, unittest.TestCase):
 
     def setUp(self):
@@ -69,7 +74,8 @@
         defineRole('member',  MessageID('Member', 'testdomain'))
         definePermission('read', MessageID('Read', 'testdomain'))
         definePermission('write', MessageID('Write', 'testdomain'))
-        self.view = RolePermissionView(RolePermissionManager(), None)
+        site = RolePermissionManager()
+        self.view = RolePermissionView(FakeSiteManager(site), None)
         ztapi.provideUtility(ITranslationDomain,
                              TranslationDomain(Member="A Member",
                                                Write="A Write",

Modified: Zope3/trunk/src/zope/app/tests/functional.py
===================================================================
--- Zope3/trunk/src/zope/app/tests/functional.py	2004-10-19 19:16:01 UTC (rev 28215)
+++ Zope3/trunk/src/zope/app/tests/functional.py	2004-10-19 19:16:04 UTC (rev 28216)
@@ -82,14 +82,17 @@
         return getattr(self._response, attr)
 
 
-grant_request = r"""
-POST /@@PrincipalRoles.html HTTP/1.1
+grant_request = (r"""
+POST /@@grant.html HTTP/1.1
 Authorization: Basic Z2xvYmFsbWdyOmdsb2JhbG1ncnB3
-Content-Length: 97
+Content-Length: 5796
 Content-Type: application/x-www-form-urlencoded
-Referer: http://localhost:8081/@@PrincipalRoles.html
 
-grid.zope.Manager.zope.mgr=Allow&principals%3Alist=zope.mgr&roles%3Alist=zope.Manager&APPLY=Apply"""
+field.principal=em9wZS5tZ3I_"""
+"""&field.principal.displayed=y"""
+"""&GRANT_SUBMIT=Change"""
+"""&field.em9wZS5tZ3I_.role.zope.Manager=allow"""
+"""&field.em9wZS5tZ3I_.role.zope.Manager-empty-marker=1""")
 
 class FunctionalTestSetup(object):
     """Keeps shared state across several functional test cases."""



More information about the Zope3-Checkins mailing list