22Customising 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
11341134Each action class also has a ``*permission*`` method which determines whether
11351135the 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
11651159Special form variables
@@ -1764,7 +1758,12 @@ history render the journal of the current item as HTML
17641758renderQueryForm specific to the "query" class - render the search form
17651759 for the query
17661760hasPermission 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.
17681767is_edit_ok is the user allowed to Edit the current item?
17691768is_view_ok is the user allowed to View the current item?
17701769is_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
26812680These lines assign the View and Edit Permissions to the "User" role, so
26822681that 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
31153114class to just the users with a new "SysAdmin" Role. To do this, we add
31163115some 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
31233121You would then (as an "admin" user) edit the details of the appropriate
31243122users, 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
39283936Then 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-
39533944Note that some older trackers might also want to change the ``page.html``
39543945template 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
42064196Back to `Table of Contents`_
0 commit comments