comparison doc/customizing.txt @ 2991:b9a55628a78d

more doc fixes simplified the security API, and bumped those changes around a couple more TODO items so I don't forget
author Richard Jones <richard@users.sourceforge.net>
date Tue, 07 Dec 2004 23:32:50 +0000
parents 9614a101b68f
children 8fa6b5747a53 714f2a60a97e
comparison
equal deleted inserted replaced
2988:f4023f1cc1d6 2991:b9a55628a78d
1 =================== 1 ===================
2 Customising Roundup 2 Customising Roundup
3 =================== 3 ===================
4 4
5 :Version: $Revision: 1.160 $ 5 :Version: $Revision: 1.161 $
6 6
7 .. This document borrows from the ZopeBook section on ZPT. The original is at: 7 .. This document borrows from the ZopeBook section on ZPT. The original is at:
8 http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx 8 http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
9 9
10 .. contents:: 10 .. contents::
1131 to define new actions, you may add them there (see `defining new 1131 to define new actions, you may add them there (see `defining new
1132 web actions`_). 1132 web actions`_).
1133 1133
1134 Each action class also has a ``*permission*`` method which determines whether 1134 Each action class also has a ``*permission*`` method which determines whether
1135 the action is permissible given the current user. The base permission checks 1135 the action is permissible given the current user. The base permission checks
1136 are: 1136 for each action are:
1137
1138 XXX REVIEW for Permissions changes
1139 1137
1140 **login** 1138 **login**
1141 Determine whether the user has permission to log in. Base behaviour is 1139 Determine whether the user has the "Web Access" Permission.
1142 to check the user has "Web Access".
1143 **logout** 1140 **logout**
1144 No permission checks are made. 1141 No permission checks are made.
1145 **register** 1142 **register**
1146 Determine whether the user has permission to register. Base behaviour 1143 Determine whether the user has the "Web Registration" Permission.
1147 is to check the user has the "Web Registration" Permission.
1148 **edit** 1144 **edit**
1149 Determine whether the user has permission to edit this item. If we're 1145 Determine whether the user has permission to edit this item. If we're
1150 editing the "user" class, users are allowed to edit their own details - 1146 editing the "user" class, users are allowed to edit their own details -
1151 unless they try to edit the "roles" property, which requires the 1147 unless they try to edit the "roles" property, which requires the
1152 special Permission "Web Roles". 1148 special Permission "Web Roles".
1153 **new** 1149 **new**
1154 Determine whether the user has permission to create this item. No 1150 Determine whether the user has permission to create this item. No
1155 additional property checks are made. Additionally, new user items may 1151 additional property checks are made. Additionally, new user items may
1156 be created if the user has the "Web Registration" Permission. 1152 be created if the user has the "Web Registration" Permission.
1157 **editCSV** 1153 **editCSV**
1158 Determine whether the user has permission to edit this class. Base 1154 Determine whether the user has permission to edit this class.
1159 behaviour is to check whether the user may edit this class.
1160 **search** 1155 **search**
1161 Determine whether the user has permission to search this class. Base 1156 Determine whether the user has permission to view this class.
1162 behaviour is to check whether the user may view this class.
1163 1157
1164 1158
1165 Special form variables 1159 Special form variables
1166 ---------------------- 1160 ----------------------
1167 1161
1762 implemented**) 1756 implemented**)
1763 history render the journal of the current item as HTML 1757 history render the journal of the current item as HTML
1764 renderQueryForm specific to the "query" class - render the search form 1758 renderQueryForm specific to the "query" class - render the search form
1765 for the query 1759 for the query
1766 hasPermission specific to the "user" class - determine whether the 1760 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.
1768 is_edit_ok is the user allowed to Edit the current item? 1767 is_edit_ok is the user allowed to Edit the current item?
1769 is_view_ok is the user allowed to View the current item? 1768 is_view_ok is the user allowed to View the current item?
1770 is_retired is the item retired? 1769 is_retired is the item retired?
1771 download_url generates a url-quoted link for download of FileClass 1770 download_url generates a url-quoted link for download of FileClass
1772 item contents (ie. file<id>/<name>) 1771 item contents (ie. file<id>/<name>)
2672 2671
2673 # Assign the access and edit permissions for issue, file and message 2672 # Assign the access and edit permissions for issue, file and message
2674 # to regular users now 2673 # to regular users now
2675 for cl in 'issue', 'file', 'msg', 'category': 2674 for cl in 'issue', 'file', 'msg', 'category':
2676 p = db.security.getPermission('View', cl) 2675 p = db.security.getPermission('View', cl)
2677 db.security.addPermissionToRole('User', p) 2676 db.security.addPermissionToRole('User', 'View', cl)
2678 p = db.security.getPermission('Edit', cl) 2677 db.security.addPermissionToRole('User', 'Edit', cl)
2679 db.security.addPermissionToRole('User', p) 2678 db.security.addPermissionToRole('User', 'Create', cl)
2680 2679
2681 These lines assign the View and Edit Permissions to the "User" role, so 2680 These lines assign the View and Edit Permissions to the "User" role, so
2682 that normal users can view and edit "category" objects. 2681 that normal users can view and edit "category" objects.
2683 2682
2684 This is all the work that needs to be done for the database. It will 2683 This is all the work that needs to be done for the database. It will
3113 3112
3114 Optionally, you might want to restrict the users able to access this new 3113 Optionally, you might want to restrict the users able to access this new
3115 class to just the users with a new "SysAdmin" Role. To do this, we add 3114 class to just the users with a new "SysAdmin" Role. To do this, we add
3116 some security declarations:: 3115 some security declarations::
3117 3116
3118 p = db.security.getPermission('View', 'support') 3117 db.security.addPermissionToRole('SysAdmin', 'View', 'support')
3119 db.security.addPermissionToRole('SysAdmin', p) 3118 db.security.addPermissionToRole('SysAdmin', 'Create', 'support')
3120 p = db.security.getPermission('Edit', 'support') 3119 db.security.addPermissionToRole('SysAdmin', 'Edit', 'support')
3121 db.security.addPermissionToRole('SysAdmin', p)
3122 3120
3123 You would then (as an "admin" user) edit the details of the appropriate 3121 You would then (as an "admin" user) edit the details of the appropriate
3124 users, and add "SysAdmin" to their Roles list. 3122 users, and add "SysAdmin" to their Roles list.
3125 3123
3126 Alternatively, you might want to change the Edit/View permissions granted 3124 Alternatively, you might want to change the Edit/View permissions granted
3906 ``schema.py``:: 3904 ``schema.py``::
3907 3905
3908 # New users not approved by the admin 3906 # New users not approved by the admin
3909 db.security.addRole(name='Provisional User', 3907 db.security.addRole(name='Provisional User',
3910 description='New user registered via web or email') 3908 description='New user registered via web or email')
3911 p = db.security.addPermission(name='Edit Own', klass='issue', 3909
3912 description='Can only edit own issues') 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')
3913 db.security.addPermissionToRole('Provisional User', p) 3918 db.security.addPermissionToRole('Provisional User', p)
3914 3919 p = db.security.addPermission(name='View Own Issues', klass='issue',
3915 # Assign the access and edit Permissions for issue to new users now 3920 code=own_issue, description='Can only view own issues')
3916 p = db.security.getPermission('View', 'issue')
3917 db.security.addPermissionToRole('Provisional User', p) 3921 db.security.addPermissionToRole('Provisional User', p)
3918 p = db.security.getPermission('Edit', 'issue') 3922
3919 db.security.addPermissionToRole('Provisional User', p) 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)
3920 3930
3921 # and give the new users access to the web and email interface 3931 # and give the new users access to the web and email interface
3922 p = db.security.getPermission('Web Access') 3932 db.security.addPermissionToRole('Provisional User', 'Web Access')
3923 db.security.addPermissionToRole('Provisional User', p) 3933 db.security.addPermissionToRole('Provisional User', 'Email Access')
3924 p = db.security.getPermission('Email Access')
3925 db.security.addPermissionToRole('Provisional User', p)
3926 3934
3927 3935
3928 Then in the ``config.ini`` we change the Role assigned to newly-registered 3936 Then in the ``config.ini`` we change the Role assigned to newly-registered
3929 users, replacing the existing ``'User'`` values:: 3937 users, replacing the existing ``'User'`` values::
3930 3938
3931 [main] 3939 [main]
3932 ... 3940 ...
3933 new_web_user_roles = 'Provisional User' 3941 new_web_user_roles = 'Provisional User'
3934 new_email_user_roles = 'Provisional User' 3942 new_email_user_roles = 'Provisional User'
3935
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 3943
3953 Note that some older trackers might also want to change the ``page.html`` 3944 Note that some older trackers might also want to change the ``page.html``
3954 template as follows:: 3945 template as follows::
3955 3946
3956 <p class="classblock" 3947 <p class="classblock"
4198 4189
4199 4. Use the usual "new" action as the ``@action`` on the final page, and 4190 4. Use the usual "new" action as the ``@action`` on the final page, and
4200 you're done (the standard context/submit method can do this for you). 4191 you're done (the standard context/submit method can do this for you).
4201 4192
4202 4193
4203
4204 ------------------- 4194 -------------------
4205 4195
4206 Back to `Table of Contents`_ 4196 Back to `Table of Contents`_
4207 4197
4208 .. _`Table of Contents`: index.html 4198 .. _`Table of Contents`: index.html

Roundup Issue Tracker: http://roundup-tracker.org/