1 | # $Id: permissions.py 14949 2018-02-09 09:17:58Z henrik $ |
---|
2 | # |
---|
3 | # Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | # This program is free software; you can redistribute it and/or modify |
---|
5 | # it under the terms of the GNU General Public License as published by |
---|
6 | # the Free Software Foundation; either version 2 of the License, or |
---|
7 | # (at your option) any later version. |
---|
8 | # |
---|
9 | # This program is distributed in the hope that it will be useful, |
---|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | # GNU General Public License for more details. |
---|
13 | # |
---|
14 | # You should have received a copy of the GNU General Public License |
---|
15 | # along with this program; if not, write to the Free Software |
---|
16 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | # |
---|
18 | import grok |
---|
19 | from zope.component import getUtilitiesFor |
---|
20 | from zope.interface import Interface |
---|
21 | from zope.securitypolicy.interfaces import IRole, IPrincipalRoleMap |
---|
22 | from waeup.kofa.interfaces import ILocalRolesAssignable |
---|
23 | |
---|
24 | |
---|
25 | class Public(grok.Permission): |
---|
26 | """The Public or everyone-can-do-this-permission is being applied |
---|
27 | to views/pages that are used by everyone. |
---|
28 | """ |
---|
29 | grok.name('waeup.Public') |
---|
30 | |
---|
31 | |
---|
32 | class Anonymous(grok.Permission): |
---|
33 | """The Anonymous permission is applied to |
---|
34 | views/pages which are dedicated to anonymous users only. |
---|
35 | Logged-in users can't access these views. |
---|
36 | """ |
---|
37 | grok.name('waeup.Anonymous') |
---|
38 | |
---|
39 | |
---|
40 | class Authenticated(grok.Permission): |
---|
41 | """The Authenticated permission is applied to pages |
---|
42 | which can only be used by logged-in users and not by anonymous users. |
---|
43 | """ |
---|
44 | grok.name('waeup.Authenticated') |
---|
45 | |
---|
46 | |
---|
47 | class ViewAcademics(grok.Permission): |
---|
48 | """The ViewAcademics permission is applied to all |
---|
49 | views of the Academic Section. Users with this permission can view but |
---|
50 | not edit content in the Academic Section. |
---|
51 | """ |
---|
52 | grok.name('waeup.viewAcademics') |
---|
53 | |
---|
54 | |
---|
55 | class ManageAcademics(grok.Permission): |
---|
56 | """The ManageAcademics permission is applied to all edit/manage |
---|
57 | pages in the Academic Section. Users who have this permission |
---|
58 | can change/edit context objects. |
---|
59 | """ |
---|
60 | grok.name('waeup.manageAcademics') |
---|
61 | |
---|
62 | |
---|
63 | class ManagePortal(grok.Permission): |
---|
64 | """The ManagePortal permission is used for very few pages |
---|
65 | (e.g. the DatacenterSettings page). Only PortalManagers have this |
---|
66 | permission. It is furthermore used to control delete methods of container |
---|
67 | pages in the Academic Section. The ManageAcademics permission, |
---|
68 | described above, does enable users to edit content but not to |
---|
69 | remove sub-containers, like faculties, departments or certificates. |
---|
70 | Users must have the ManagePortal permission too to remove |
---|
71 | entire containers. |
---|
72 | """ |
---|
73 | grok.name('waeup.managePortal') |
---|
74 | |
---|
75 | |
---|
76 | class ManageUsers(grok.Permission): |
---|
77 | """The ManageUsers permission is a real superuser permission |
---|
78 | and therefore very 'dangerous'. It allows to add, remove or edit |
---|
79 | user accounts. Editing a user account includes the option to assign |
---|
80 | or remove roles. That means that a user with this permission can lock out |
---|
81 | other users by either removing their account or by removing |
---|
82 | permissions. |
---|
83 | """ |
---|
84 | grok.name('waeup.manageUsers') |
---|
85 | |
---|
86 | |
---|
87 | class ShowStudents(grok.Permission): |
---|
88 | """Users with this permission do not neccessarily see the 'Students' tab |
---|
89 | but they can search for students at department, certificate or course |
---|
90 | level. If they additionally have the ExportData permission they can |
---|
91 | export the data as csv files. |
---|
92 | |
---|
93 | Bursary or Department Officers don't have the ExportData |
---|
94 | permission (see Roles section) and are only allowed to export bursary |
---|
95 | or payments overview data respectively. |
---|
96 | """ |
---|
97 | grok.name('waeup.showStudents') |
---|
98 | |
---|
99 | |
---|
100 | class ClearAllStudents(grok.Permission): |
---|
101 | """The ClearAllStudents permission allows to clear all students |
---|
102 | in a department at one sweep. |
---|
103 | """ |
---|
104 | grok.name('waeup.clearAllStudents') |
---|
105 | |
---|
106 | |
---|
107 | class EditScores(grok.Permission): |
---|
108 | """The EditScores permission allows to edit scores in course tickets. |
---|
109 | """ |
---|
110 | grok.name('waeup.editScores') |
---|
111 | |
---|
112 | |
---|
113 | class TriggerTransition(grok.Permission): |
---|
114 | """The TriggerTransition permission allows to trigger workflow transitions |
---|
115 | of student and document objects. |
---|
116 | """ |
---|
117 | grok.name('waeup.triggerTransition') |
---|
118 | |
---|
119 | |
---|
120 | class EditUser(grok.Permission): |
---|
121 | """The EditUser permission is required for editing |
---|
122 | single user accounts. |
---|
123 | """ |
---|
124 | grok.name('waeup.editUser') |
---|
125 | |
---|
126 | |
---|
127 | class ManageDataCenter(grok.Permission): |
---|
128 | """The ManageDataCenter permission allows to access all pages |
---|
129 | in the Data Center and to upload files. It does not automatically |
---|
130 | allow to process uploaded data files. |
---|
131 | """ |
---|
132 | grok.name('waeup.manageDataCenter') |
---|
133 | |
---|
134 | |
---|
135 | class ImportData(grok.Permission): |
---|
136 | """The ImportData permission allows to batch process (import) any kind of |
---|
137 | portal data except for user data. The User Data processor |
---|
138 | requires also the ManageUsers permission. |
---|
139 | """ |
---|
140 | grok.name('waeup.importData') |
---|
141 | |
---|
142 | |
---|
143 | class ExportData(grok.Permission): |
---|
144 | """The ExportData permission allows to export any kind of portal data. |
---|
145 | """ |
---|
146 | grok.name('waeup.exportData') |
---|
147 | |
---|
148 | |
---|
149 | class ExportPaymentsOverview(grok.Permission): |
---|
150 | grok.name('waeup.exportPaymentsOverview') |
---|
151 | |
---|
152 | |
---|
153 | class ExportBursaryData(grok.Permission): |
---|
154 | grok.name('waeup.exportBursaryData') |
---|
155 | |
---|
156 | |
---|
157 | class ViewTranscript(grok.Permission): |
---|
158 | grok.name('waeup.viewTranscript') |
---|
159 | |
---|
160 | |
---|
161 | class ManagePortalConfiguration(grok.Permission): |
---|
162 | """The ManagePortalConfiguration permission allows to |
---|
163 | edit global and sessional portal configuration data. |
---|
164 | """ |
---|
165 | grok.name('waeup.managePortalConfiguration') |
---|
166 | |
---|
167 | |
---|
168 | class ManageACBatches(grok.Permission): |
---|
169 | """The ManageACBatches permission allows to view and |
---|
170 | manage accesscodes. |
---|
171 | """ |
---|
172 | grok.name('waeup.manageACBatches') |
---|
173 | |
---|
174 | |
---|
175 | class PutBiometricDataPermission(grok.Permission): |
---|
176 | """This permission allows to upload/change biometric data. |
---|
177 | """ |
---|
178 | grok.name('waeup.putBiometricData') |
---|
179 | |
---|
180 | |
---|
181 | class GetBiometricDataPermission(grok.Permission): |
---|
182 | """This permission allows to read biometric data. |
---|
183 | """ |
---|
184 | grok.name('waeup.getBiometricData') |
---|
185 | |
---|
186 | |
---|
187 | # Local Roles |
---|
188 | |
---|
189 | class ApplicationsManager(grok.Role): |
---|
190 | """The local ApplicationsManager role can be assigned at applicants |
---|
191 | container and at department level. At department level an Applications |
---|
192 | Manager can manage all applicants which desire to study a programme |
---|
193 | offered by the department (1st Choice Course of Study). |
---|
194 | |
---|
195 | At container level (local) Applications Managers gain permissions which |
---|
196 | allow to manage the container and all applicants inside the container. At |
---|
197 | container level the permission set of this local role corresonds with the |
---|
198 | permission set of the same-named global role. |
---|
199 | """ |
---|
200 | grok.name('waeup.local.ApplicationsManager') |
---|
201 | grok.title(u'Applications Manager') |
---|
202 | grok.permissions('waeup.viewAcademics', |
---|
203 | 'waeup.manageApplication', 'waeup.viewApplication', |
---|
204 | 'waeup.payApplicant') |
---|
205 | |
---|
206 | |
---|
207 | class DepartmentManager(grok.Role): |
---|
208 | """The local DepartmentManager role can be assigned at faculty or |
---|
209 | department level. The role allows to edit all data within this container. |
---|
210 | It does not automatically allow to remove sub-containers. |
---|
211 | |
---|
212 | Department Managers (Dean of Faculty or Head of Department respectively) |
---|
213 | can also list student data but not access student pages. |
---|
214 | """ |
---|
215 | grok.name('waeup.local.DepartmentManager') |
---|
216 | grok.title(u'Department Manager') |
---|
217 | grok.permissions('waeup.manageAcademics', |
---|
218 | 'waeup.showStudents', |
---|
219 | 'waeup.exportData') |
---|
220 | |
---|
221 | |
---|
222 | class DepartmentOfficer(grok.Role): |
---|
223 | """The local DepartmentOfficer role can be assigned at faculty or |
---|
224 | department level. The role allows to list all student data within the |
---|
225 | faculty/department the local role is assigned. |
---|
226 | |
---|
227 | Department Managers (Dean of Faculty or Head of Department respectively) |
---|
228 | can also list student data but not access student pages. They can |
---|
229 | furthermore export payment overviews. |
---|
230 | """ |
---|
231 | grok.name('waeup.local.DepartmentOfficer') |
---|
232 | grok.title(u'Department Officer') |
---|
233 | grok.permissions('waeup.showStudents', |
---|
234 | 'waeup.viewAcademics', |
---|
235 | 'waeup.exportPaymentsOverview') |
---|
236 | |
---|
237 | |
---|
238 | class ClearanceOfficer(grok.Role): |
---|
239 | """The local ClearanceOfficer role can be assigned at faculty or |
---|
240 | department level. The role allows to list or export all student |
---|
241 | data within the faculty/department the local role is assigned. |
---|
242 | |
---|
243 | Clearance Officers can furthermore clear all students or reject clearance |
---|
244 | of all students in their faculty/department. They get the |
---|
245 | StudentsClearanceOfficer role for this subset of students. |
---|
246 | """ |
---|
247 | grok.name('waeup.local.ClearanceOfficer') |
---|
248 | grok.title(u'Clearance Officer') |
---|
249 | grok.permissions('waeup.showStudents', |
---|
250 | 'waeup.viewAcademics', |
---|
251 | 'waeup.exportData', |
---|
252 | 'waeup.clearAllStudents') |
---|
253 | |
---|
254 | |
---|
255 | class LocalStudentsManager(grok.Role): |
---|
256 | """The local LocalStudentsManager role can be assigned at faculty or |
---|
257 | department level. The role allows to view all data and to view or export |
---|
258 | all student data within the faculty/department the local role is assigned. |
---|
259 | |
---|
260 | Local Students Managers can furthermore manage data of students |
---|
261 | in their faculty/department. They get the StudentsManager role for |
---|
262 | this subset of students. |
---|
263 | """ |
---|
264 | grok.name('waeup.local.LocalStudentsManager') |
---|
265 | grok.title(u'Students Manager') |
---|
266 | grok.permissions('waeup.showStudents', |
---|
267 | 'waeup.viewAcademics', |
---|
268 | 'waeup.exportData') |
---|
269 | |
---|
270 | |
---|
271 | class LocalWorkflowManager(grok.Role): |
---|
272 | """The local LocalWorkflowManager role can be assigned at faculty level. |
---|
273 | The role allows to view all data and to list or export |
---|
274 | all student data within the faculty the local role is assigned. |
---|
275 | |
---|
276 | Local Workflow Managers can trigger transition of students in their |
---|
277 | faculty/department. They get the WorkflowManager role for |
---|
278 | this subset of students. |
---|
279 | """ |
---|
280 | grok.name('waeup.local.LocalWorkflowManager') |
---|
281 | grok.title(u'Student Workflow Manager') |
---|
282 | grok.permissions('waeup.showStudents', |
---|
283 | 'waeup.viewAcademics', |
---|
284 | 'waeup.exportData') |
---|
285 | |
---|
286 | |
---|
287 | class UGClearanceOfficer(grok.Role): |
---|
288 | """UG Clearance Officers are regular Clearance Officers with restricted |
---|
289 | dynamic permission assignment. They can only access undergraduate |
---|
290 | students. |
---|
291 | """ |
---|
292 | grok.name('waeup.local.UGClearanceOfficer') |
---|
293 | grok.title(u'UG Clearance Officer') |
---|
294 | grok.permissions('waeup.showStudents', |
---|
295 | 'waeup.viewAcademics', |
---|
296 | 'waeup.exportData', |
---|
297 | 'waeup.clearAllStudents') |
---|
298 | |
---|
299 | |
---|
300 | class PGClearanceOfficer(grok.Role): |
---|
301 | """PG Clearance Officers are regular Clearance Officers with restricted |
---|
302 | dynamic permission assignment. They can only access postgraduate |
---|
303 | students. |
---|
304 | """ |
---|
305 | grok.name('waeup.local.PGClearanceOfficer') |
---|
306 | grok.title(u'PG Clearance Officer') |
---|
307 | grok.permissions('waeup.showStudents', |
---|
308 | 'waeup.viewAcademics', |
---|
309 | 'waeup.exportData', |
---|
310 | 'waeup.clearAllStudents') |
---|
311 | |
---|
312 | |
---|
313 | class CourseAdviser100(grok.Role): |
---|
314 | """The local CourseAdviser100 role can be assigned at faculty, |
---|
315 | department or certificate level. The role allows to view all data and |
---|
316 | to list or export all student data within the faculty, department |
---|
317 | or certificate the local role is assigned. |
---|
318 | |
---|
319 | Local Course Advisers can validate or reject course lists of students |
---|
320 | in ther faculty/department/certificate at level 100. |
---|
321 | They get the StudentsCourseAdviser role for this subset of students. |
---|
322 | """ |
---|
323 | grok.name('waeup.local.CourseAdviser100') |
---|
324 | grok.title(u'Course Adviser 100L') |
---|
325 | grok.permissions('waeup.showStudents', |
---|
326 | 'waeup.viewAcademics', |
---|
327 | 'waeup.exportData') |
---|
328 | |
---|
329 | |
---|
330 | class CourseAdviser200(grok.Role): |
---|
331 | """Same as CourseAdviser100 but for level 200. |
---|
332 | """ |
---|
333 | grok.name('waeup.local.CourseAdviser200') |
---|
334 | grok.title(u'Course Adviser 200L') |
---|
335 | grok.permissions('waeup.showStudents', |
---|
336 | 'waeup.viewAcademics', |
---|
337 | 'waeup.exportData') |
---|
338 | |
---|
339 | |
---|
340 | class CourseAdviser300(grok.Role): |
---|
341 | """Same as CourseAdviser100 but for level 300. |
---|
342 | """ |
---|
343 | grok.name('waeup.local.CourseAdviser300') |
---|
344 | grok.title(u'Course Adviser 300L') |
---|
345 | grok.permissions('waeup.showStudents', |
---|
346 | 'waeup.viewAcademics', |
---|
347 | 'waeup.exportData') |
---|
348 | |
---|
349 | |
---|
350 | class CourseAdviser400(grok.Role): |
---|
351 | """Same as CourseAdviser100 but for level 400. |
---|
352 | """ |
---|
353 | grok.name('waeup.local.CourseAdviser400') |
---|
354 | grok.title(u'Course Adviser 400L') |
---|
355 | grok.permissions('waeup.showStudents', |
---|
356 | 'waeup.viewAcademics', |
---|
357 | 'waeup.exportData') |
---|
358 | |
---|
359 | |
---|
360 | class CourseAdviser500(grok.Role): |
---|
361 | """Same as CourseAdviser100 but for level 500. |
---|
362 | """ |
---|
363 | grok.name('waeup.local.CourseAdviser500') |
---|
364 | grok.title(u'Course Adviser 500L') |
---|
365 | grok.permissions('waeup.showStudents', |
---|
366 | 'waeup.viewAcademics', |
---|
367 | 'waeup.exportData') |
---|
368 | |
---|
369 | |
---|
370 | class CourseAdviser600(grok.Role): |
---|
371 | """Same as CourseAdviser100 but for level 600. |
---|
372 | """ |
---|
373 | grok.name('waeup.local.CourseAdviser600') |
---|
374 | grok.title(u'Course Adviser 600L') |
---|
375 | grok.permissions('waeup.showStudents', |
---|
376 | 'waeup.viewAcademics', |
---|
377 | 'waeup.exportData') |
---|
378 | |
---|
379 | |
---|
380 | class CourseAdviser700(grok.Role): |
---|
381 | """Same as CourseAdviser100 but for level 700. |
---|
382 | """ |
---|
383 | grok.name('waeup.local.CourseAdviser700') |
---|
384 | grok.title(u'Course Adviser 700L') |
---|
385 | grok.permissions('waeup.showStudents', |
---|
386 | 'waeup.viewAcademics', |
---|
387 | 'waeup.exportData') |
---|
388 | |
---|
389 | |
---|
390 | class CourseAdviser800(grok.Role): |
---|
391 | """Same as CourseAdviser100 but for level 800. |
---|
392 | """ |
---|
393 | grok.name('waeup.local.CourseAdviser800') |
---|
394 | grok.title(u'Course Adviser 800L') |
---|
395 | grok.permissions('waeup.showStudents', |
---|
396 | 'waeup.viewAcademics', |
---|
397 | 'waeup.exportData') |
---|
398 | |
---|
399 | |
---|
400 | class Lecturer(grok.Role): |
---|
401 | """The local Lecturer role can be assigned at course level. |
---|
402 | The role allows to export some student |
---|
403 | data within the course the local role is assigned. Lecturers can't access |
---|
404 | student data directly but they can edit the scores in course tickets. |
---|
405 | """ |
---|
406 | grok.name('waeup.local.Lecturer') |
---|
407 | grok.title(u'Lecturer') |
---|
408 | grok.permissions('waeup.editScores', |
---|
409 | 'waeup.viewAcademics', |
---|
410 | 'waeup.exportData') |
---|
411 | |
---|
412 | |
---|
413 | class Owner(grok.Role): |
---|
414 | """Each user 'owns' her/his user object and gains permission to edit |
---|
415 | some of the user attributes. |
---|
416 | """ |
---|
417 | grok.name('waeup.local.Owner') |
---|
418 | grok.title(u'Owner') |
---|
419 | grok.permissions('waeup.editUser') |
---|
420 | |
---|
421 | |
---|
422 | # Site Roles |
---|
423 | class AcademicsOfficer(grok.Role): |
---|
424 | """An Academics Officer can view but not edit data in the |
---|
425 | academic section. |
---|
426 | |
---|
427 | This is the default role which is automatically assigned to all |
---|
428 | officers of the portal. A user with this role can access all display pages |
---|
429 | at faculty, department, course, certificate and certificate course level. |
---|
430 | """ |
---|
431 | grok.name('waeup.AcademicsOfficer') |
---|
432 | grok.title(u'Academics Officer (view only)') |
---|
433 | grok.permissions('waeup.viewAcademics') |
---|
434 | |
---|
435 | |
---|
436 | class AcademicsManager(grok.Role): |
---|
437 | """An Academics Manager can view and edit all data in the |
---|
438 | scademic section, i.e. access all manage pages |
---|
439 | at faculty, department, course, certificate and certificate course level. |
---|
440 | """ |
---|
441 | grok.name('waeup.AcademicsManager') |
---|
442 | grok.title(u'Academics Manager') |
---|
443 | title = u'Academics Manager' |
---|
444 | grok.permissions('waeup.viewAcademics', |
---|
445 | 'waeup.manageAcademics') |
---|
446 | |
---|
447 | |
---|
448 | class ACManager(grok.Role): |
---|
449 | """This is the role for Access Code Managers. |
---|
450 | An AC Manager can view and manage the Accesscodes Section, see |
---|
451 | ManageACBatches permission above. |
---|
452 | """ |
---|
453 | grok.name('waeup.ACManager') |
---|
454 | grok.title(u'Access Code Manager') |
---|
455 | grok.permissions('waeup.manageACBatches') |
---|
456 | |
---|
457 | |
---|
458 | class DataCenterManager(grok.Role): |
---|
459 | """This single-permission role is dedicated to those users |
---|
460 | who are charged with batch processing of portal data. |
---|
461 | A Data Center Manager can access all pages in the Data Center, |
---|
462 | see ManageDataCenter permission above. |
---|
463 | """ |
---|
464 | grok.name('waeup.DataCenterManager') |
---|
465 | grok.title(u'Datacenter Manager') |
---|
466 | grok.permissions('waeup.manageDataCenter') |
---|
467 | |
---|
468 | |
---|
469 | class ImportManager(grok.Role): |
---|
470 | """An Import Manager is a Data Center Manager who is also allowed |
---|
471 | to batch process (import) data. All batch processors (importers) are |
---|
472 | available except for the User Processor. This processor requires the |
---|
473 | Users Manager role too. The ImportManager role includes the |
---|
474 | DataCenterManager role but not vice versa. |
---|
475 | """ |
---|
476 | grok.name('waeup.ImportManager') |
---|
477 | grok.title(u'Import Manager') |
---|
478 | grok.permissions('waeup.manageDataCenter', |
---|
479 | 'waeup.importData') |
---|
480 | |
---|
481 | |
---|
482 | class ExportManager(grok.Role): |
---|
483 | """An Export Manager is a Data Center Manager who is also allowed |
---|
484 | to export all kind of portal data. The ExportManager role includes the |
---|
485 | DataCenterManager role but not vice versa. |
---|
486 | """ |
---|
487 | grok.name('waeup.ExportManager') |
---|
488 | grok.title(u'Export Manager') |
---|
489 | grok.permissions('waeup.manageDataCenter', |
---|
490 | 'waeup.exportData', |
---|
491 | 'waeup.showStudents') |
---|
492 | |
---|
493 | |
---|
494 | class BursaryOfficer(grok.Role): |
---|
495 | """Bursary Officers can export bursary data. They can't access the |
---|
496 | Data Center but see student data export buttons in the Academic Section. |
---|
497 | """ |
---|
498 | grok.name('waeup.BursaryOfficer') |
---|
499 | grok.title(u'Bursary Officer') |
---|
500 | grok.permissions('waeup.showStudents', |
---|
501 | 'waeup.viewAcademics', |
---|
502 | 'waeup.exportBursaryData') |
---|
503 | |
---|
504 | |
---|
505 | class UsersManager(grok.Role): |
---|
506 | """A Users Manager can add, remove or edit |
---|
507 | user accounts, see ManageUsers permission for further information. |
---|
508 | Be very careful with this role. |
---|
509 | """ |
---|
510 | grok.name('waeup.UsersManager') |
---|
511 | grok.title(u'Users Manager') |
---|
512 | grok.permissions('waeup.manageUsers', |
---|
513 | 'waeup.editUser') |
---|
514 | |
---|
515 | |
---|
516 | class WorkflowManager(grok.Role): |
---|
517 | """The Workflow Manager can trigger workflow transitions |
---|
518 | of student and document objects, see TriggerTransition permission |
---|
519 | for further information. |
---|
520 | """ |
---|
521 | grok.name('waeup.WorkflowManager') |
---|
522 | grok.title(u'Workflow Manager') |
---|
523 | grok.permissions('waeup.triggerTransition') |
---|
524 | |
---|
525 | |
---|
526 | class FingerprintReaderDeviceRole(grok.Role): |
---|
527 | """Fingerprint Reader Devices. |
---|
528 | |
---|
529 | Fingerprint readers are remote devices that can store and retrieve |
---|
530 | fingerprint data. |
---|
531 | """ |
---|
532 | grok.name('waeup.FingerprintDevice') |
---|
533 | grok.title(u'Fingerprint Reader') |
---|
534 | grok.permissions( |
---|
535 | 'waeup.getBiometricData', |
---|
536 | 'waeup.putBiometricData', |
---|
537 | ) |
---|
538 | |
---|
539 | |
---|
540 | class PortalManager(grok.Role): |
---|
541 | """The PortalManager role is the maximum set of Kofa permissions |
---|
542 | which are needed to manage the entire portal. This set must not |
---|
543 | be customized. It is recommended to assign this role only |
---|
544 | to a few certified Kofa administrators. |
---|
545 | A less dangerous manager role is the CCOfficer role described below. |
---|
546 | For the most tasks the CCOfficer role is sufficient. |
---|
547 | """ |
---|
548 | grok.name('waeup.PortalManager') |
---|
549 | grok.title(u'Portal Manager') |
---|
550 | grok.permissions('waeup.managePortal', |
---|
551 | 'waeup.manageUsers', |
---|
552 | 'waeup.viewAcademics', 'waeup.manageAcademics', |
---|
553 | 'waeup.manageACBatches', |
---|
554 | 'waeup.manageDataCenter', |
---|
555 | 'waeup.importData', |
---|
556 | 'waeup.exportData', |
---|
557 | 'waeup.viewTranscript', |
---|
558 | 'waeup.viewDocuments', 'waeup.manageDocuments', |
---|
559 | 'waeup.managePortalConfiguration', |
---|
560 | 'waeup.viewApplication', |
---|
561 | 'waeup.manageApplication', 'waeup.handleApplication', |
---|
562 | 'waeup.viewApplicantsTab', 'waeup.payApplicant', |
---|
563 | 'waeup.viewApplicationStatistics', |
---|
564 | 'waeup.viewStudent', 'waeup.manageStudent', |
---|
565 | 'waeup.clearStudent', 'waeup.payStudent', |
---|
566 | 'waeup.clearStudentFinancially', # not used in base pkg |
---|
567 | 'waeup.uploadStudentFile', 'waeup.showStudents', |
---|
568 | 'waeup.clearAllStudents', |
---|
569 | 'waeup.createStudents', |
---|
570 | 'waeup.editScores', |
---|
571 | 'waeup.triggerTransition', |
---|
572 | 'waeup.validateStudent', |
---|
573 | 'waeup.viewStudentsContainer', |
---|
574 | 'waeup.handleAccommodation', |
---|
575 | 'waeup.viewHostels', 'waeup.manageHostels', |
---|
576 | 'waeup.editUser', |
---|
577 | 'waeup.loginAsStudent', |
---|
578 | 'waeup.handleReports', |
---|
579 | 'waeup.manageReports', |
---|
580 | 'waeup.manageJobs', |
---|
581 | ) |
---|
582 | |
---|
583 | |
---|
584 | class CCOfficer(grok.Role): |
---|
585 | """The role of the Computer Center Officer is basically a copy |
---|
586 | of the the PortalManager role. Some 'dangerous' permissions are excluded |
---|
587 | by commenting them out (see source code). If officers need to gain more |
---|
588 | access rights than defined in this role, do not hastily switch to the |
---|
589 | PortalManager role but add further manager roles instead. Additional |
---|
590 | roles could be: UsersManager, ACManager, ImportManager, WorkflowManager |
---|
591 | or StudentImpersonator. |
---|
592 | |
---|
593 | CCOfficer is a base class which means that this role is subject to |
---|
594 | customization. It is not used in the ``waeup.kofa`` base package. |
---|
595 | """ |
---|
596 | grok.baseclass() |
---|
597 | grok.name('waeup.CCOfficer') |
---|
598 | grok.title(u'Computer Center Officer') |
---|
599 | grok.permissions( |
---|
600 | # 'waeup.managePortal', |
---|
601 | # 'waeup.manageUsers', |
---|
602 | 'waeup.viewAcademics', |
---|
603 | 'waeup.manageAcademics', |
---|
604 | # 'waeup.manageACBatches', |
---|
605 | 'waeup.manageDataCenter', |
---|
606 | # 'waeup.importData', |
---|
607 | 'waeup.exportData', |
---|
608 | 'waeup.viewTranscript', |
---|
609 | 'waeup.viewDocuments', 'waeup.manageDocuments', |
---|
610 | 'waeup.managePortalConfiguration', 'waeup.viewApplication', |
---|
611 | 'waeup.manageApplication', 'waeup.handleApplication', |
---|
612 | 'waeup.viewApplicantsTab', 'waeup.payApplicant', |
---|
613 | 'waeup.viewApplicationStatistics', |
---|
614 | 'waeup.viewStudent', 'waeup.manageStudent', |
---|
615 | 'waeup.clearStudent', 'waeup.payStudent', |
---|
616 | 'waeup.uploadStudentFile', 'waeup.showStudents', |
---|
617 | 'waeup.clearAllStudents', |
---|
618 | # 'waeup.createStudents', |
---|
619 | 'waeup.editScores', |
---|
620 | # 'waeup.triggerTransition', |
---|
621 | 'waeup.validateStudent', |
---|
622 | 'waeup.viewStudentsContainer', |
---|
623 | 'waeup.handleAccommodation', |
---|
624 | 'waeup.viewHostels', 'waeup.manageHostels', |
---|
625 | # 'waeup.editUser', |
---|
626 | # 'waeup.loginAsStudent', |
---|
627 | 'waeup.handleReports', |
---|
628 | 'waeup.manageReports', |
---|
629 | # 'waeup.manageJobs', |
---|
630 | ) |
---|
631 | |
---|
632 | |
---|
633 | def get_all_roles(): |
---|
634 | """Return a list of tuples ``<ROLE-NAME>, <ROLE>``. |
---|
635 | """ |
---|
636 | return getUtilitiesFor(IRole) |
---|
637 | |
---|
638 | |
---|
639 | def get_waeup_roles(also_local=False): |
---|
640 | """Get all Kofa roles. |
---|
641 | |
---|
642 | Kofa roles are ordinary roles whose id by convention starts with |
---|
643 | a ``waeup.`` prefix. |
---|
644 | |
---|
645 | If `also_local` is ``True`` (``False`` by default), also local |
---|
646 | roles are returned. Local Kofa roles are such whose id starts |
---|
647 | with ``waeup.local.`` prefix (this is also a convention). |
---|
648 | |
---|
649 | Returns a generator of the found roles. |
---|
650 | """ |
---|
651 | for name, item in get_all_roles(): |
---|
652 | if not name.startswith('waeup.'): |
---|
653 | # Ignore non-Kofa roles... |
---|
654 | continue |
---|
655 | if not also_local and name.startswith('waeup.local.'): |
---|
656 | # Ignore local roles... |
---|
657 | continue |
---|
658 | yield item |
---|
659 | |
---|
660 | |
---|
661 | def get_waeup_role_names(): |
---|
662 | """Get the ids of all Kofa roles. |
---|
663 | |
---|
664 | See :func:`get_waeup_roles` for what a 'KofaRole' is. |
---|
665 | |
---|
666 | This function returns a sorted list of Kofa role names. |
---|
667 | """ |
---|
668 | return sorted([x.id for x in get_waeup_roles()]) |
---|
669 | |
---|
670 | |
---|
671 | class LocalRolesAssignable(grok.Adapter): |
---|
672 | """Default implementation for `ILocalRolesAssignable`. |
---|
673 | |
---|
674 | This adapter returns a list for dictionaries for objects for which |
---|
675 | we want to know the roles assignable to them locally. |
---|
676 | |
---|
677 | The returned dicts contain a ``name`` and a ``title`` entry which |
---|
678 | give a role (``name``) and a description, for which kind of users |
---|
679 | the permission is meant to be used (``title``). |
---|
680 | |
---|
681 | Having this adapter registered we make sure, that for each normal |
---|
682 | object we get a valid `ILocalRolesAssignable` adapter. |
---|
683 | |
---|
684 | Objects that want to offer certain local roles, can do so by |
---|
685 | setting a (preferably class-) attribute to a list of role ids. |
---|
686 | |
---|
687 | You can also define different adapters for different contexts to |
---|
688 | have different role lookup mechanisms become available. But in |
---|
689 | normal cases it should be sufficient to use this basic adapter. |
---|
690 | """ |
---|
691 | grok.context(Interface) |
---|
692 | grok.provides(ILocalRolesAssignable) |
---|
693 | |
---|
694 | _roles = [] |
---|
695 | |
---|
696 | def __init__(self, context): |
---|
697 | self.context = context |
---|
698 | role_ids = getattr(context, 'local_roles', self._roles) |
---|
699 | self._roles = [(name, role) for name, role in get_all_roles() |
---|
700 | if name in role_ids] |
---|
701 | return |
---|
702 | |
---|
703 | def __call__(self): |
---|
704 | """Get a list of dictionaries containing ``names`` (the roles to |
---|
705 | assign) and ``titles`` (some description of the type of user |
---|
706 | to assign each role to). |
---|
707 | """ |
---|
708 | list_of_dict = [dict( |
---|
709 | name=name, |
---|
710 | title=role.title, |
---|
711 | description=role.description) |
---|
712 | for name, role in self._roles] |
---|
713 | return sorted(list_of_dict, key=lambda x: x['name']) |
---|
714 | |
---|
715 | |
---|
716 | def get_all_users(): |
---|
717 | """Get a list of dictionaries. |
---|
718 | """ |
---|
719 | users = sorted(grok.getSite()['users'].items(), key=lambda x: x[1].title) |
---|
720 | for key, val in users: |
---|
721 | yield(dict(name=key, val=val)) |
---|
722 | |
---|
723 | |
---|
724 | def get_users_with_local_roles(context): |
---|
725 | """Get a list of dicts representing the local roles set for `context`. |
---|
726 | |
---|
727 | Each dict returns `user_name`, `user_title`, `local_role`, |
---|
728 | `local_role_title`, and `setting` for each entry in the local |
---|
729 | roles map of the `context` object. |
---|
730 | """ |
---|
731 | try: |
---|
732 | role_map = IPrincipalRoleMap(context) |
---|
733 | except TypeError: |
---|
734 | # no map no roles. |
---|
735 | raise StopIteration |
---|
736 | for local_role, user_name, setting in role_map.getPrincipalsAndRoles(): |
---|
737 | user = grok.getSite()['users'].get(user_name, None) |
---|
738 | user_title = getattr(user, 'title', user_name) |
---|
739 | local_role_title = getattr( |
---|
740 | dict(get_all_roles()).get(local_role, None), 'title', None) |
---|
741 | yield dict(user_name=user_name, |
---|
742 | user_title=user_title, |
---|
743 | local_role=local_role, |
---|
744 | local_role_title=local_role_title, |
---|
745 | setting=setting) |
---|
746 | |
---|
747 | |
---|
748 | def get_users_with_role(role, context): |
---|
749 | """Get a list of dicts representing the usres who have been granted |
---|
750 | a role for `context`. |
---|
751 | """ |
---|
752 | try: |
---|
753 | role_map = IPrincipalRoleMap(context) |
---|
754 | except TypeError: |
---|
755 | # no map no roles. |
---|
756 | raise StopIteration |
---|
757 | for user_name, setting in role_map.getPrincipalsForRole(role): |
---|
758 | user = grok.getSite()['users'].get(user_name, None) |
---|
759 | user_title = getattr(user, 'title', user_name) |
---|
760 | user_email = getattr(user, 'email', None) |
---|
761 | yield dict(user_name=user_name, |
---|
762 | user_title=user_title, |
---|
763 | user_email=user_email, |
---|
764 | setting=setting) |
---|