Skip to content

Commit 9139d9d

Browse files
author
Richard Jones
committed
Added the web access and email access permissions..
...so people can restrict access to users who register through the email interface (for example). Also added "security" command to the roundup-admin interface to display the Role/Permission config for an instance.
1 parent c729684 commit 9139d9d

File tree

5 files changed

+123
-33
lines changed

5 files changed

+123
-33
lines changed

roundup/admin.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.19 2002-07-25 07:14:05 richard Exp $
19+
# $Id: admin.py,v 1.20 2002-08-01 00:56:22 richard Exp $
2020

2121
import sys, os, getpass, getopt, re, UserDict, shlex, shutil
2222
try:
@@ -249,7 +249,6 @@ def help_initopts(self):
249249
backends = roundup.backends.__all__
250250
print _('Back ends:'), ', '.join(backends)
251251

252-
253252
def do_install(self, instance_home, args):
254253
'''Usage: install [template [backend [admin password]]]
255254
Install a new Roundup instance.
@@ -981,6 +980,30 @@ def do_reindex(self, args):
981980
self.db.reindex()
982981
return 0
983982

983+
def do_security(self, args):
984+
'''Usage: security [Role name]
985+
Display the Permissions available to one or all Roles.
986+
'''
987+
if len(args) == 1:
988+
role = args[0]
989+
try:
990+
roles = [(args[0], self.db.security.role[args[0]])]
991+
except KeyError:
992+
print _('No such Role "%(role)s"')%locals()
993+
return 1
994+
else:
995+
roles = self.db.security.role.items()
996+
roles.sort()
997+
for rolename, role in roles:
998+
print _('Role "%(name)s":')%role.__dict__
999+
for permission in role.permissions:
1000+
if permission.klass:
1001+
print _(' %(description)s (%(name)s for "%(klass)s" '
1002+
'only)')%permission.__dict__
1003+
else:
1004+
print _(' %(description)s (%(name)s)')%permission.__dict__
1005+
return 0
1006+
9841007
def run_command(self, args):
9851008
'''Run a single command
9861009
'''
@@ -1131,6 +1154,14 @@ def main(self):
11311154

11321155
#
11331156
# $Log: not supported by cvs2svn $
1157+
# Revision 1.19 2002/07/25 07:14:05 richard
1158+
# Bugger it. Here's the current shape of the new security implementation.
1159+
# Still to do:
1160+
# . call the security funcs from cgi and mailgw
1161+
# . change shipped templates to include correct initialisation and remove
1162+
# the old config vars
1163+
# ... that seems like a lot. The bulk of the work has been done though. Honest :)
1164+
#
11341165
# Revision 1.18 2002/07/18 11:17:30 gmcm
11351166
# Add Number and Boolean types to hyperdb.
11361167
# Add conversion cases to web, mail & admin interfaces.

roundup/cgi_client.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: cgi_client.py,v 1.154 2002-07-31 23:57:36 richard Exp $
18+
# $Id: cgi_client.py,v 1.155 2002-08-01 00:56:22 richard Exp $
1919

2020
__doc__ = """
2121
WWW request handler (also used in the stand-alone server).
@@ -41,6 +41,8 @@ def initialiseSecurity(security):
4141
'''
4242
security.addPermission(name="Web Registration",
4343
description="User may register through the web")
44+
security.addPermission(name="Web Access",
45+
description="User may access the web interface")
4446

