Skip to content

Commit 3638b2f

Browse files
author
Richard Jones
committed
Fix to hasPermission, thanks Stefan Seefeld.
1 parent 3a6b418 commit 3638b2f

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

doc/customizing.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.12 $
5+
:Version: $Revision: 1.13 $
66

77
.. contents::
88

99

1010
What You Can Do
1111
---------------
1212

13-
Customisation of Roundup can take one of three forms:
13+
Customisation of Roundup can take one of four forms:
1414

1515
1. `instance configuration`_ file changes
16-
2. `instance schema`_ changes
16+
2. database, or `instance schema`_ changes
1717
3. "definition" class `database content`_ changes
18+
4. behavioural changes, through detectors_
1819

1920
The third case is special because it takes two distinctly different forms
2021
depending upon whether the instance has been initialised or not. The other two
@@ -515,7 +516,7 @@ Create a node in the database. This is generally used to create nodes in the
515516

516517
Detectors - adding behaviour to your tracker
517518
--------------------------------------------
518-
.. _`detectors`:
519+
.. _detectors:
519520

520521
The detectors in your instance fire before (*auditors*) and after (*reactors*)
521522
changes to the contents of your database. They are Python modules that sit in
@@ -537,7 +538,7 @@ ones. The existing detectors installed for you are:
537538
See the detectors section in the `design document`__ for details of the
538539
interface for detectors.
539540

540-
__ spec.html
541+
__ design.html
541542

542543
Sample additional detectors that have been found useful will appear in the
543544
``detectors`` directory of the Roundup distribution:

doc/index.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ Roch'e Compaan,
6767
Engelbert Gruber,
6868
Juergen Hermann,
6969
Gordon McMillan,
70-
Patrick Ohly.
70+
Patrick Ohly,
71+
Stefan Seefeld.
7172

7273

7374
License

roundup/security.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,13 @@ def getPermission(self, permission, classname=None):
7878
'''
7979
if not self.permission.has_key(permission):
8080
raise ValueError, 'No permission "%s" defined'%permission
81+
82+
# look through all the permissions of the given name
8183
for perm in self.permission[permission]:
84+
# if we're passed a classname, the permission must match
8285
if perm.klass is not None and perm.klass == classname:
8386
return perm
87+
# otherwise the permission klass must be unset
8488
elif not perm.klass and not classname:
8589
return perm
8690
raise ValueError, 'No permission "%s" defined for "%s"'%(permission,
@@ -96,9 +100,14 @@ def hasPermission(self, permission, userid, classname=None):
96100
for rolename in roles.split(','):
97101
if not rolename:
98102
continue
103+
# for each of the user's Roles, check the permissions
99104
for perm in self.role[rolename].permissions:
100-
if perm.klass is None or perm.klass == classname:
101-
return 1
105+
# permission name match?
106+
if perm.name == permission:
107+
# permission klass match?
108+
if perm.klass is None or perm.klass == classname:
109+
# we have a winner
110+
return 1
102111
return 0
103112

104113
def hasNodePermission(self, classname, nodeid, **propspec):

test/test_security.py

Lines changed: 11 additions & 2 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.2 2002-07-26 08:27:00 richard Exp $
21+
# $Id: test_security.py,v 1.3 2002-07-29 21:53:29 richard Exp $
2222

2323
import os, unittest, shutil
2424

@@ -71,7 +71,9 @@ def testDBinit(self):
7171

7272
def testAccessControls(self):
7373
self.testDBinit()
74-
self.testInitialiseSecurity()
74+
ei = self.db.security.addPermission(name="Edit", klass="issue",
75+
description="User is allowed to edit issues")
76+
self.db.security.addPermissionToRole('User', ei)
7577

7678
# test class-level access
7779
userid = self.db.user.lookup('admin')
@@ -84,6 +86,8 @@ def testAccessControls(self):
8486
'issue'), 1)
8587
self.assertEquals(self.db.security.hasPermission('Edit', userid,
8688
'user'), 0)
89+
self.assertEquals(self.db.security.hasPermission('View', userid,
90+
'issue'), 0)
8791

8892
# test node-level access
8993
issueid = self.db.issue.create(title='foo', assignedto='admin')
@@ -102,6 +106,11 @@ def suite():
102106

103107
#
104108
# $Log: not supported by cvs2svn $
109+
# Revision 1.2 2002/07/26 08:27:00 richard
110+
# Very close now. The cgi and mailgw now use the new security API. The two
111+
# templates have been migrated to that setup. Lots of unit tests. Still some
112+
# issue in the web form for editing Roles assigned to users.
113+
#
105114
# Revision 1.1 2002/07/25 07:14:06 richard
106115
# Bugger it. Here's the current shape of the new security implementation.
107116
# Still to do:

0 commit comments

Comments
 (0)