Changeset 7177 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 23 Nov 2011, 09:18:19 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/authentication.py
r7173 r7177 76 76 self.description = description 77 77 self.setPassword(password) 78 self.setRoles(roles)78 #self.setSiteRolesForPrincipal(roles) 79 79 # We don't want to share this dict with other accounts 80 80 self._local_roles = dict() … … 88 88 return passwordmanager.checkPassword(self.password, password) 89 89 90 def get Roles(self):90 def getSiteRolesForPrincipal(self): 91 91 prm = get_principal_role_manager() 92 92 roles = [x[0] for x in prm.getRolesForPrincipal(self.name) … … 94 94 return roles 95 95 96 def set Roles(self, roles):96 def setSiteRolesForPrincipal(self, roles): 97 97 prm = get_principal_role_manager() 98 99 old_roles = self.getRoles() 98 old_roles = self.getSiteRolesForPrincipal() 100 99 for role in old_roles: 101 100 # Remove old roles, not to be set now... 102 101 if role.startswith('waeup.') and role not in roles: 103 102 prm.unsetRoleForPrincipal(role, self.name) 104 105 103 for role in roles: 106 104 prm.assignRoleToPrincipal(role, self.name) 107 105 108 roles = property(get Roles, setRoles)106 roles = property(getSiteRolesForPrincipal, setSiteRolesForPrincipal) 109 107 110 108 def getLocalRoles(self): -
main/waeup.sirp/trunk/src/waeup/sirp/authentication.txt
r7173 r7177 53 53 Users have also got the global PortalUser role: 54 54 55 >>> alice.get Roles()55 >>> alice.getSiteRolesForPrincipal() 56 56 ['waeup.PortalUser'] 57 57 -
main/waeup.sirp/trunk/src/waeup/sirp/browser/layout.py
r7176 r7177 16 16 from waeup.sirp.students.interfaces import IStudentNavigation 17 17 from waeup.sirp.authentication import get_principal_role_manager 18 from waeup.sirp.permissions import getRoles19 18 20 19 grok.templatedir('templates') -
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r7176 r7177 37 37 ISessionConfiguration, ISessionConfigurationAdd, academic_sessions_vocab, 38 38 IPasswordValidator) 39 from waeup.sirp.permissions import ( 40 get_users_with_local_roles, 41 getGlobalRolesForAccount, getLocalRolesForAccount) 39 from waeup.sirp.permissions import get_users_with_local_roles, getAllRoles 42 40 from waeup.sirp.university.catalog import search 43 41 from waeup.sirp.university.vocabularies import course_levels … … 263 261 264 262 def getLocalRoles(self, account): 265 return getLocalRolesForAccount(self, account) 263 local_roles = account.getLocalRoles() 264 local_roles_string = '' 265 site_url = self.url(grok.getSite()) 266 for local_role in local_roles.keys(): 267 role_title = dict(getAllRoles())[local_role].title 268 objects_string = '' 269 for object in local_roles[local_role]: 270 objects_string += '<a href="%s">%s</a>, ' %(self.url(object), 271 self.url(object).replace(site_url,'')) 272 local_roles_string += '%s: <br />%s <br />' %(role_title, 273 objects_string.rstrip(', ')) 274 return local_roles_string 266 275 267 276 def getGlobalRoles(self, account): 268 return getGlobalRolesForAccount(account) 277 global_roles = account.roles 278 global_roles_string = '' 279 for global_role in global_roles: 280 role_title = dict(getAllRoles())[global_role].title 281 global_roles_string += '%s <br />' % role_title 282 return global_roles_string 269 283 270 284 class AddUserFormPage(WAeUPAddFormPage): -
main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py
r7172 r7177 86 86 def getTitle(self, value): 87 87 # late import: in interfaces we should not import local modules 88 from waeup.sirp.permissions import get Roles89 roles = dict(get Roles())88 from waeup.sirp.permissions import getAllRoles 89 roles = dict(getAllRoles()) 90 90 if value in roles.keys(): 91 91 title = roles[value].title -
main/waeup.sirp/trunk/src/waeup/sirp/permissions.py
r7176 r7177 85 85 'waeup.viewHostels', 'waeup.manageHostels') 86 86 87 def get Roles():87 def getAllRoles(): 88 88 """Return a list of tuples ``<ROLE-NAME>, <ROLE>``. 89 89 """ … … 102 102 Returns a generator of the found roles. 103 103 """ 104 for name, item in get Roles():104 for name, item in getAllRoles(): 105 105 if not name.startswith('waeup.'): 106 106 # Ignore non-WAeUP roles... … … 120 120 return sorted([x.id for x in getWAeUPRoles()]) 121 121 122 def getLocalRolesForAccount(view, account):123 """Return HTML tagged string with all local roles of a user account.124 """125 local_roles = account.getLocalRoles()126 local_roles_string = ''127 site_url = view.url(grok.getSite())128 for local_role in local_roles.keys():129 role_title = dict(getRoles())[local_role].title130 objects_string = ''131 for object in local_roles[local_role]:132 objects_string += '<a href="%s">%s</a>, ' %(view.url(object),133 view.url(object).replace(site_url,''))134 local_roles_string += '%s: <br />%s <br />' %(role_title,135 objects_string.rstrip(', '))136 return local_roles_string137 138 def getGlobalRolesForAccount(account):139 """Return HTML tagged string with all global roles of a user account.140 """141 global_roles = account.roles142 global_roles_string = ''143 for global_role in global_roles:144 role_title = dict(getRoles())[global_role].title145 global_roles_string += '%s <br />' % role_title146 return global_roles_string122 #def getLocalRolesForAccount(view, account): 123 # """Return HTML tagged string with all local roles of a user account. 124 # """ 125 # local_roles = account.getLocalRoles() 126 # local_roles_string = '' 127 # site_url = view.url(grok.getSite()) 128 # for local_role in local_roles.keys(): 129 # role_title = dict(getAllRoles())[local_role].title 130 # objects_string = '' 131 # for object in local_roles[local_role]: 132 # objects_string += '<a href="%s">%s</a>, ' %(view.url(object), 133 # view.url(object).replace(site_url,'')) 134 # local_roles_string += '%s: <br />%s <br />' %(role_title, 135 # objects_string.rstrip(', ')) 136 # return local_roles_string 137 138 #def getGlobalRolesForAccount(account): 139 # """Return HTML tagged string with all global roles of a user account. 140 # """ 141 # global_roles = account.roles 142 # global_roles_string = '' 143 # for global_role in global_roles: 144 # role_title = dict(getAllRoles())[global_role].title 145 # global_roles_string += '%s <br />' % role_title 146 # return global_roles_string 147 147 148 148 def getMyRoles(view): … … 183 183 self.context = context 184 184 role_ids = getattr(context, 'local_roles', self._roles) 185 self._roles = [(name, role) for name, role in get Roles()185 self._roles = [(name, role) for name, role in getAllRoles() 186 186 if name in role_ids] 187 187 return … … 214 214 user = grok.getSite()['users'].get(user_name,None) 215 215 user_title = getattr(user, 'description', user_name) 216 local_role_title = dict(get Roles())[local_role].title216 local_role_title = dict(getAllRoles())[local_role].title 217 217 yield dict(user_name = user_name, 218 218 user_title = user_title, -
main/waeup.sirp/trunk/src/waeup/sirp/permissions.txt
r7168 r7177 13 13 roles. 14 14 15 :func:`get Roles`16 ---------------- 15 :func:`getAllRoles` 16 ------------------- 17 17 18 18 Gives us all roles defined in a WAeUP SIRP portal. We get tuples of … … 24 24 with the ZCA (a string) and ``<ROLE>`` is the real role object. 25 25 26 >>> from waeup.sirp.permissions import get Roles27 >>> get Roles()26 >>> from waeup.sirp.permissions import getAllRoles 27 >>> getAllRoles() 28 28 <generator object...at 0x...> 29 29 30 >>> sorted(list(get Roles()))30 >>> sorted(list(getAllRoles())) 31 31 [(u'waeup.AccommodationOfficer', <waeup.sirp.hostels.permissions.AccommodationOfficer object at 0x...] 32 32
Note: See TracChangeset for help on using the changeset viewer.