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

Last change on this file since 14602 was 14602, checked in by uli, 8 years ago

Add permission role for fingerprint devices.

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