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