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