Skip to content

Commit e061dee

Browse files
author
Richard Jones
committed
Added 'Users may only edit their issues' customisation example.
Fixed permission check in page.html template.
1 parent 85b431c commit e061dee

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

doc/customizing.txt

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

5-
:Version: $Revision: 1.106 $
5+
:Version: $Revision: 1.107 $
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
@@ -3584,6 +3584,76 @@ Resolving the issue::
35843584

35853585
... and so on
35863586

3587+
Users may only edit their issues
3588+
--------------------------------
3589+
3590+
Users registering themselves are granted Provisional access - meaning they
3591+
have access to edit the issues they submit, but not others. We create a new
3592+
Role called "Provisional User" which is granted to newly-registered users,
3593+
and has limited access. One of the Permissions they have is the new "Edit
3594+
Own" on issues (regular users have "Edit".) We back up the permissions with
3595+
an auditor.
3596+
3597+
First up, we create the new Role and Permission structure in
3598+
``dbinit.py``::
3599+
3600+
# New users not approved by the admin
3601+
db.security.addRole(name='Provisional User',
3602+
description='New user registered via web or email')
3603+
p = db.security.addPermission(name='Edit Own', klass='issue',
3604+
description='Can only edit own issues')
3605+
db.security.addPermissionToRole('Provisional User', p)
3606+
3607+
# Assign the access and edit Permissions for issue to new users now
3608+
p = db.security.getPermission('View', 'issue')
3609+
db.security.addPermissionToRole('Provisional User', p)
3610+
p = db.security.getPermission('Edit', 'issue')
3611+
db.security.addPermissionToRole('Provisional User', p)
3612+
3613+
# and give the new users access to the web and email interface
3614+
p = db.security.getPermission('Web Access')
3615+
db.security.addPermissionToRole('Provisional User', p)
3616+
p = db.security.getPermission('Email Access')
3617+
db.security.addPermissionToRole('Provisional User', p)
3618+
3619+
3620+
Then in the ``config.py`` we change the Role assigned to newly-registered
3621+
users, replacing the existing ``'User'`` values::
3622+
3623+
NEW_WEB_USER_ROLES = 'Provisional User'
3624+
NEW_EMAIL_USER_ROLES = 'Provisional User'
3625+
3626+
Finally we add a new *auditor* to the ``detectors`` directory called
3627+
``provisional_user_auditor.py``::
3628+
3629+
def audit_provisionaluser(db, cl, nodeid, newvalues):
3630+
''' New users are only allowed to modify their own issues.
3631+
'''
3632+
if (db.getuid() != cl.get(nodeid, 'creator')
3633+
and db.security.hasPermission('Edit Own', db.getuid(), cl.classname)):
3634+
raise ValueError, ('You are only allowed to edit your own %s'
3635+
% cl.classname)
3636+
3637+
def init(db):
3638+
# fire before changes are made
3639+
db.issue.audit('set', audit_provisionaluser)
3640+
db.issue.audit('retire', audit_provisionaluser)
3641+
db.issue.audit('restore', audit_provisionaluser)
3642+
3643+
Note that some older trackers might also want to change the ``page.html``
3644+
template as follows::
3645+
3646+
<p class="classblock"
3647+
- tal:condition="python:request.user.username != 'anonymous'">
3648+
+ tal:condition="python:request.user.hasPermission('View', 'user')">
3649+
<b>Administration</b><br>
3650+
<tal:block tal:condition="python:request.user.hasPermission('Edit', None)">
3651+
<a href="home?:template=classlist">Class List</a><br>
3652+
3653+
(note that the "-" indicates a removed line, and the "+" indicates an added
3654+
line).
3655+
3656+
35873657
-------------------
35883658

35893659
Back to `Table of Contents`_

templates/classic/html/page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
</p>
5858

5959
<p class="classblock"
60-
tal:condition="python:request.user.username != 'anonymous'">
60+
tal:condition="python:request.user.hasPermission('View', 'user')">
6161
<b>Administration</b><br>
6262
<tal:block tal:condition="python:request.user.hasPermission('Edit', None)">
6363
<a href="home?@template=classlist">Class List</a><br>

0 commit comments

Comments
 (0)