4547
# doing Role stuff through the web - make sure Admin can
4648
p = security.addPermission(name="Web Roles",
@@ -1407,8 +1409,9 @@ def logout(self, message=None):
14071409
def opendb(self, user):
14081410
''' Open the database - but include the definition of the sessions db.
14091411
'''
1410-
# open the db
1411-
self.db = self.instance.open(user)
1412+
# open the db if the user has changed
1413+
if not hasattr(self, 'db') or user != self.db.journaltag:
1414+
self.db = self.instance.open(user)
14121415

14131416
def main(self):
14141417
''' Wrap the request and handle unauthorised requests
@@ -1489,29 +1492,39 @@ def main_action(self):
14891492
return
14901493
# figure the resulting page
14911494
action = self.form['__destination_url'].value
1492-
if not action:
1493-
action = 'index'
1494-
self.do_action(action)
1495-
return
14961495

14971496
# allow anonymous people to register
1498-
if action == 'newuser_action':
1497+
elif action == 'newuser_action':
14991498
# try to add the user
15001499
if not self.newuser_action():
15011500
return
15021501
# figure the resulting page
15031502
action = self.form['__destination_url'].value
1504-
if not action:
1505-
action = 'index'
1503+
1504+
# ok, now we have figured out who the user is, make sure the user
1505+
# has permission to use this interface
1506+
userid = self.db.user.lookup(self.user)
1507+
if not self.db.security.hasPermission('Web Access', userid):
1508+
raise Unauthorised, \
1509+
_("You do not have permission to access this interface.")
15061510

15071511
# re-open the database for real, using the user
15081512
self.opendb(self.user)
15091513

1510-
# just a regular action
1511-
self.do_action(action)
1514+
# make sure we have a sane action
1515+
if not action:
1516+
action = 'index'
15121517

1513-
# commit all changes to the database
1514-
self.db.commit()
1518+
# just a regular action
1519+
try:
1520+
self.do_action(action)
1521+
except Unauthorised, message:
1522+
# if unauth is raised here, then a page header will have
1523+
# been displayed
1524+
self.write('<p class="system-msg">%s</p>'%message)
1525+
else:
1526+
# commit all changes to the database
1527+
self.db.commit()
15151528

15161529
def do_action(self, action, dre=re.compile(r'([^\d]+)(\d+)'),
15171530
nre=re.compile(r'new(\w+)'), sre=re.compile(r'search(\w+)')):
@@ -1690,6 +1703,9 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
16901703

16911704
#
16921705
# $Log: not supported by cvs2svn $
1706+
# Revision 1.154 2002/07/31 23:57:36 richard
1707+
# . web forms may now unset Link values (like assignedto)
1708+
#
16931709
# Revision 1.153 2002/07/31 22:40:50 gmcm
16941710
# Fixes to the search form and saving queries.
16951711
# Fixes to sorting in back_metakit.py.

roundup/mailgw.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.79 2002-07-26 08:26:59 richard Exp $
76+
$Id: mailgw.py,v 1.80 2002-08-01 00:56:22 richard Exp $
7777
'''
7878

7979

@@ -104,6 +104,8 @@ def initialiseSecurity(security):
104104
'''
105105
newid = security.addPermission(name="Email Registration",
106106
description="Anonymous may register through e-mail")
107+
security.addPermission(name="Email Access",
108+
description="User may use the email interface")
107109

108110
class Message(mimetools.Message):
109111
''' subclass mimetools.Message so we can retrieve the parts of the
@@ -527,15 +529,23 @@ def handle_message(self, message):
527529
if not self.db.security.hasPermission('Email Registration', anonid):
528530
create = 0
529531

532+
# ok, now figure out who the author is - create a new user if the
533+
# "create" flag is true
530534
author = uidFromAddress(self.db, message.getaddrlist('from')[0],
531535
create=create)
536+
537+
# no author? means we're not author
532538
if not author:
533539
raise Unauthorized, '''
534540
You are not a registered user.
535541
536542
Unknown address: %s
537543
'''%message.getaddrlist('from')[0][1]
538544

545+
# make sure the author has permission to use the email interface
546+
if not self.db.security.hasPermission('Email Access', author):
547+
raise Unauthorized, 'You are not permitted to access this tracker.'
548+
539549
# the author may have been created - make sure the change is
540550
# committed before we reopen the database
541551
self.db.commit()
@@ -843,6 +853,11 @@ def parseContent(content, keep_citations, keep_body,
843853

844854
#
845855
# $Log: not supported by cvs2svn $
856+
# Revision 1.79 2002/07/26 08:26:59 richard
857+
# Very close now. The cgi and mailgw now use the new security API. The two
858+
# templates have been migrated to that setup. Lots of unit tests. Still some
859+
# issue in the web form for editing Roles assigned to users.
860+
#
846861
# Revision 1.78 2002/07/25 07:14:06 richard
847862
# Bugger it. Here's the current shape of the new security implementation.
848863
# Still to do:

roundup/templates/classic/dbinit.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: dbinit.py,v 1.21 2002-07-26 08:26:59 richard Exp $
18+
# $Id: dbinit.py,v 1.22 2002-08-01 00:56:22 richard Exp $
1919

2020
import os
2121

@@ -98,6 +98,19 @@ def open(name=None):
9898
db.security.addPermission(name="View", klass=cl,
9999
description="User is allowed to access "+cl)
100100

101+
# Assign the access and edit permissions for issue, file and message
102+
# to regular users now
103+
for cl in 'issue', 'file', 'msg':
104+
p = db.security.getPermission('View', cl)
105+
db.security.addPermissionToRole('User', p)
106+
p = db.security.getPermission('Edit', cl)
107+
db.security.addPermissionToRole('User', p)
108+
# and give the regular users access to the web and email interface
109+
p = db.security.getPermission('Web Access')
110+
db.security.addPermissionToRole('User', p)
111+
p = db.security.getPermission('Email Access')
112+
db.security.addPermissionToRole('User', p)
113+
101114
# Assign the appropriate permissions to the anonymous user's Anonymous
102115
# Role. Choices here are:
103116
# - Allow anonymous users to register through the web
@@ -117,13 +130,9 @@ def open(name=None):
117130
#p = db.security.getPermission('Edit', 'issue')
118131
#db.security.addPermissionToRole('Anonymous', p)
119132

120-
# Assign the access and edit permissions for issue, file and message
121-
# to regular users now
122-
for cl in 'issue', 'file', 'msg':
123-
p = db.security.getPermission('View', cl)
124-
db.security.addPermissionToRole('User', p)
125-
p = db.security.getPermission('Edit', cl)
126-
db.security.addPermissionToRole('User', p)
133+
# oh, g'wan, let anonymous access the web interface too
134+
p = db.security.getPermission('Web Access')
135+
db.security.addPermissionToRole('Anonymous', p)
127136

128137
import detectors
129138
detectors.init(db)
@@ -176,6 +185,11 @@ def init(adminpw):
176185

177186
#
178187
# $Log: not supported by cvs2svn $
188+
# Revision 1.21 2002/07/26 08:26:59 richard
189+
# Very close now. The cgi and mailgw now use the new security API. The two
190+
# templates have been migrated to that setup. Lots of unit tests. Still some
191+
# issue in the web form for editing Roles assigned to users.
192+
#
179193
# Revision 1.20 2002/07/17 12:39:10 gmcm
180194
# Saving, running & editing queries.
181195
#

roundup/templates/extended/dbinit.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: dbinit.py,v 1.24 2002-07-26 08:27:00 richard Exp $
18+
# $Id: dbinit.py,v 1.25 2002-08-01 00:56:22 richard Exp $
1919

2020
import os
2121

@@ -122,6 +122,19 @@ def open(name=None):
122122
db.security.addPermission(name="View", klass=cl,
123123
description="User is allowed to access "+cl)
124124

125+
# Assign the access and edit permissions for issue, file and message
126+
# to regular users now
127+
for cl in 'issue', 'support', 'file', 'msg':
128+
p = db.security.getPermission('View', cl)
129+
db.security.addPermissionToRole('User', p)
130+
p = db.security.getPermission('Edit', cl)
131+
db.security.addPermissionToRole('User', p)
132+
# and give the regular users access to the web and email interface
133+
p = db.security.getPermission('Web Access')
134+
db.security.addPermissionToRole('User', p)
135+
p = db.security.getPermission('Email Access')
136+
db.security.addPermissionToRole('User', p)
137+
125138
# Assign the appropriate permissions to the anonymous user's Anonymous
126139
# Role. Choices here are:
127140
# - Allow anonymous users to register through the web
@@ -141,13 +154,9 @@ def open(name=None):
141154
#p = db.security.getPermission('Edit', 'issue')
142155
#db.security.addPermissionToRole('Anonymous', p)
143156

144-
# Assign the access and edit permissions for issue, file and message
145-
# to regular users now
146-
for cl in 'issue', 'support', 'file', 'msg':
147-
p = db.security.getPermission('View', cl)
148-
db.security.addPermissionToRole('User', p)
149-
p = db.security.getPermission('Edit', cl)
150-
db.security.addPermissionToRole('User', p)
157+
# oh, g'wan, let anonymous access the web interface too
158+
p = db.security.getPermission('Web Access')
159+
db.security.addPermissionToRole('Anonymous', p)
151160

152161
import detectors
153162
detectors.init(db)
@@ -217,6 +226,11 @@ def init(adminpw):
217226

218227
#
219228
# $Log: not supported by cvs2svn $
229+
# Revision 1.24 2002/07/26 08:27:00 richard
230+
# Very close now. The cgi and mailgw now use the new security API. The two
231+
# templates have been migrated to that setup. Lots of unit tests. Still some
232+
# issue in the web form for editing Roles assigned to users.
233+
#
220234
# Revision 1.23 2002/07/14 02:05:54 richard
221235
# . all storage-specific code (ie. backend) is now implemented by the backends
222236
#

0 commit comments

Comments
 (0)