[14603] | 1 | # $Id: permissions.py 14633 2017-03-19 16:15:46Z uli $ |
---|
| 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 | |
---|
[7185] | 207 | class DepartmentManager(grok.Role): |
---|
[12847] | 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. |
---|
[12843] | 214 | """ |
---|
[7185] | 215 | grok.name('waeup.local.DepartmentManager') |
---|
| 216 | grok.title(u'Department Manager') |
---|
[10248] | 217 | grok.permissions('waeup.manageAcademics', |
---|
| 218 | 'waeup.showStudents', |
---|
| 219 | 'waeup.exportData') |
---|
[6142] | 220 | |
---|
[14603] | 221 | |
---|
[10279] | 222 | class DepartmentOfficer(grok.Role): |
---|
[12847] | 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. |
---|
[12843] | 230 | """ |
---|
[10279] | 231 | grok.name('waeup.local.DepartmentOfficer') |
---|
| 232 | grok.title(u'Department Officer') |
---|
| 233 | grok.permissions('waeup.showStudents', |
---|
| 234 | 'waeup.viewAcademics', |
---|
| 235 | 'waeup.exportPaymentsOverview') |
---|
| 236 | |
---|
[14603] | 237 | |
---|
[6655] | 238 | class ClearanceOfficer(grok.Role): |
---|
[12847] | 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. |
---|
[7168] | 246 | """ |
---|
[6655] | 247 | grok.name('waeup.local.ClearanceOfficer') |
---|
| 248 | grok.title(u'Clearance Officer') |
---|
[10248] | 249 | grok.permissions('waeup.showStudents', |
---|
| 250 | 'waeup.viewAcademics', |
---|
[11862] | 251 | 'waeup.exportData', |
---|
| 252 | 'waeup.clearAllStudents') |
---|
[6655] | 253 | |
---|
[14603] | 254 | |
---|
[10639] | 255 | class LocalStudentsManager(grok.Role): |
---|
[12847] | 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. |
---|
[10639] | 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 | |
---|
[14603] | 270 | |
---|
[10639] | 271 | class LocalWorkflowManager(grok.Role): |
---|
[12847] | 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. |
---|
[10639] | 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 | |
---|
[14603] | 286 | |
---|
[8962] | 287 | class UGClearanceOfficer(grok.Role): |
---|
[12847] | 288 | """UG Clearance Officers are regular Clearance Officers with restricted |
---|
| 289 | dynamic permission assignment. They can only access undergraduate |
---|
| 290 | students. |
---|
[8962] | 291 | """ |
---|
| 292 | grok.name('waeup.local.UGClearanceOfficer') |
---|
| 293 | grok.title(u'UG Clearance Officer') |
---|
[10248] | 294 | grok.permissions('waeup.showStudents', |
---|
| 295 | 'waeup.viewAcademics', |
---|
[11862] | 296 | 'waeup.exportData', |
---|
| 297 | 'waeup.clearAllStudents') |
---|
[8962] | 298 | |
---|
[14603] | 299 | |
---|
[8962] | 300 | class PGClearanceOfficer(grok.Role): |
---|
[12847] | 301 | """PG Clearance Officers are regular Clearance Officers with restricted |
---|
| 302 | dynamic permission assignment. They can only access postgraduate |
---|
| 303 | students. |
---|
[8962] | 304 | """ |
---|
| 305 | grok.name('waeup.local.PGClearanceOfficer') |
---|
| 306 | grok.title(u'PG Clearance Officer') |
---|
[10248] | 307 | grok.permissions('waeup.showStudents', |
---|
| 308 | 'waeup.viewAcademics', |
---|
[11862] | 309 | 'waeup.exportData', |
---|
| 310 | 'waeup.clearAllStudents') |
---|
[8962] | 311 | |
---|
[14603] | 312 | |
---|
[7334] | 313 | class CourseAdviser100(grok.Role): |
---|
[12847] | 314 | """The local CourseAdviser100 role can be assigned at faculty, |
---|
[14603] | 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 |
---|
[12847] | 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. |
---|
[7168] | 322 | """ |
---|
[7334] | 323 | grok.name('waeup.local.CourseAdviser100') |
---|
| 324 | grok.title(u'Course Adviser 100L') |
---|
[10248] | 325 | grok.permissions('waeup.showStudents', |
---|
| 326 | 'waeup.viewAcademics', |
---|
| 327 | 'waeup.exportData') |
---|
[6655] | 328 | |
---|
[14603] | 329 | |
---|
[7334] | 330 | class CourseAdviser200(grok.Role): |
---|
[12847] | 331 | """Same as CourseAdviser100 but for level 200. |
---|
[7334] | 332 | """ |
---|
| 333 | grok.name('waeup.local.CourseAdviser200') |
---|
| 334 | grok.title(u'Course Adviser 200L') |
---|
[10248] | 335 | grok.permissions('waeup.showStudents', |
---|
| 336 | 'waeup.viewAcademics', |
---|
| 337 | 'waeup.exportData') |
---|
[7334] | 338 | |
---|
[14603] | 339 | |
---|
[7334] | 340 | class CourseAdviser300(grok.Role): |
---|
[12847] | 341 | """Same as CourseAdviser100 but for level 300. |
---|
[7334] | 342 | """ |
---|
| 343 | grok.name('waeup.local.CourseAdviser300') |
---|
| 344 | grok.title(u'Course Adviser 300L') |
---|
[10248] | 345 | grok.permissions('waeup.showStudents', |
---|
| 346 | 'waeup.viewAcademics', |
---|
| 347 | 'waeup.exportData') |
---|
[7334] | 348 | |
---|
[14603] | 349 | |
---|
[7334] | 350 | class CourseAdviser400(grok.Role): |
---|
[12847] | 351 | """Same as CourseAdviser100 but for level 400. |
---|
[7334] | 352 | """ |
---|
| 353 | grok.name('waeup.local.CourseAdviser400') |
---|
| 354 | grok.title(u'Course Adviser 400L') |
---|
[10248] | 355 | grok.permissions('waeup.showStudents', |
---|
| 356 | 'waeup.viewAcademics', |
---|
| 357 | 'waeup.exportData') |
---|
[7334] | 358 | |
---|
[14603] | 359 | |
---|
[7334] | 360 | class CourseAdviser500(grok.Role): |
---|
[12847] | 361 | """Same as CourseAdviser100 but for level 500. |
---|
[7334] | 362 | """ |
---|
| 363 | grok.name('waeup.local.CourseAdviser500') |
---|
| 364 | grok.title(u'Course Adviser 500L') |
---|
[10248] | 365 | grok.permissions('waeup.showStudents', |
---|
| 366 | 'waeup.viewAcademics', |
---|
| 367 | 'waeup.exportData') |
---|
[7334] | 368 | |
---|
[14603] | 369 | |
---|
[7334] | 370 | class CourseAdviser600(grok.Role): |
---|
[12847] | 371 | """Same as CourseAdviser100 but for level 600. |
---|
[7334] | 372 | """ |
---|
| 373 | grok.name('waeup.local.CourseAdviser600') |
---|
| 374 | grok.title(u'Course Adviser 600L') |
---|
[10248] | 375 | grok.permissions('waeup.showStudents', |
---|
| 376 | 'waeup.viewAcademics', |
---|
| 377 | 'waeup.exportData') |
---|
[7334] | 378 | |
---|
[14603] | 379 | |
---|
[10064] | 380 | class CourseAdviser700(grok.Role): |
---|
[12847] | 381 | """Same as CourseAdviser100 but for level 700. |
---|
[10064] | 382 | """ |
---|
| 383 | grok.name('waeup.local.CourseAdviser700') |
---|
| 384 | grok.title(u'Course Adviser 700L') |
---|
[10248] | 385 | grok.permissions('waeup.showStudents', |
---|
| 386 | 'waeup.viewAcademics', |
---|
| 387 | 'waeup.exportData') |
---|
[10064] | 388 | |
---|
[14603] | 389 | |
---|
[10064] | 390 | class CourseAdviser800(grok.Role): |
---|
[12847] | 391 | """Same as CourseAdviser100 but for level 800. |
---|
[10064] | 392 | """ |
---|
| 393 | grok.name('waeup.local.CourseAdviser800') |
---|
| 394 | grok.title(u'Course Adviser 800L') |
---|
[10248] | 395 | grok.permissions('waeup.showStudents', |
---|
| 396 | 'waeup.viewAcademics', |
---|
| 397 | 'waeup.exportData') |
---|
[10064] | 398 | |
---|
[14603] | 399 | |
---|
[9002] | 400 | class Lecturer(grok.Role): |
---|
[12847] | 401 | """The local Lecturer role can be assigned at course level. |
---|
[13894] | 402 | The role allows to export some student |
---|
[13046] | 403 | data within the course the local role is assigned. Lecturers can't access |
---|
[12847] | 404 | student data directly but they can edit the scores in course tickets. |
---|
[9002] | 405 | """ |
---|
| 406 | grok.name('waeup.local.Lecturer') |
---|
| 407 | grok.title(u'Lecturer') |
---|
[13894] | 408 | grok.permissions('waeup.editScores', |
---|
[10248] | 409 | 'waeup.viewAcademics', |
---|
| 410 | 'waeup.exportData') |
---|
[9002] | 411 | |
---|
[14603] | 412 | |
---|
[7163] | 413 | class Owner(grok.Role): |
---|
[12847] | 414 | """Each user 'owns' her/his user object and gains permission to edit |
---|
| 415 | some of the user attributes. |
---|
| 416 | """ |
---|
[7163] | 417 | grok.name('waeup.local.Owner') |
---|
| 418 | grok.title(u'Owner') |
---|
| 419 | grok.permissions('waeup.editUser') |
---|
| 420 | |
---|
[14603] | 421 | |
---|
[7178] | 422 | # Site Roles |
---|
[7185] | 423 | class AcademicsOfficer(grok.Role): |
---|
[12844] | 424 | """An Academics Officer can view but not edit data in the |
---|
[12862] | 425 | academic section. |
---|
[12843] | 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 | """ |
---|
[7185] | 431 | grok.name('waeup.AcademicsOfficer') |
---|
[7188] | 432 | grok.title(u'Academics Officer (view only)') |
---|
[7184] | 433 | grok.permissions('waeup.viewAcademics') |
---|
[3521] | 434 | |
---|
[14603] | 435 | |
---|
[8367] | 436 | class AcademicsManager(grok.Role): |
---|
[12843] | 437 | """An Academics Manager can view and edit all data in the |
---|
[12862] | 438 | scademic section, i.e. access all manage pages |
---|
[12843] | 439 | at faculty, department, course, certificate and certificate course level. |
---|
| 440 | """ |
---|
[8367] | 441 | grok.name('waeup.AcademicsManager') |
---|
| 442 | grok.title(u'Academics Manager') |
---|
[12835] | 443 | title = u'Academics Manager' |
---|
[8367] | 444 | grok.permissions('waeup.viewAcademics', |
---|
| 445 | 'waeup.manageAcademics') |
---|
| 446 | |
---|
[14603] | 447 | |
---|
[7181] | 448 | class ACManager(grok.Role): |
---|
[12843] | 449 | """This is the role for Access Code Managers. |
---|
[12847] | 450 | An AC Manager can view and manage the Accesscodes Section, see |
---|
[12844] | 451 | ManageACBatches permission above. |
---|
[12843] | 452 | """ |
---|
[7181] | 453 | grok.name('waeup.ACManager') |
---|
| 454 | grok.title(u'Access Code Manager') |
---|
| 455 | grok.permissions('waeup.manageACBatches') |
---|
| 456 | |
---|
[14603] | 457 | |
---|
[8367] | 458 | class DataCenterManager(grok.Role): |
---|
[12843] | 459 | """This single-permission role is dedicated to those users |
---|
| 460 | who are charged with batch processing of portal data. |
---|
[12847] | 461 | A Data Center Manager can access all pages in the Data Center, |
---|
[12844] | 462 | see ManageDataCenter permission above. |
---|
[12843] | 463 | """ |
---|
[8367] | 464 | grok.name('waeup.DataCenterManager') |
---|
| 465 | grok.title(u'Datacenter Manager') |
---|
| 466 | grok.permissions('waeup.manageDataCenter') |
---|
| 467 | |
---|
[14603] | 468 | |
---|
[8367] | 469 | class ImportManager(grok.Role): |
---|
[12847] | 470 | """An Import Manager is a Data Center Manager who is also allowed |
---|
[14603] | 471 | to batch process (import) data. All batch processors (importers) are |
---|
[12843] | 472 | available except for the User Processor. This processor requires the |
---|
[12847] | 473 | Users Manager role too. The ImportManager role includes the |
---|
[12844] | 474 | DataCenterManager role but not vice versa. |
---|
[12843] | 475 | """ |
---|
[8367] | 476 | grok.name('waeup.ImportManager') |
---|
| 477 | grok.title(u'Import Manager') |
---|
| 478 | grok.permissions('waeup.manageDataCenter', |
---|
| 479 | 'waeup.importData') |
---|
| 480 | |
---|
[14603] | 481 | |
---|
[10177] | 482 | class ExportManager(grok.Role): |
---|
[12847] | 483 | """An Export Manager is a Data Center Manager who is also allowed |
---|
[12843] | 484 | to export all kind of portal data. The ExportManager role includes the |
---|
[12844] | 485 | DataCenterManager role but not vice versa. |
---|
[12843] | 486 | """ |
---|
[10177] | 487 | grok.name('waeup.ExportManager') |
---|
| 488 | grok.title(u'Export Manager') |
---|
| 489 | grok.permissions('waeup.manageDataCenter', |
---|
| 490 | 'waeup.exportData') |
---|
| 491 | |
---|
[14603] | 492 | |
---|
[10246] | 493 | class BursaryOfficer(grok.Role): |
---|
[12847] | 494 | """Bursary Officers can export bursary data. They can't access the |
---|
[12844] | 495 | Data Center but see student data export buttons in the Academic Section. |
---|
[12843] | 496 | """ |
---|
[10246] | 497 | grok.name('waeup.BursaryOfficer') |
---|
| 498 | grok.title(u'Bursary Officer') |
---|
[10279] | 499 | grok.permissions('waeup.showStudents', |
---|
| 500 | 'waeup.viewAcademics', |
---|
| 501 | 'waeup.exportBursaryData') |
---|
[10246] | 502 | |
---|
[14603] | 503 | |
---|
[8367] | 504 | class UsersManager(grok.Role): |
---|
[12847] | 505 | """A Users Manager can add, remove or edit |
---|
[12844] | 506 | user accounts, see ManageUsers permission for further information. |
---|
| 507 | Be very careful with this role. |
---|
[12843] | 508 | """ |
---|
[8367] | 509 | grok.name('waeup.UsersManager') |
---|
| 510 | grok.title(u'Users Manager') |
---|
[9259] | 511 | grok.permissions('waeup.manageUsers', |
---|
| 512 | 'waeup.editUser') |
---|
[8367] | 513 | |
---|
[14603] | 514 | |
---|
[9300] | 515 | class WorkflowManager(grok.Role): |
---|
[12847] | 516 | """The Workflow Manager can trigger workflow transitions |
---|
[12844] | 517 | of student and document objects, see TriggerTransition permission |
---|
| 518 | for further information. |
---|
[12843] | 519 | """ |
---|
[9300] | 520 | grok.name('waeup.WorkflowManager') |
---|
| 521 | grok.title(u'Workflow Manager') |
---|
[9299] | 522 | grok.permissions('waeup.triggerTransition') |
---|
| 523 | |
---|
[14602] | 524 | |
---|
| 525 | class FingerprintReaderDeviceRole(grok.Role): |
---|
| 526 | """Fingerprint Reader Devices. |
---|
| 527 | |
---|
| 528 | Fingerprint readers are remote devices that can store and retrieve |
---|
| 529 | fingerprint data.i |
---|
| 530 | """ |
---|
| 531 | grok.name('waeup.FingerprintDevice') |
---|
| 532 | grok.title(u'Fingerprint Reader') |
---|
| 533 | grok.permissions( |
---|
[14633] | 534 | 'waeup.getBiometricData', |
---|
| 535 | 'waeup.putBiometricData', |
---|
| 536 | ) |
---|
[14602] | 537 | |
---|
| 538 | |
---|
[4789] | 539 | class PortalManager(grok.Role): |
---|
[12847] | 540 | """The PortalManager role is the maximum set of Kofa permissions |
---|
[12835] | 541 | which are needed to manage the entire portal. This set must not |
---|
[12844] | 542 | be customized. It is recommended to assign this role only |
---|
| 543 | to a few certified Kofa administrators. |
---|
| 544 | A less dangerous manager role is the CCOfficer role described below. |
---|
| 545 | For the most tasks the CCOfficer role is sufficient. |
---|
[12835] | 546 | """ |
---|
[4789] | 547 | grok.name('waeup.PortalManager') |
---|
[6159] | 548 | grok.title(u'Portal Manager') |
---|
[9259] | 549 | grok.permissions('waeup.managePortal', |
---|
| 550 | 'waeup.manageUsers', |
---|
[8374] | 551 | 'waeup.viewAcademics', 'waeup.manageAcademics', |
---|
[8367] | 552 | 'waeup.manageACBatches', |
---|
[9259] | 553 | 'waeup.manageDataCenter', |
---|
| 554 | 'waeup.importData', |
---|
[10177] | 555 | 'waeup.exportData', |
---|
[10278] | 556 | 'waeup.viewTranscript', |
---|
[12440] | 557 | 'waeup.viewDocuments', 'waeup.manageDocuments', |
---|
[14603] | 558 | 'waeup.managePortalConfiguration', |
---|
| 559 | 'waeup.viewApplication', |
---|
[7184] | 560 | 'waeup.manageApplication', 'waeup.handleApplication', |
---|
[7250] | 561 | 'waeup.viewApplicantsTab', 'waeup.payApplicant', |
---|
[8565] | 562 | 'waeup.viewApplicationStatistics', |
---|
[7250] | 563 | 'waeup.viewStudent', 'waeup.manageStudent', |
---|
| 564 | 'waeup.clearStudent', 'waeup.payStudent', |
---|
[14603] | 565 | 'waeup.clearStudentFinancially', # not used in base pkg |
---|
[7250] | 566 | 'waeup.uploadStudentFile', 'waeup.showStudents', |
---|
[11862] | 567 | 'waeup.clearAllStudents', |
---|
[10632] | 568 | 'waeup.editScores', |
---|
[9273] | 569 | 'waeup.triggerTransition', |
---|
[14166] | 570 | 'waeup.validateStudent', |
---|
[12843] | 571 | 'waeup.viewStudentsContainer', |
---|
[9186] | 572 | 'waeup.handleAccommodation', |
---|
[7205] | 573 | 'waeup.viewHostels', 'waeup.manageHostels', |
---|
[9335] | 574 | 'waeup.editUser', |
---|
[9637] | 575 | 'waeup.loginAsStudent', |
---|
[12900] | 576 | 'waeup.handleReports', |
---|
[9637] | 577 | 'waeup.manageReports', |
---|
[9645] | 578 | 'waeup.manageJobs', |
---|
[7240] | 579 | ) |
---|
[4789] | 580 | |
---|
[14603] | 581 | |
---|
[9259] | 582 | class CCOfficer(grok.Role): |
---|
[12843] | 583 | """The role of the Computer Center Officer is basically a copy |
---|
[12835] | 584 | of the the PortalManager role. Some 'dangerous' permissions are excluded |
---|
| 585 | by commenting them out (see source code). If officers need to gain more |
---|
| 586 | access rights than defined in this role, do not hastily switch to the |
---|
[12843] | 587 | PortalManager role but add further manager roles instead. Additional |
---|
[12835] | 588 | roles could be: UsersManager, ACManager, ImportManager, WorkflowManager |
---|
| 589 | or StudentImpersonator. |
---|
[12843] | 590 | |
---|
[12844] | 591 | CCOfficer is a base class which means that this role is subject to |
---|
| 592 | customization. It is not used in the ``waeup.kofa`` base package. |
---|
[9259] | 593 | """ |
---|
[10346] | 594 | grok.baseclass() |
---|
[9259] | 595 | grok.name('waeup.CCOfficer') |
---|
| 596 | grok.title(u'Computer Center Officer') |
---|
[14603] | 597 | grok.permissions( |
---|
| 598 | # 'waeup.managePortal', |
---|
| 599 | # 'waeup.manageUsers', |
---|
| 600 | 'waeup.viewAcademics', |
---|
| 601 | 'waeup.manageAcademics', |
---|
| 602 | # 'waeup.manageACBatches', |
---|
| 603 | 'waeup.manageDataCenter', |
---|
| 604 | # 'waeup.importData', |
---|
| 605 | 'waeup.exportData', |
---|
| 606 | 'waeup.viewTranscript', |
---|
| 607 | 'waeup.viewDocuments', 'waeup.manageDocuments', |
---|
| 608 | 'waeup.managePortalConfiguration', 'waeup.viewApplication', |
---|
| 609 | 'waeup.manageApplication', 'waeup.handleApplication', |
---|
| 610 | 'waeup.viewApplicantsTab', 'waeup.payApplicant', |
---|
| 611 | 'waeup.viewApplicationStatistics', |
---|
| 612 | 'waeup.viewStudent', 'waeup.manageStudent', |
---|
| 613 | 'waeup.clearStudent', 'waeup.payStudent', |
---|
| 614 | 'waeup.uploadStudentFile', 'waeup.showStudents', |
---|
| 615 | 'waeup.clearAllStudents', |
---|
| 616 | 'waeup.editScores', |
---|
| 617 | # 'waeup.triggerTransition', |
---|
| 618 | 'waeup.validateStudent', |
---|
| 619 | 'waeup.viewStudentsContainer', |
---|
| 620 | 'waeup.handleAccommodation', |
---|
| 621 | 'waeup.viewHostels', 'waeup.manageHostels', |
---|
| 622 | # 'waeup.editUser', |
---|
| 623 | # 'waeup.loginAsStudent', |
---|
| 624 | 'waeup.handleReports', |
---|
| 625 | 'waeup.manageReports', |
---|
| 626 | # 'waeup.manageJobs', |
---|
| 627 | ) |
---|
[9259] | 628 | |
---|
[14603] | 629 | |
---|
[7186] | 630 | def get_all_roles(): |
---|
[6157] | 631 | """Return a list of tuples ``<ROLE-NAME>, <ROLE>``. |
---|
| 632 | """ |
---|
| 633 | return getUtilitiesFor(IRole) |
---|
| 634 | |
---|
[14603] | 635 | |
---|
[7186] | 636 | def get_waeup_roles(also_local=False): |
---|
[7819] | 637 | """Get all Kofa roles. |
---|
[6157] | 638 | |
---|
[7819] | 639 | Kofa roles are ordinary roles whose id by convention starts with |
---|
[6157] | 640 | a ``waeup.`` prefix. |
---|
| 641 | |
---|
| 642 | If `also_local` is ``True`` (``False`` by default), also local |
---|
[7819] | 643 | roles are returned. Local Kofa roles are such whose id starts |
---|
[6157] | 644 | with ``waeup.local.`` prefix (this is also a convention). |
---|
| 645 | |
---|
| 646 | Returns a generator of the found roles. |
---|
| 647 | """ |
---|
[7186] | 648 | for name, item in get_all_roles(): |
---|
[6157] | 649 | if not name.startswith('waeup.'): |
---|
[7819] | 650 | # Ignore non-Kofa roles... |
---|
[4789] | 651 | continue |
---|
[6157] | 652 | if not also_local and name.startswith('waeup.local.'): |
---|
| 653 | # Ignore local roles... |
---|
[6045] | 654 | continue |
---|
[6157] | 655 | yield item |
---|
[4789] | 656 | |
---|
[14603] | 657 | |
---|
[7186] | 658 | def get_waeup_role_names(): |
---|
[7819] | 659 | """Get the ids of all Kofa roles. |
---|
[6157] | 660 | |
---|
[7819] | 661 | See :func:`get_waeup_roles` for what a 'KofaRole' is. |
---|
[6157] | 662 | |
---|
[7819] | 663 | This function returns a sorted list of Kofa role names. |
---|
[6157] | 664 | """ |
---|
[7186] | 665 | return sorted([x.id for x in get_waeup_roles()]) |
---|
[6157] | 666 | |
---|
[14603] | 667 | |
---|
[6144] | 668 | class LocalRolesAssignable(grok.Adapter): |
---|
| 669 | """Default implementation for `ILocalRolesAssignable`. |
---|
| 670 | |
---|
| 671 | This adapter returns a list for dictionaries for objects for which |
---|
| 672 | we want to know the roles assignable to them locally. |
---|
| 673 | |
---|
| 674 | The returned dicts contain a ``name`` and a ``title`` entry which |
---|
| 675 | give a role (``name``) and a description, for which kind of users |
---|
| 676 | the permission is meant to be used (``title``). |
---|
| 677 | |
---|
| 678 | Having this adapter registered we make sure, that for each normal |
---|
| 679 | object we get a valid `ILocalRolesAssignable` adapter. |
---|
| 680 | |
---|
| 681 | Objects that want to offer certain local roles, can do so by |
---|
[6162] | 682 | setting a (preferably class-) attribute to a list of role ids. |
---|
[6144] | 683 | |
---|
| 684 | You can also define different adapters for different contexts to |
---|
| 685 | have different role lookup mechanisms become available. But in |
---|
| 686 | normal cases it should be sufficient to use this basic adapter. |
---|
| 687 | """ |
---|
| 688 | grok.context(Interface) |
---|
| 689 | grok.provides(ILocalRolesAssignable) |
---|
| 690 | |
---|
| 691 | _roles = [] |
---|
| 692 | |
---|
| 693 | def __init__(self, context): |
---|
| 694 | self.context = context |
---|
[6162] | 695 | role_ids = getattr(context, 'local_roles', self._roles) |
---|
[7186] | 696 | self._roles = [(name, role) for name, role in get_all_roles() |
---|
[6162] | 697 | if name in role_ids] |
---|
[6144] | 698 | return |
---|
| 699 | |
---|
| 700 | def __call__(self): |
---|
| 701 | """Get a list of dictionaries containing ``names`` (the roles to |
---|
| 702 | assign) and ``titles`` (some description of the type of user |
---|
| 703 | to assign each role to). |
---|
| 704 | """ |
---|
[7334] | 705 | list_of_dict = [dict( |
---|
[6162] | 706 | name=name, |
---|
| 707 | title=role.title, |
---|
[6163] | 708 | description=role.description) |
---|
[7334] | 709 | for name, role in self._roles] |
---|
| 710 | return sorted(list_of_dict, key=lambda x: x['name']) |
---|
[6144] | 711 | |
---|
[14603] | 712 | |
---|
[8774] | 713 | def get_all_users(): |
---|
| 714 | """Get a list of dictionaries. |
---|
| 715 | """ |
---|
| 716 | users = sorted(grok.getSite()['users'].items(), key=lambda x: x[1].title) |
---|
| 717 | for key, val in users: |
---|
| 718 | yield(dict(name=key, val=val)) |
---|
| 719 | |
---|
[14603] | 720 | |
---|
[6163] | 721 | def get_users_with_local_roles(context): |
---|
| 722 | """Get a list of dicts representing the local roles set for `context`. |
---|
| 723 | |
---|
| 724 | Each dict returns `user_name`, `user_title`, `local_role`, |
---|
| 725 | `local_role_title`, and `setting` for each entry in the local |
---|
| 726 | roles map of the `context` object. |
---|
| 727 | """ |
---|
[6202] | 728 | try: |
---|
| 729 | role_map = IPrincipalRoleMap(context) |
---|
| 730 | except TypeError: |
---|
| 731 | # no map no roles. |
---|
| 732 | raise StopIteration |
---|
[6163] | 733 | for local_role, user_name, setting in role_map.getPrincipalsAndRoles(): |
---|
[14603] | 734 | user = grok.getSite()['users'].get(user_name, None) |
---|
[7213] | 735 | user_title = getattr(user, 'title', user_name) |
---|
[10227] | 736 | local_role_title = getattr( |
---|
| 737 | dict(get_all_roles()).get(local_role, None), 'title', None) |
---|
[14603] | 738 | yield dict(user_name=user_name, |
---|
| 739 | user_title=user_title, |
---|
| 740 | local_role=local_role, |
---|
| 741 | local_role_title=local_role_title, |
---|
| 742 | setting=setting) |
---|
[9309] | 743 | |
---|
[14603] | 744 | |
---|
[9309] | 745 | def get_users_with_role(role, context): |
---|
| 746 | """Get a list of dicts representing the usres who have been granted |
---|
| 747 | a role for `context`. |
---|
| 748 | """ |
---|
| 749 | try: |
---|
| 750 | role_map = IPrincipalRoleMap(context) |
---|
| 751 | except TypeError: |
---|
| 752 | # no map no roles. |
---|
| 753 | raise StopIteration |
---|
| 754 | for user_name, setting in role_map.getPrincipalsForRole(role): |
---|
[14603] | 755 | user = grok.getSite()['users'].get(user_name, None) |
---|
[9309] | 756 | user_title = getattr(user, 'title', user_name) |
---|
| 757 | user_email = getattr(user, 'email', None) |
---|
[14603] | 758 | yield dict(user_name=user_name, |
---|
| 759 | user_title=user_title, |
---|
| 760 | user_email=user_email, |
---|
| 761 | setting=setting) |
---|