Skip to content

Commit 21c96e3

Browse files
author
Richard Jones
committed
more doc fixes
simplified the security API, and bumped those changes around a couple more TODO items so I don't forget
1 parent 0a5db26 commit 21c96e3

File tree

8 files changed

+86
-100
lines changed

8 files changed

+86
-100
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Feature:
3737
- unless in debug mode, keep a single persistent connection through a
3838
single web or mailgw request.
3939
- HTTP Basic Authentication (sf patch 1067690)
40+
- extended security.addPermissionToRole to allow skipping the separate
41+
getPermission call
4042

4143
Fixed:
4244
- postgres backend open doesn't hide corruption in schema (sf bug 956375)
@@ -49,6 +51,7 @@ Fixed:
4951
Fixed:
5052
- reset ID counters if the database is cleared (thanks William)
5153
- apply IE caching "fix" to automatically serve up all pages expired
54+
- fix typo (sf patch 1076629)
5255

5356

5457
2004-10-26 0.7.9

TODO.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Required:
44
- Security review:
55
- write up security model used in classic tracker
66
- ensure classic template actually implements the model detailed
7+
- "Web Access" revocation needs work - the context should not be rendered
8+
- should redefinitions of a permission keyed off (name, classname) generate
9+
an error or a warning? Something needs to be generated, as such
10+
occurrances are an error in the schema...
11+
- check that the Provisional User example actually works as advertised
712

