Skip to content

Commit 26e9a2b

Browse files
author
Richard Jones
committed
fix security check for hasPermission(Permission, None)
add hasRole to HTMLUser
1 parent c1390a5 commit 26e9a2b

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ are given with the most recent entry first.
44
2006-??-?? 1.0.1
55
Feature:
66
- scripts/import_sf.py will import a tracker from Sourceforge.NET
7+
- added hasRole() to HTMLUser
78

89
Fixed:
910
- SQL generation for sort/group by separate Link properties (sf bug
1011
1417565)
1112
- fix timezone offsetting in email Date: header
13+
- fix security check for hasPermission('Permission', None)
14+
1215

1316
2006-01-27 1.0
1417
Feature:

doc/customizing.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.190 $
5+
:Version: $Revision: 1.191 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -1916,6 +1916,11 @@ hasPermission specific to the "user" class - determine whether the
19161916
[property=], [itemid=])
19171917

19181918
where the classname defaults to the current context.
1919+
hasRole specific to the "user" class - determine whether the
1920+
user has a Role. The signature is::
1921+
1922+
hasRole(self, rolename)
1923+
19191924
is_edit_ok is the user allowed to Edit the current item?
19201925
is_view_ok is the user allowed to View the current item?
19211926
is_retired is the item retired?

roundup/cgi/templating.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,9 +1119,16 @@ def hasPermission(self, permission, classname=_marker,
11191119
'''
11201120
if classname is self._marker:
11211121
classname = self._client.classname
1122-
return self._client.db.security.hasPermission(permission,
1122+
return self._db.security.hasPermission(permission,
11231123
self._nodeid, classname, property, itemid)
11241124

1125+
def hasRole(self, rolename):
1126+
'''Determine whether the user has the Role.'''
1127+
roles = self._db.user.get(self._nodeid, 'roles').split(',')
1128+
for role in roles:
1129+
if role.strip() == rolename: return True
1130+
return False
1131+
11251132
def HTMLItem(client, classname, nodeid, anonymous=0):
11261133
if classname == 'user':
11271134
return _HTMLUser(client, classname, nodeid, anonymous)

roundup/security.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def test(self, db, permission, classname, property, userid, itemid):
3939
return 0
4040

4141
# are we checking the correct class
42-
if (classname is not None and self.klass is not None
43-
and self.klass != classname):
42+
if self.klass is not None and self.klass != classname:
4443
return 0
4544

4645
# what about property?

test/test_security.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
# $Id: test_security.py,v 1.9 2005-01-28 04:07:58 richard Exp $
21+
# $Id: test_security.py,v 1.10 2006-02-03 04:04:37 richard Exp $
2222

2323
import os, unittest, shutil
2424

@@ -41,18 +41,28 @@ def testInterfaceSecurity(self):
4141
# TODO: some asserts
4242

4343
def testInitialiseSecurity(self):
44-
''' Create some Permissions and Roles on the security object
45-
46-
This function is directly invoked by security.Security.__init__()
47-
as a part of the Security object instantiation.
48-
'''
4944
ei = self.db.security.addPermission(name="Edit", klass="issue",
5045
description="User is allowed to edit issues")
5146
self.db.security.addPermissionToRole('User', ei)
5247
ai = self.db.security.addPermission(name="View", klass="issue",
5348
description="User is allowed to access issues")
5449
self.db.security.addPermissionToRole('User', ai)
5550

51+
def testAdmin(self):
52+
ei = self.db.security.addPermission(name="Edit", klass="issue",
53+
description="User is allowed to edit issues")
54+
self.db.security.addPermissionToRole('User', ei)
55+
ei = self.db.security.addPermission(name="Edit", klass=None,
56+
description="User is allowed to edit issues")
57+
self.db.security.addPermissionToRole('Admin', ei)
58+
59+
u1 = self.db.user.create(username='one', roles='Admin')
60+
u2 = self.db.user.create(username='two', roles='User')
61+
62+
self.assert_(self.db.security.hasPermission('Edit', u1, None))
63+
self.assert_(not self.db.security.hasPermission('Edit', u2, None))
64+
65+
5666
def testGetPermission(self):
5767
self.db.security.getPermission('Edit')
5868
self.db.security.getPermission('View')

0 commit comments

Comments
 (0)