source: main/waeup.kofa/trunk/src/waeup/kofa/permissions.py @ 12845

Last change on this file since 12845 was 12844, checked in by Henrik Bettermann, 10 years ago

Add ReportsManager? role.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 23.7 KB
RevLine 
[7193]1## $Id: permissions.py 12844 2015-04-02 06:11:59Z 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]18import grok
[6157]19from zope.component import getUtilitiesFor
[6144]20from zope.interface import Interface
[6163]21from zope.securitypolicy.interfaces import IRole, IPrincipalRoleMap
[7811]22from waeup.kofa.interfaces import ILocalRolesAssignable
[3521]23
[4789]24class 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]30class 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]37class 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]43class 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]50class 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]57class 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]69class 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]79class 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]91class 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]97class 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]102class 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]108class 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]114class 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
117    allow to process uploaded data.
[12835]118    """
[6127]119    grok.name('waeup.manageDataCenter')
[6142]120
[8367]121class ImportData(grok.Permission):
[12843]122    """The ImportData permission allows to batch process (import) any kind of
[12844]123    portal data except for user data. This User Data processor
124    requires also the ManageUsers permission.
[12835]125    """
[8367]126    grok.name('waeup.importData')
127
[10177]128class 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]133class ExportPaymentsOverview(grok.Permission):
134    grok.name('waeup.exportPaymentsOverview')
135
136class ExportBursaryData(grok.Permission):
137    grok.name('waeup.exportBursaryData')
138
[10278]139class ViewTranscript(grok.Permission):
140    grok.name('waeup.viewTranscript')
141
[6907]142class 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]148class 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]154class PutBiometricDataPermission(grok.Permission):
[12835]155    """This permission allows to upload/change biometric data.
[11673]156    """
157    grok.name('waeup.putBiometricData')
158
[11665]159class 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
[10226]166class ApplicationsManager(grok.Role):
[12843]167    """
168    """
[10226]169    grok.name('waeup.local.ApplicationsManager')
170    grok.title(u'Applications Manager')
171    grok.permissions('waeup.viewAcademics')
172
[7185]173class DepartmentManager(grok.Role):
[12843]174    """
175    """
[7185]176    grok.name('waeup.local.DepartmentManager')
177    grok.title(u'Department Manager')
[10248]178    grok.permissions('waeup.manageAcademics',
179                     'waeup.showStudents',
180                     'waeup.exportData')
[6142]181
[10279]182class DepartmentOfficer(grok.Role):
[12843]183    """
184    """
[10279]185    grok.name('waeup.local.DepartmentOfficer')
186    grok.title(u'Department Officer')
187    grok.permissions('waeup.showStudents',
188                     'waeup.viewAcademics',
189                     'waeup.exportPaymentsOverview')
190
[6655]191class ClearanceOfficer(grok.Role):
[7168]192    """The clearance officer role is meant for the
193    assignment of dynamic roles only.
194    """
[6655]195    grok.name('waeup.local.ClearanceOfficer')
196    grok.title(u'Clearance Officer')
[10248]197    grok.permissions('waeup.showStudents',
198                     'waeup.viewAcademics',
[11862]199                     'waeup.exportData',
200                     'waeup.clearAllStudents')
[6655]201
[10639]202class LocalStudentsManager(grok.Role):
203    """The local students manager role is meant for the
204    assignment of dynamic roles only.
205    """
206    grok.name('waeup.local.LocalStudentsManager')
207    grok.title(u'Students Manager')
208    grok.permissions('waeup.showStudents',
209                     'waeup.viewAcademics',
210                     'waeup.exportData')
211
212class LocalWorkflowManager(grok.Role):
213    """The local workflow manager role is meant for the
214    assignment of dynamic roles only.
215    """
216    grok.name('waeup.local.LocalWorkflowManager')
217    grok.title(u'Student Workflow Manager')
218    grok.permissions('waeup.showStudents',
219                     'waeup.viewAcademics',
220                     'waeup.exportData')
221
[8962]222class UGClearanceOfficer(grok.Role):
223    """The clearance officer role is meant for the
224    assignment of dynamic roles only.
225    """
226    grok.name('waeup.local.UGClearanceOfficer')
227    grok.title(u'UG Clearance Officer')
[10248]228    grok.permissions('waeup.showStudents',
229                     'waeup.viewAcademics',
[11862]230                     'waeup.exportData',
231                     'waeup.clearAllStudents')
[8962]232
233class PGClearanceOfficer(grok.Role):
234    """The clearance officer role is meant for the
235    assignment of dynamic roles only.
236    """
237    grok.name('waeup.local.PGClearanceOfficer')
238    grok.title(u'PG Clearance Officer')
[10248]239    grok.permissions('waeup.showStudents',
240                     'waeup.viewAcademics',
[11862]241                     'waeup.exportData',
242                     'waeup.clearAllStudents')
[8962]243
[7334]244class CourseAdviser100(grok.Role):
[7335]245    """The 100 level course adviser role is meant for the
[7168]246    assignment of dynamic roles only.
247    """
[7334]248    grok.name('waeup.local.CourseAdviser100')
249    grok.title(u'Course Adviser 100L')
[10248]250    grok.permissions('waeup.showStudents',
251                     'waeup.viewAcademics',
252                     'waeup.exportData')
[6655]253
[7334]254class CourseAdviser200(grok.Role):
[7335]255    """The course 200 level adviser role is meant for the
[7334]256    assignment of dynamic roles only.
257    """
258    grok.name('waeup.local.CourseAdviser200')
259    grok.title(u'Course Adviser 200L')
[10248]260    grok.permissions('waeup.showStudents',
261                     'waeup.viewAcademics',
262                     'waeup.exportData')
[7334]263
264class CourseAdviser300(grok.Role):
[7335]265    """The 300 level course adviser role is meant for the
[7334]266    assignment of dynamic roles only.
267    """
268    grok.name('waeup.local.CourseAdviser300')
269    grok.title(u'Course Adviser 300L')
[10248]270    grok.permissions('waeup.showStudents',
271                     'waeup.viewAcademics',
272                     'waeup.exportData')
[7334]273
274class CourseAdviser400(grok.Role):
[7335]275    """The 400 level course adviser role is meant for the
[7334]276    assignment of dynamic roles only.
277    """
278    grok.name('waeup.local.CourseAdviser400')
279    grok.title(u'Course Adviser 400L')
[10248]280    grok.permissions('waeup.showStudents',
281                     'waeup.viewAcademics',
282                     'waeup.exportData')
[7334]283
284class CourseAdviser500(grok.Role):
[7335]285    """The 500 level course adviser role is meant for the
[7334]286    assignment of dynamic roles only.
287    """
288    grok.name('waeup.local.CourseAdviser500')
289    grok.title(u'Course Adviser 500L')
[10248]290    grok.permissions('waeup.showStudents',
291                     'waeup.viewAcademics',
292                     'waeup.exportData')
[7334]293
294class CourseAdviser600(grok.Role):
[7335]295    """The 600 level course adviser role is meant for the
[7334]296    assignment of dynamic roles only.
297    """
298    grok.name('waeup.local.CourseAdviser600')
299    grok.title(u'Course Adviser 600L')
[10248]300    grok.permissions('waeup.showStudents',
301                     'waeup.viewAcademics',
302                     'waeup.exportData')
[7334]303
[10064]304class CourseAdviser700(grok.Role):
305    """The 700 level course adviser role is meant for the
306    assignment of dynamic roles only.
307    """
308    grok.name('waeup.local.CourseAdviser700')
309    grok.title(u'Course Adviser 700L')
[10248]310    grok.permissions('waeup.showStudents',
311                     'waeup.viewAcademics',
312                     'waeup.exportData')
[10064]313
314class CourseAdviser800(grok.Role):
315    """The 800 level course adviser role is meant for the
316    assignment of dynamic roles only.
317    """
318    grok.name('waeup.local.CourseAdviser800')
319    grok.title(u'Course Adviser 800L')
[10248]320    grok.permissions('waeup.showStudents',
321                     'waeup.viewAcademics',
322                     'waeup.exportData')
[10064]323
[9002]324class Lecturer(grok.Role):
325    """The lecturer role is meant for the
326    assignment of dynamic roles only.
327    """
328    grok.name('waeup.local.Lecturer')
329    grok.title(u'Lecturer')
[10248]330    grok.permissions('waeup.showStudents',
[10632]331                     'waeup.editScores',
[10248]332                     'waeup.viewAcademics',
333                     'waeup.exportData')
[9002]334
[7163]335class Owner(grok.Role):
336    grok.name('waeup.local.Owner')
337    grok.title(u'Owner')
338    grok.permissions('waeup.editUser')
339
[7178]340# Site Roles
[7185]341class AcademicsOfficer(grok.Role):
[12844]342    """An Academics Officer can view but not edit data in the
[12843]343    Academics Section.
344
345    This is the default role which is automatically assigned to all
346    officers of the portal. A user with this role can access all display pages
347    at faculty, department, course, certificate and certificate course level.
348    """
[7185]349    grok.name('waeup.AcademicsOfficer')
[7188]350    grok.title(u'Academics Officer (view only)')
[7184]351    grok.permissions('waeup.viewAcademics')
[3521]352
[8367]353class AcademicsManager(grok.Role):
[12843]354    """An Academics Manager can view and edit all data in the
[12844]355    Academics Section, i.e. access all manage pages
[12843]356    at faculty, department, course, certificate and certificate course level.
357    """
[8367]358    grok.name('waeup.AcademicsManager')
359    grok.title(u'Academics Manager')
[12835]360    title = u'Academics Manager'
[8367]361    grok.permissions('waeup.viewAcademics',
362                     'waeup.manageAcademics')
363
[7181]364class ACManager(grok.Role):
[12843]365    """This is the role for Access Code Managers.
[12844]366    An ACManager can view and manage the Accesscodes Section, see
367    ManageACBatches permission above.
[12843]368    """
[7181]369    grok.name('waeup.ACManager')
370    grok.title(u'Access Code Manager')
371    grok.permissions('waeup.manageACBatches')
372
[8367]373class DataCenterManager(grok.Role):
[12843]374    """This single-permission role is dedicated to those users
375    who are charged with batch processing of portal data.
[12844]376    A DataCenterManager manager can access all pages in the Data Center,
377    see ManageDataCenter permission above.
[12843]378    """
[8367]379    grok.name('waeup.DataCenterManager')
380    grok.title(u'Datacenter Manager')
381    grok.permissions('waeup.manageDataCenter')
382
383class ImportManager(grok.Role):
[12843]384    """An ImportManager is a DataCenterManager who is also allowed
385    to batch process (import) data. All batch processors (importers) are
386    available except for the User Processor. This processor requires the
387    UsersManager role too. The ImportManager role includes the
[12844]388    DataCenterManager role but not vice versa.
[12843]389    """
[8367]390    grok.name('waeup.ImportManager')
391    grok.title(u'Import Manager')
392    grok.permissions('waeup.manageDataCenter',
393                     'waeup.importData')
394
[10177]395class ExportManager(grok.Role):
[12843]396    """An ExportManager is a DataCenterManager who is also allowed
397    to export all kind of portal data. The ExportManager role includes the
[12844]398    DataCenterManager role but not vice versa.
[12843]399    """
[10177]400    grok.name('waeup.ExportManager')
401    grok.title(u'Export Manager')
402    grok.permissions('waeup.manageDataCenter',
403                     'waeup.exportData')
404
[10246]405class BursaryOfficer(grok.Role):
[12843]406    """BursaryOfficers can export bursary data. They can't access the
[12844]407    Data Center but see student data export buttons in the Academic Section.
[12843]408    """
[10246]409    grok.name('waeup.BursaryOfficer')
410    grok.title(u'Bursary Officer')
[10279]411    grok.permissions('waeup.showStudents',
412                     'waeup.viewAcademics',
413                     'waeup.exportBursaryData')
[10246]414
[8367]415class UsersManager(grok.Role):
[12844]416    """A UsersManager can add, remove or edit
417    user accounts, see ManageUsers permission for further information.
418    Be very careful with this role.
[12843]419    """
[8367]420    grok.name('waeup.UsersManager')
421    grok.title(u'Users Manager')
[9259]422    grok.permissions('waeup.manageUsers',
423                     'waeup.editUser')
[8367]424
[9300]425class WorkflowManager(grok.Role):
[12844]426    """The WorkflowManager can trigger workflow transitions
427    of student and document objects, see TriggerTransition permission
428    for further information.
[12843]429    """
[9300]430    grok.name('waeup.WorkflowManager')
431    grok.title(u'Workflow Manager')
[9299]432    grok.permissions('waeup.triggerTransition')
433
[4789]434class PortalManager(grok.Role):
[12835]435    """The portal manager role is the maximum set of Kofa permissions
436    which are needed to manage the entire portal. This set must not
[12844]437    be customized. It is recommended to assign this role only
438    to a few certified Kofa administrators.
439    A less dangerous manager role is the CCOfficer role described below.
440    For the most tasks the CCOfficer role is sufficient.
[12835]441    """
[4789]442    grok.name('waeup.PortalManager')
[6159]443    grok.title(u'Portal Manager')
[9259]444    grok.permissions('waeup.managePortal',
445                     'waeup.manageUsers',
[8374]446                     'waeup.viewAcademics', 'waeup.manageAcademics',
[8367]447                     'waeup.manageACBatches',
[9259]448                     'waeup.manageDataCenter',
449                     'waeup.importData',
[10177]450                     'waeup.exportData',
[10278]451                     'waeup.viewTranscript',
[12440]452                     'waeup.viewDocuments', 'waeup.manageDocuments',
[7184]453                     'waeup.managePortalConfiguration', 'waeup.viewApplication',
454                     'waeup.manageApplication', 'waeup.handleApplication',
[7250]455                     'waeup.viewApplicantsTab', 'waeup.payApplicant',
[8565]456                     'waeup.viewApplicationStatistics',
[7250]457                     'waeup.viewStudent', 'waeup.manageStudent',
458                     'waeup.clearStudent', 'waeup.payStudent',
459                     'waeup.uploadStudentFile', 'waeup.showStudents',
[11862]460                     'waeup.clearAllStudents',
[10632]461                     'waeup.editScores',
[9273]462                     'waeup.triggerTransition',
[12843]463                     'waeup.viewStudentsContainer',
[9186]464                     'waeup.handleAccommodation',
[7205]465                     'waeup.viewHostels', 'waeup.manageHostels',
[9335]466                     'waeup.editUser',
[9637]467                     'waeup.loginAsStudent',
468                     'waeup.manageReports',
[9645]469                     'waeup.manageJobs',
[7240]470                     )
[4789]471
[9259]472class CCOfficer(grok.Role):
[12843]473    """The role of the Computer Center Officer is basically a copy
[12835]474    of the the PortalManager role. Some 'dangerous' permissions are excluded
475    by commenting them out (see source code). If officers need to gain more
476    access rights than defined in this role, do not hastily switch to the
[12843]477    PortalManager role but add further manager roles instead. Additional
[12835]478    roles could be: UsersManager, ACManager, ImportManager, WorkflowManager
479    or StudentImpersonator.
[12843]480
[12844]481    CCOfficer is a base class which means that this role is subject to
482    customization. It is not used in the ``waeup.kofa`` base package.
[9259]483    """
[10346]484    grok.baseclass()
[9259]485    grok.name('waeup.CCOfficer')
486    grok.title(u'Computer Center Officer')
487    grok.permissions(#'waeup.managePortal',
488                     #'waeup.manageUsers',
489                     'waeup.viewAcademics', 'waeup.manageAcademics',
490                     #'waeup.manageACBatches',
491                     'waeup.manageDataCenter',
492                     #'waeup.importData',
[10243]493                     'waeup.exportData',
[10278]494                     'waeup.viewTranscript',
[12440]495                     'waeup.viewDocuments', 'waeup.manageDocuments',
[9259]496                     'waeup.managePortalConfiguration', 'waeup.viewApplication',
497                     'waeup.manageApplication', 'waeup.handleApplication',
498                     'waeup.viewApplicantsTab', 'waeup.payApplicant',
499                     'waeup.viewApplicationStatistics',
500                     'waeup.viewStudent', 'waeup.manageStudent',
501                     'waeup.clearStudent', 'waeup.payStudent',
502                     'waeup.uploadStudentFile', 'waeup.showStudents',
[11862]503                     'waeup.clearAllStudents',
[10632]504                     'waeup.editScores',
[9273]505                     #'waeup.triggerTransition',
[12843]506                     'waeup.viewStudentsContainer',
[9259]507                     'waeup.handleAccommodation',
508                     'waeup.viewHostels', 'waeup.manageHostels',
[9335]509                     #'waeup.editUser',
[9637]510                     #'waeup.loginAsStudent',
511                     'waeup.manageReports',
[9645]512                     #'waeup.manageJobs',
[9259]513                     )
514
[7186]515def get_all_roles():
[6157]516    """Return a list of tuples ``<ROLE-NAME>, <ROLE>``.
517    """
518    return getUtilitiesFor(IRole)
519
[7186]520def get_waeup_roles(also_local=False):
[7819]521    """Get all Kofa roles.
[6157]522
[7819]523    Kofa roles are ordinary roles whose id by convention starts with
[6157]524    a ``waeup.`` prefix.
525
526    If `also_local` is ``True`` (``False`` by default), also local
[7819]527    roles are returned. Local Kofa roles are such whose id starts
[6157]528    with ``waeup.local.`` prefix (this is also a convention).
529
530    Returns a generator of the found roles.
531    """
[7186]532    for name, item in get_all_roles():
[6157]533        if not name.startswith('waeup.'):
[7819]534            # Ignore non-Kofa roles...
[4789]535            continue
[6157]536        if not also_local and name.startswith('waeup.local.'):
537            # Ignore local roles...
[6045]538            continue
[6157]539        yield item
[4789]540
[7186]541def get_waeup_role_names():
[7819]542    """Get the ids of all Kofa roles.
[6157]543
[7819]544    See :func:`get_waeup_roles` for what a 'KofaRole' is.
[6157]545
[7819]546    This function returns a sorted list of Kofa role names.
[6157]547    """
[7186]548    return sorted([x.id for x in get_waeup_roles()])
[6157]549
[6144]550class LocalRolesAssignable(grok.Adapter):
551    """Default implementation for `ILocalRolesAssignable`.
552
553    This adapter returns a list for dictionaries for objects for which
554    we want to know the roles assignable to them locally.
555
556    The returned dicts contain a ``name`` and a ``title`` entry which
557    give a role (``name``) and a description, for which kind of users
558    the permission is meant to be used (``title``).
559
560    Having this adapter registered we make sure, that for each normal
561    object we get a valid `ILocalRolesAssignable` adapter.
562
563    Objects that want to offer certain local roles, can do so by
[6162]564    setting a (preferably class-) attribute to a list of role ids.
[6144]565
566    You can also define different adapters for different contexts to
567    have different role lookup mechanisms become available. But in
568    normal cases it should be sufficient to use this basic adapter.
569    """
570    grok.context(Interface)
571    grok.provides(ILocalRolesAssignable)
572
573    _roles = []
574
575    def __init__(self, context):
576        self.context = context
[6162]577        role_ids = getattr(context, 'local_roles', self._roles)
[7186]578        self._roles = [(name, role) for name, role in get_all_roles()
[6162]579                       if name in role_ids]
[6144]580        return
581
582    def __call__(self):
583        """Get a list of dictionaries containing ``names`` (the roles to
584        assign) and ``titles`` (some description of the type of user
585        to assign each role to).
586        """
[7334]587        list_of_dict = [dict(
[6162]588                name=name,
589                title=role.title,
[6163]590                description=role.description)
[7334]591                for name, role in self._roles]
592        return sorted(list_of_dict, key=lambda x: x['name'])
[6144]593
[8774]594def get_all_users():
595    """Get a list of dictionaries.
596    """
597    users = sorted(grok.getSite()['users'].items(), key=lambda x: x[1].title)
598    for key, val in users:
599        yield(dict(name=key, val=val))
600
[6163]601def get_users_with_local_roles(context):
602    """Get a list of dicts representing the local roles set for `context`.
603
604    Each dict returns `user_name`, `user_title`, `local_role`,
605    `local_role_title`, and `setting` for each entry in the local
606    roles map of the `context` object.
607    """
[6202]608    try:
609        role_map = IPrincipalRoleMap(context)
610    except TypeError:
611        # no map no roles.
612        raise StopIteration
[6163]613    for local_role, user_name, setting in role_map.getPrincipalsAndRoles():
614        user = grok.getSite()['users'].get(user_name,None)
[7213]615        user_title = getattr(user, 'title', user_name)
[10227]616        local_role_title = getattr(
617            dict(get_all_roles()).get(local_role, None), 'title', None)
[6163]618        yield dict(user_name = user_name,
619                   user_title = user_title,
620                   local_role = local_role,
621                   local_role_title = local_role_title,
[9309]622                   setting = setting)
623
624def get_users_with_role(role, context):
625    """Get a list of dicts representing the usres who have been granted
626    a role for `context`.
627    """
628    try:
629        role_map = IPrincipalRoleMap(context)
630    except TypeError:
631        # no map no roles.
632        raise StopIteration
633    for user_name, setting in role_map.getPrincipalsForRole(role):
634        user = grok.getSite()['users'].get(user_name,None)
635        user_title = getattr(user, 'title', user_name)
636        user_email = getattr(user, 'email', None)
637        yield dict(user_name = user_name,
638                   user_title = user_title,
639                   user_email = user_email,
640                   setting = setting)
Note: See TracBrowser for help on using the repository browser.