813
Optionally:
914
- clean up roundup.cgi (switch to config file, use proper logging, remove

doc/customizing.txt

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.160 $
5+
:Version: $Revision: 1.161 $
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
@@ -1133,18 +1133,14 @@ web actions`_).
11331133

11341134
Each action class also has a ``*permission*`` method which determines whether
11351135
the action is permissible given the current user. The base permission checks
1136-
are:
1137-
1138-
XXX REVIEW for Permissions changes
1136+
for each action are:
11391137

11401138
**login**
1141-
Determine whether the user has permission to log in. Base behaviour is
1142-
to check the user has "Web Access".
1139+
Determine whether the user has the "Web Access" Permission.
11431140
**logout**
11441141
No permission checks are made.
11451142
**register**
1146-
Determine whether the user has permission to register. Base behaviour
1147-
is to check the user has the "Web Registration" Permission.
1143+
Determine whether the user has the "Web Registration" Permission.
11481144
**edit**
11491145
Determine whether the user has permission to edit this item. If we're
11501146
editing the "user" class, users are allowed to edit their own details -
@@ -1155,11 +1151,9 @@ XXX REVIEW for Permissions changes
11551151
additional property checks are made. Additionally, new user items may
11561152
be created if the user has the "Web Registration" Permission.
11571153
**editCSV**
1158-
Determine whether the user has permission to edit this class. Base
1159-
behaviour is to check whether the user may edit this class.
1154+
Determine whether the user has permission to edit this class.
11601155
**search**
1161-
Determine whether the user has permission to search this class. Base
1162-
behaviour is to check whether the user may view this class.
1156+
Determine whether the user has permission to view this class.
11631157

11641158

11651159
Special form variables
@@ -1764,7 +1758,12 @@ history render the journal of the current item as HTML
17641758
renderQueryForm specific to the "query" class - render the search form
17651759
for the query
17661760
hasPermission specific to the "user" class - determine whether the
1767-
user has a Permission
1761+
user has a Permission. The signature is::
1762+
1763+
hasPermission(self, permission, [classname=],
1764+
[property=], [itemid=])
1765+
1766+
where the classname defaults to the current context.
17681767
is_edit_ok is the user allowed to Edit the current item?
17691768
is_view_ok is the user allowed to View the current item?
17701769
is_retired is the item retired?
@@ -2674,9 +2673,9 @@ them to various roles. Simply add the new "category" to both lists::
26742673
# to regular users now
26752674
for cl in 'issue', 'file', 'msg', 'category':
26762675
p = db.security.getPermission('View', cl)
2677-
db.security.addPermissionToRole('User', p)
2678-
p = db.security.getPermission('Edit', cl)
2679-
db.security.addPermissionToRole('User', p)
2676+
db.security.addPermissionToRole('User', 'View', cl)
2677+
db.security.addPermissionToRole('User', 'Edit', cl)
2678+
db.security.addPermissionToRole('User', 'Create', cl)
26802679

26812680
These lines assign the View and Edit Permissions to the "User" role, so
26822681
that normal users can view and edit "category" objects.
@@ -3115,10 +3114,9 @@ Optionally, you might want to restrict the users able to access this new
31153114
class to just the users with a new "SysAdmin" Role. To do this, we add
31163115
some security declarations::
31173116

3118-
p = db.security.getPermission('View', 'support')
3119-
db.security.addPermissionToRole('SysAdmin', p)
3120-
p = db.security.getPermission('Edit', 'support')
3121-
db.security.addPermissionToRole('SysAdmin', p)
3117+
db.security.addPermissionToRole('SysAdmin', 'View', 'support')
3118+
db.security.addPermissionToRole('SysAdmin', 'Create', 'support')
3119+
db.security.addPermissionToRole('SysAdmin', 'Edit', 'support')
31223120

31233121
You would then (as an "admin" user) edit the details of the appropriate
31243122
users, and add "SysAdmin" to their Roles list.
@@ -3908,21 +3906,31 @@ First up, we create the new Role and Permission structure in
39083906
# New users not approved by the admin
39093907
db.security.addRole(name='Provisional User',
39103908
description='New user registered via web or email')
3911-
p = db.security.addPermission(name='Edit Own', klass='issue',
3912-
description='Can only edit own issues')
3913-
db.security.addPermissionToRole('Provisional User', p)
39143909

3915-
# Assign the access and edit Permissions for issue to new users now
3916-
p = db.security.getPermission('View', 'issue')
3910+
# These users need to be able to view and create issues but only edit
3911+
# and view their own
3912+
db.security.addPermissionToRole('Provisional User', 'Create', 'issue')
3913+
def own_issue(db, userid, itemid):
3914+
'''Determine whether the userid matches the creator of the issue.'''
3915+
return userid == db.issue.get(itemid, 'creator')
3916+
p = db.security.addPermission(name='Edit Own Issues', klass='issue',
3917+
code=own_issue, description='Can only edit own issues')
39173918
db.security.addPermissionToRole('Provisional User', p)
3918-
p = db.security.getPermission('Edit', 'issue')
3919+
p = db.security.addPermission(name='View Own Issues', klass='issue',
3920+
code=own_issue, description='Can only view own issues')
39193921
db.security.addPermissionToRole('Provisional User', p)
39203922

3923+
# Assign the Permissions for issue-related classes
3924+
for cl in 'file', 'msg', 'query', 'keyword':
3925+
db.security.addPermissionToRole('User', 'View', cl)
3926+
db.security.addPermissionToRole('User', 'Edit', cl)
3927+
db.security.addPermissionToRole('User', 'Create', cl)
3928+
for cl in 'priority', 'status':
3929+
db.security.addPermissionToRole('User', 'View', cl)
3930+
39213931
# and give the new users access to the web and email interface
3922-
p = db.security.getPermission('Web Access')
3923-
db.security.addPermissionToRole('Provisional User', p)
3924-
p = db.security.getPermission('Email Access')
3925-
db.security.addPermissionToRole('Provisional User', p)
3932+
db.security.addPermissionToRole('Provisional User', 'Web Access')
3933+
db.security.addPermissionToRole('Provisional User', 'Email Access')
39263934

39273935

39283936
Then in the ``config.ini`` we change the Role assigned to newly-registered
@@ -3933,23 +3941,6 @@ users, replacing the existing ``'User'`` values::
39333941
new_web_user_roles = 'Provisional User'
39343942
new_email_user_roles = 'Provisional User'
39353943

3936-
Finally we add a new *auditor* to the ``detectors`` directory called
3937-
``provisional_user_auditor.py``::
3938-
3939-
def audit_provisionaluser(db, cl, nodeid, newvalues):
3940-
''' New users are only allowed to modify their own issues.
3941-
'''
3942-
if (db.getuid() != cl.get(nodeid, 'creator')
3943-
and db.security.hasPermission('Edit Own', db.getuid(), cl.classname)):
3944-
raise ValueError, ('You are only allowed to edit your own %s'
3945-
% cl.classname)
3946-
3947-
def init(db):
3948-
# fire before changes are made
3949-
db.issue.audit('set', audit_provisionaluser)
3950-
db.issue.audit('retire', audit_provisionaluser)
3951-
db.issue.audit('restore', audit_provisionaluser)
3952-
39533944
Note that some older trackers might also want to change the ``page.html``
39543945
template as follows::
39553946

@@ -4200,7 +4191,6 @@ Setting up a "wizard" (or "druid") for controlled adding of issues
42004191
you're done (the standard context/submit method can do this for you).
42014192

42024193

4203-
42044194
-------------------
42054195

42064196
Back to `Table of Contents`_

doc/installation.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ at so you may start playing. Three users will be set up:
114114
Installation
115115
============
116116

117-
Set aside 15-30 minutes. Please make sure you're using a supported version of
118-
Python -- see `testing your python`_. There's several steps to follow in your
117+
Set aside 15-30 minutes. There's several steps to follow in your
119118
installation:
120119

121120
1. `basic installation steps`_ if Roundup is not installed on your system

roundup/cgi/templating.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,8 @@ class _HTMLUser(_HTMLItem):
10231023
'''Add ability to check for permissions on users.
10241024
'''
10251025
_marker = []
1026-
def hasPermission(self, permission, classname=_marker):
1026+
def hasPermission(self, permission, classname=_marker,
1027+
property=None, itemid=None):
10271028
'''Determine if the user has the Permission.
10281029
10291030
The class being tested defaults to the template's class, but may

roundup/security.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,18 @@ def addRole(self, **propspec):
195195
self.role[role.name] = role
196196
return role
197197

198-
def addPermissionToRole(self, rolename, permission):
198+
def addPermissionToRole(self, rolename, permission, classname=None):
199199
''' Add the permission to the role's permission list.
200200
201201
'rolename' is the name of the role to add the permission to.
202+
203+
'permission' is either a Permission *or* a permission name
204+
accompanied by 'classname' (thus in the second case a Permission
205+
is obtained by passing 'permission' and 'classname' to
206+
self.getPermission)
202207
'''
208+
if not isinstance(permission, Permission):
209+
permission = self.getPermission(permission, classname)
203210
role = self.role[rolename.lower()]
204211
role.permissions.append(permission)
205212

templates/classic/schema.py

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,31 @@
8585
# REGULAR USERS
8686
#
8787
# Give the regular users access to the web and email interface
88-
p = db.security.getPermission('Web Access')
89-
db.security.addPermissionToRole('User', p)
90-
p = db.security.getPermission('Email Access')
91-
db.security.addPermissionToRole('User', p)
88+
db.security.addPermissionToRole('User', 'Web Access')
89+
db.security.addPermissionToRole('User', 'Email Access')
9290

9391
# Assign the access and edit Permissions for issue, file and message
9492
# to regular users now
9593
for cl in 'issue', 'file', 'msg', 'query', 'keyword':
96-
p = db.security.getPermission('View', cl)
97-
db.security.addPermissionToRole('User', p)
98-
p = db.security.getPermission('Edit', cl)
99-
db.security.addPermissionToRole('User', p)
100-
p = db.security.getPermission('Create', cl)
101-
db.security.addPermissionToRole('User', p)
94+
db.security.addPermissionToRole('User', 'View', cl)
95+
db.security.addPermissionToRole('User', 'Edit', cl)
96+
db.security.addPermissionToRole('User', 'Create', cl)
10297
for cl in 'priority', 'status':
103-
p = db.security.getPermission('View', cl)
104-
db.security.addPermissionToRole('User', p)
98+
db.security.addPermissionToRole('User', 'View', cl)
10599

106100
# May users view other user information? Comment these lines out
107101
# if you don't want them to
108-
p = db.security.getPermission('View', 'user')
109-
db.security.addPermissionToRole('User', p)
102+
db.security.addPermissionToRole('User', 'View', 'user')
110103

111-
# Users should be able to edit their own details. Note that this
112-
# permission is limited to only the situation where the Viewed or
113-
# Edited item is their own.
104+
# Users should be able to edit their own details -- this permission is
105+
# limited to only the situation where the Viewed or Edited item is their own.
114106
def own_record(db, userid, itemid):
115107
'''Determine whether the userid matches the item being accessed.'''
116108
return userid == itemid
117-
p = db.security.addPermission(name='View', klass='user', check=own_record,
109+
p = db.security.addPermission(name='View Self', klass='user', check=own_record,
118110
description="User is allowed to view their own user details")
119-
p = db.security.addPermission(name='Edit', klass='user', check=own_record,
111+
db.security.addPermissionToRole('User', p)
112+
p = db.security.addPermission(name='Edit Self', klass='user', check=own_record,
120113
description="User is allowed to edit their own user details")
121114
db.security.addPermissionToRole('User', p)
122115

@@ -126,35 +119,29 @@ def own_record(db, userid, itemid):
126119
# Let anonymous users access the web interface. Note that almost all
127120
# trackers will need this Permission. The only situation where it's not
128121
# required is in a tracker that uses an HTTP Basic Authenticated front-end.
129-
p = db.security.getPermission('Web Access')
130-
db.security.addPermissionToRole('Anonymous', p)
122+
db.security.addPermissionToRole('Anonymous', 'Web Access')
131123

132124
# Let anonymous users access the email interface (note that this implies
133125
# that they will be registered automatically, hence they will need the
134126
# "Create" user Permission below)
135-
p = db.security.getPermission('Email Access')
136-
db.security.addPermissionToRole('Anonymous', p)
127+
db.security.addPermissionToRole('Anonymous', 'Email Access')
137128

138129
# Assign the appropriate permissions to the anonymous user's Anonymous
139130
# Role. Choices here are:
140131
# - Allow anonymous users to register
141-
p = db.security.getPermission('Create', 'user')
142-
db.security.addPermissionToRole('Anonymous', p)
132+
db.security.addPermissionToRole('Anonymous', 'Create', 'user')
143133

144134
# Allow anonymous users access to view issues (and the related, linked
145135
# information)
146136
for cl in 'issue', 'file', 'msg', 'keyword', 'priority', 'status':
147-
p = db.security.getPermission('View', cl)
148-
db.security.addPermissionToRole('Anonymous', p)
137+
db.security.addPermissionToRole('Anonymous', 'View', cl)
149138

150139
# [OPTIONAL]
151140
# Allow anonymous users access to create or edit "issue" items (and the
152141
# related file and message items)
153142
#for cl in 'issue', 'file', 'msg':
154-
# p = db.security.getPermission('Create', cl)
155-
# db.security.addPermissionToRole('Anonymous', p)
156-
# p = db.security.getPermission('Edit', cl)
157-
# db.security.addPermissionToRole('Anonymous', p)
143+
# db.security.addPermissionToRole('Anonymous', 'Create', cl)
144+
# db.security.addPermissionToRole('Anonymous', 'Edit', cl)
158145

159146

160147
# vim: set filetype=python sts=4 sw=4 et si :

templates/minimal/schema.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,22 @@
2525
# REGULAR USERS
2626
#
2727
# Give the regular users access to the web and email interface
28-
p = db.security.getPermission('Web Access')
29-
db.security.addPermissionToRole('User', p)
30-
p = db.security.getPermission('Email Access')
31-
db.security.addPermissionToRole('User', p)
28+
db.security.addPermissionToRole('User', 'Web Access')
29+
db.security.addPermissionToRole('User', 'Email Access')
3230

3331
# May users view other user information?
3432
# Comment these lines out if you don't want them to
35-
p = db.security.getPermission('View', 'user')
36-
db.security.addPermissionToRole('User', p)
33+
db.security.addPermissionToRole('User', 'View', 'user')
3734

38-
# Users should be able to edit their own details.
39-
# Note that this permission is limited to only the situation
40-
# where the Viewed or Edited item is their own.
35+
# Users should be able to edit their own details -- this permission is
36+
# limited to only the situation where the Viewed or Edited item is their own.
4137
def own_record(db, userid, itemid):
4238
'''Determine whether the userid matches the item being accessed.'''
4339
return userid == itemid
44-
p = db.security.addPermission(name='View', klass='user', check=own_record,
40+
p = db.security.addPermission(name='View Self', klass='user', check=own_record,
4541
description="User is allowed to view their own user details")
46-
p = db.security.addPermission(name='Edit', klass='user', check=own_record,
42+
db.security.addPermissionToRole('User', p)
43+
p = db.security.addPermission(name='Edit Self', klass='user', check=own_record,
4744
description="User is allowed to edit their own user details")
4845
db.security.addPermissionToRole('User', p)
4946

@@ -53,19 +50,16 @@ def own_record(db, userid, itemid):
5350
# Let anonymous users access the web interface. Note that almost all
5451
# trackers will need this Permission. The only situation where it's not
5552
# required is in a tracker that uses an HTTP Basic Authenticated front-end.
56-
p = db.security.getPermission('Web Access')
57-
db.security.addPermissionToRole('Anonymous', p)
53+
db.security.addPermissionToRole('Anonymous', 'Web Access')
5854

5955
# Let anonymous users access the email interface (note that this implies
6056
# that they will be registered automatically, hence they will need the
6157
# "Create" user Permission below)
62-
p = db.security.getPermission('Email Access')
63-
db.security.addPermissionToRole('Anonymous', p)
58+
db.security.addPermissionToRole('Anonymous', 'Email Access')
6459

6560
# Assign the appropriate permissions to the anonymous user's
6661
# Anonymous Role. Choices here are:
6762
# - Allow anonymous users to register
68-
p = db.security.getPermission('Create', 'user')
69-
db.security.addPermissionToRole('Anonymous', p)
63+
db.security.addPermissionToRole('Anonymous', 'Create', 'user')
7064

7165
# vim: set et sts=4 sw=4 :

0 commit comments

Comments
 (0)