[3521] | 1 | import grok |
---|
[4789] | 2 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[3521] | 3 | |
---|
[4789] | 4 | class Public(grok.Permission): |
---|
| 5 | """Everyone-can-do-this-permission. |
---|
| 6 | |
---|
| 7 | This permission is meant to be applied to objects/views/pages |
---|
| 8 | etc., that should be usable/readable by everyone. |
---|
| 9 | |
---|
| 10 | We need this to be able to tune default permissions more |
---|
| 11 | restrictive and open up some dedicated objects like the front |
---|
| 12 | page. |
---|
| 13 | """ |
---|
| 14 | grok.name('waeup.Public') |
---|
| 15 | |
---|
| 16 | class ViewPermission(grok.Permission): |
---|
| 17 | grok.name('waeup.View') |
---|
| 18 | |
---|
| 19 | class ManageUniversity(grok.Permission): |
---|
| 20 | grok.name('waeup.manageUniversity') |
---|
| 21 | |
---|
| 22 | class ManageUsers(grok.Permission): |
---|
| 23 | grok.name('waeup.manageUsers') |
---|
| 24 | |
---|
[3521] | 25 | class FacultyRead(grok.Permission): |
---|
| 26 | grok.name('waeup.facultyread') |
---|
[4789] | 27 | |
---|
| 28 | class PortalUser(grok.Role): |
---|
| 29 | grok.name('waeup.PortalUser') |
---|
| 30 | grok.permissions('waeup.facultyread', 'waeup.View', 'waeup.Public') |
---|
[3521] | 31 | |
---|
[4789] | 32 | class PortalManager(grok.Role): |
---|
| 33 | grok.name('waeup.PortalManager') |
---|
| 34 | grok.permissions('waeup.manageUniversity', 'waeup.manageUsers', |
---|
[5410] | 35 | 'waeup.View', 'waeup.Public','waeup.manageACBatches') |
---|
[4789] | 36 | |
---|
| 37 | def getRoles(): |
---|
| 38 | app = grok.getSite() |
---|
| 39 | app = None |
---|
| 40 | manager = None |
---|
| 41 | if app is not None: |
---|
| 42 | from zope.securitypolicy.interfaces import IRolePermissionManager |
---|
| 43 | manager = IRolePermissionManager(app, None) |
---|
| 44 | else: |
---|
| 45 | from zope.securitypolicy.rolepermission import ( |
---|
| 46 | rolePermissionManager as manager) |
---|
| 47 | role_permission_map = manager.getRolesAndPermissions() |
---|
| 48 | result = dict() |
---|
| 49 | for item in role_permission_map: |
---|
| 50 | if not item[1].startswith('waeup.'): |
---|
| 51 | # Ignore non-WAeUP roles... |
---|
| 52 | continue |
---|
| 53 | result[item[1]] = True |
---|
| 54 | return sorted(result.keys()) |
---|
| 55 | |
---|
| 56 | class RoleSource(BasicSourceFactory): |
---|
| 57 | def getValues(self): |
---|
| 58 | return getRoles() |
---|
| 59 | def getTitle(self, value): |
---|
| 60 | if isinstance(value, basestring): |
---|
| 61 | return value.split('.', 2)[1] |
---|