[7819] | 1 | Kofa permissions and roles |
---|
[7321] | 2 | ************************** |
---|
[4127] | 3 | |
---|
[7819] | 4 | Permissions and roles used in a Kofa portal. |
---|
[4127] | 5 | |
---|
[5140] | 6 | .. :doctest: |
---|
[7819] | 7 | .. :layer: waeup.kofa.testing.KofaUnitTestLayer |
---|
[4127] | 8 | |
---|
[6157] | 9 | Convenience functions |
---|
| 10 | ===================== |
---|
[4127] | 11 | |
---|
[7811] | 12 | :mod:`waeup.kofa` offers some convenience functions to handle security |
---|
[6157] | 13 | roles. |
---|
| 14 | |
---|
[7186] | 15 | :func:`get_all_roles` |
---|
| 16 | --------------------- |
---|
[6157] | 17 | |
---|
[7819] | 18 | Gives us all roles defined in Kofa. We get tuples of |
---|
[6157] | 19 | kind |
---|
| 20 | |
---|
| 21 | ``(<ROLE-NAME>, <ROLE>)`` |
---|
| 22 | |
---|
| 23 | where ``<ROLE-NAME>`` is the name under which a role was registered |
---|
| 24 | with the ZCA (a string) and ``<ROLE>`` is the real role object. |
---|
| 25 | |
---|
[7811] | 26 | >>> from waeup.kofa.permissions import get_all_roles |
---|
[7186] | 27 | >>> get_all_roles() |
---|
[6333] | 28 | <generator object...at 0x...> |
---|
[4127] | 29 | |
---|
[7186] | 30 | >>> sorted(list(get_all_roles())) |
---|
[7811] | 31 | [(u'waeup.ACManager', <waeup.kofa.permissions.ACManager object at 0x...] |
---|
[6157] | 32 | |
---|
[7186] | 33 | :func:`get_waeup_roles` |
---|
| 34 | ----------------------- |
---|
[6157] | 35 | |
---|
[7819] | 36 | Gives us all roles, except the Kofa specific roles. We can get a list |
---|
[6157] | 37 | with or without local roles: |
---|
| 38 | |
---|
[7811] | 39 | >>> from waeup.kofa.permissions import get_waeup_roles |
---|
[7186] | 40 | >>> len(list(get_waeup_roles())) |
---|
[8367] | 41 | 15 |
---|
[6157] | 42 | |
---|
[7186] | 43 | >>> len(list(get_waeup_roles(also_local=True))) |
---|
[9211] | 44 | 26 |
---|
[6157] | 45 | |
---|
| 46 | |
---|
[7186] | 47 | :func:`get_waeup_role_names` |
---|
| 48 | ---------------------------- |
---|
[6157] | 49 | |
---|
[7819] | 50 | We can get all role names defined in Kofa (except 'local' |
---|
[6157] | 51 | roles that are meant not to be assigned globally): |
---|
| 52 | |
---|
[7811] | 53 | >>> from waeup.kofa.permissions import get_waeup_role_names |
---|
[7186] | 54 | >>> list(get_waeup_role_names()) |
---|
[7334] | 55 | [u'waeup.ACManager', |
---|
[8367] | 56 | u'waeup.AcademicsManager', |
---|
[7334] | 57 | u'waeup.AcademicsOfficer', |
---|
| 58 | u'waeup.AccommodationOfficer', |
---|
| 59 | u'waeup.Applicant', |
---|
[7168] | 60 | u'waeup.ApplicationsOfficer', |
---|
[8367] | 61 | u'waeup.DataCenterManager', |
---|
| 62 | u'waeup.ImportManager', |
---|
[7334] | 63 | u'waeup.PortalManager', |
---|
| 64 | u'waeup.Student', |
---|
| 65 | u'waeup.StudentsClearanceOfficer', |
---|
| 66 | u'waeup.StudentsCourseAdviser', |
---|
| 67 | u'waeup.StudentsManager', |
---|
[8367] | 68 | u'waeup.StudentsOfficer', |
---|
| 69 | u'waeup.UsersManager'] |
---|
[6202] | 70 | |
---|
| 71 | :func:`get_users_with_local_roles` |
---|
| 72 | ---------------------------------- |
---|
| 73 | |
---|
| 74 | We can get all users and their roles for a certain context |
---|
| 75 | object. This even works for objects that cannot have local roles as |
---|
| 76 | they are not stored in the ZODB: |
---|
| 77 | |
---|
[7811] | 78 | >>> from waeup.kofa.permissions import get_users_with_local_roles |
---|
[6202] | 79 | >>> mycontext = object() |
---|
| 80 | >>> people_and_roles = get_users_with_local_roles(mycontext) |
---|
| 81 | >>> people_and_roles |
---|
[6333] | 82 | <generator object...at 0x...> |
---|
[6202] | 83 | |
---|
| 84 | In this case, the result is empty: |
---|
| 85 | |
---|
| 86 | >>> people_and_roles = list(people_and_roles) |
---|
| 87 | >>> people_and_roles |
---|
| 88 | [] |
---|