[Zope3-checkins]
SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/
Merged from trunk:
Jim Fulton
jim at zope.com
Wed Aug 11 17:42:23 EDT 2004
Log message for revision 27041:
Merged from trunk:
r27032 | jim | 2004-08-11 16:39:37 -0400 (Wed, 11 Aug 2004) | 4 lines
Fixed http://collector.zope.org/Zope3-dev/235:
Multiple bugs in AllRolePermissions.html
Changed:
U Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/manage_roleform.pt
U Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/rolepermissionview.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/manage_roleform.pt
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/manage_roleform.pt 2004-08-11 21:18:11 UTC (rev 27040)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/manage_roleform.pt 2004-08-11 21:42:23 UTC (rev 27041)
@@ -6,19 +6,19 @@
tal:condition="status"
tal:content="status" />
- <p class="form-help" i18n:translate="">
- Helpful message explaining about how to set specific roles
- </p>
<div tal:define="role
python:view.roleForID(request.get('role_to_manage'))" tal:omit-tag="">
- <p class="form-text" i18n:translate="">
- Permissions assigned to the role
- <strong tal:content="role/title"
- i18n:name="role_title">Great Master Guru</strong>
- (id: <strong tal:content="role/id"
- i18n:name="role_id">Zope.Some.Role</strong>)
+ <p class="form-help" i18n:translate="">
+ This page shows the permissions allowed and denied the role
+ <strong tal:content="role/title"
+ i18n:name="role_title">Great Master Guru</strong>
+ (id: <strong tal:content="role/id"
+ i18n:name="role_id">Zope.Some.Role</strong>).
+ To change settings, simply select different permissions in the
+ Allow or Deny lists. Make sure you don't select the same
+ permission in both lists though.
</p>
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/rolepermissionview.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/rolepermissionview.py 2004-08-11 21:18:11 UTC (rev 27040)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/rolepermissionview.py 2004-08-11 21:42:23 UTC (rev 27041)
@@ -17,9 +17,11 @@
"""
from datetime import datetime
+from zope.i18n import translate
from zope.interface import implements
from zope.app import zapi
+from zope.app.exception.interfaces import UserError
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.security.settings import Unset, Allow, Deny
from zope.app.security.interfaces import IPermission
@@ -30,15 +32,26 @@
def roles(self):
roles = getattr(self, '_roles', None)
if roles is None:
- roles = self._roles = \
- [role for name, role in zapi.getUtilitiesFor(IRole)]
+ roles = [
+ (translate(role.title, context=self.request).strip(), role)
+ for name, role in zapi.getUtilitiesFor(IRole)]
+ roles.sort()
+ roles = self._roles = [role for name, role in roles]
return roles
def permissions(self):
permissions = getattr(self, '_permissions', None)
if permissions is None:
- permissions = self._permissions = \
- [perm for name, perm in zapi.getUtilitiesFor(IPermission)]
+ permissions = [
+ (translate(perm.title, context=self.request).strip(), perm)
+ for name, perm in zapi.getUtilitiesFor(IPermission)
+ if name != 'zope.Public']
+ permissions.sort()
+
+
+ permissions = self._permissions = [perm
+ for name, perm in permissions]
+
return permissions
def availableSettings(self, noacquire=False):
@@ -123,7 +136,11 @@
for permission in self.permissions():
rperm = permission.id
if rperm in allowed and rperm in denied:
- raise ValueError("Incorrect setting for %s" % rperm)
+ raise UserError(
+ 'You chose both allow and deny for permission "%s". '
+ 'This is not allowed.'
+ % translate(permission.title, context=self.request)
+ )
if rperm in allowed:
prm.grantPermissionToRole(rperm, role_id)
elif rperm in denied:
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py 2004-08-11 21:18:11 UTC (rev 27040)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/browser/tests/test_rolepermissionview.py 2004-08-11 21:42:23 UTC (rev 27041)
@@ -17,7 +17,12 @@
"""
import unittest
+from zope.i18n.interfaces import ITranslationDomain
+from zope.i18nmessageid import MessageID
+import zope.interface
from zope.publisher.browser import TestRequest
+
+from zope.app.exception.interfaces import UserError
from zope.app.publisher.browser import BrowserView
from zope.app.tests import ztapi
from zope.app.security.permission import Permission
@@ -31,9 +36,21 @@
from zope.app.securitypolicy.browser.rolepermissionview \
import RolePermissionView
+from zope.app.tests import ztapi
+
class RolePermissionView(RolePermissionView, BrowserView):
"""Adding BrowserView to Utilities; this is usually done by ZCML."""
+class TranslationDomain:
+ zope.interface.implements(ITranslationDomain)
+
+ def __init__(self, **translations):
+ self.translations = translations
+
+ def translate(self, msgid, *ignored, **also_ignored):
+ return self.translations.get(msgid, msgid)
+
+
def defineRole(id, title=None, description=None):
role = Role(id, title, description)
ztapi.provideUtility(IRole, role, name=role.id)
@@ -48,33 +65,24 @@
def setUp(self):
PlacefulSetup.setUp(self)
- defineRole('manager', 'Manager')
- defineRole('member', 'Member')
- definePermission('read', 'Read')
- definePermission('write', 'Write')
+ defineRole('manager', MessageID('Manager', 'testdomain'))
+ defineRole('member', MessageID('Member', 'testdomain'))
+ definePermission('read', MessageID('Read', 'testdomain'))
+ definePermission('write', MessageID('Write', 'testdomain'))
self.view = RolePermissionView(RolePermissionManager(), None)
+ ztapi.provideUtility(ITranslationDomain,
+ TranslationDomain(Member="A Member",
+ Write="A Write",
+ ),
+ 'testdomain')
def testRoles(self):
- roles = list(self.view.roles())
- ids = ['manager', 'member']
- titles = ['Manager', 'Member']
- for role in roles:
- i=ids.index(role.id)
- self.failIf(i < 0)
- self.assertEqual(role.title, titles[i])
- del ids[i]
- del titles[i]
+ self.assertEqual([role.title for role in self.view.roles()],
+ ["Member", "Manager"])
def testPermisssions(self):
- permissions = list(self.view.permissions())
- ids = ['read', 'write', 'zope.Public']
- titles = ['Read', 'Write', 'Public']
- for permission in permissions:
- i=ids.index(permission.id)
- self.failIf(i < 0)
- self.assertEqual(permission.title, titles[i])
- del ids[i]
- del titles[i]
+ self.assertEqual([role.title for role in self.view.permissions()],
+ ["Write", "Read"])
def testMatrix(self):
roles = self.view.roles()
@@ -192,6 +200,15 @@
self.assertEquals(pinfo['setting'], 'Unset')
+ def testRolePermissions_UserError(self):
+ env={'Allow': ['read'],
+ 'Deny': ['read'],
+ 'SUBMIT_ROLE': 1,
+ 'role_id': 'member'}
+ self.view.request = TestRequest(environ=env)
+ self.assertRaises(UserError, self.view.update, 1)
+
+
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
More information about the Zope3-Checkins
mailing list