Changeset 7169 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 22 Nov 2011, 14:35:12 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/authentication.py
r7147 r7169 2 2 """ 3 3 import grok 4 from zope.event import notify 4 5 from zope.component import getUtility, getUtilitiesFor 6 from zope.interface import Interface 7 from zope.securitypolicy.interfaces import ( 8 IPrincipalRoleMap, IPrincipalRoleManager) 5 9 from zope.pluggableauth.plugins.session import SessionCredentialsPlugin 6 10 from zope.pluggableauth.interfaces import ( 7 11 ICredentialsPlugin, IAuthenticatorPlugin, IPrincipalInfo) 8 12 from zope.password.interfaces import IPasswordManager 9 from zope.securitypolicy.interfaces import IPrincipalRoleManager10 13 from zope.securitypolicy.principalrole import principalRoleManager 11 from waeup.sirp.interfaces import ( 14 from waeup.sirp.interfaces import (ILocalRoleSetEvent, 12 15 IUserAccount, IAuthPluginUtility, IPasswordValidator) 13 16 … … 184 187 return errors 185 188 189 class LocalRoleSetEvent(object): 190 191 grok.implements(ILocalRoleSetEvent) 192 193 def __init__(self, object, role_id, principal_id, granted=True): 194 self.object = object 195 self.role_id = role_id 196 self.principal_id = principal_id 197 self.granted = granted 198 186 199 @grok.subscribe(IUserAccount, grok.IObjectRemovedEvent) 187 200 def handle_account_removed(account, event): … … 199 212 role_manager.unsetRoleForPrincipal(role_id, principal) 200 213 return 214 215 @grok.subscribe(IUserAccount, grok.IObjectAddedEvent) 216 def handle_account_added(account, event): 217 """When an account is added, the local owner role and the global 218 PortalUser rolemust be set. 219 """ 220 # First we have to set the local owner role of the account object 221 role_manager = IPrincipalRoleManager(account) 222 role_manager.assignRoleToPrincipal( 223 'waeup.local.Owner', account.name) 224 # Then we have to notify the user account that the local role 225 # of the same object has changed 226 notify(LocalRoleSetEvent( 227 account, 'waeup.local.Owner', account.name, granted=True)) 228 return 229 230 @grok.subscribe(Interface, ILocalRoleSetEvent) 231 def handle_local_role_changed(obj, event): 232 site = grok.getSite() 233 if site is None: 234 return 235 users = site.get('users', None) 236 if users is None: 237 return 238 role_id = event.role_id 239 if event.principal_id not in users.keys(): 240 return 241 user = users[event.principal_id] 242 user.notifyLocalRoleChanged(event.object, event.role_id, event.granted) 243 return 244 245 @grok.subscribe(Interface, grok.IObjectRemovedEvent) 246 def handle_local_roles_on_obj_removed(obj, event): 247 try: 248 role_map = IPrincipalRoleMap(obj) 249 except TypeError: 250 # no map, no roles to remove 251 return 252 for local_role, user_name, setting in role_map.getPrincipalsAndRoles(): 253 notify(LocalRoleSetEvent( 254 obj, local_role, user_name, granted=False)) 255 return -
main/waeup.sirp/trunk/src/waeup/sirp/authentication.txt
r7163 r7169 71 71 because we do not neccessarily know where Alice lives: 72 72 73 >>> from waeup.sirp. usersimport LocalRoleSetEvent73 >>> from waeup.sirp.authentication import LocalRoleSetEvent 74 74 >>> from zope.event import notify 75 75 >>> notify(LocalRoleSetEvent(chalet, 'BigBoss', 'alice', -
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r7165 r7169 40 40 from waeup.sirp.university.catalog import search 41 41 from waeup.sirp.university.vocabularies import course_levels 42 from waeup.sirp. usersimport LocalRoleSetEvent42 from waeup.sirp.authentication import LocalRoleSetEvent 43 43 from waeup.sirp.widgets.restwidget import ReSTDisplayWidget 44 44 from waeup.sirp.authentication import get_principal_role_manager -
main/waeup.sirp/trunk/src/waeup/sirp/users.py
r7163 r7169 1 """User s (principals)for the WAeUP portal.1 """User container for the WAeUP portal. 2 2 """ 3 3 import grok 4 4 from zope.event import notify 5 from zope.interface import Interface6 from zope.securitypolicy.interfaces import (7 IPrincipalRoleMap, IPrincipalRoleManager)8 5 from waeup.sirp.authentication import Account 9 from waeup.sirp.interfaces import ( 10 IUserContainer, ILocalRoleSetEvent, IUserAccount) 6 from waeup.sirp.interfaces import IUserContainer 11 7 12 8 class UserContainer(grok.Container): … … 39 35 if name in self.keys(): 40 36 del self[name] 41 42 class LocalRoleSetEvent(object):43 44 grok.implements(ILocalRoleSetEvent)45 46 def __init__(self, object, role_id, principal_id, granted=True):47 self.object = object48 self.role_id = role_id49 self.principal_id = principal_id50 self.granted = granted51 52 @grok.subscribe(Interface, ILocalRoleSetEvent)53 def handle_local_role_changed(obj, event):54 site = grok.getSite()55 if site is None:56 return57 users = site.get('users', None)58 if users is None:59 return60 role_id = event.role_id61 if event.principal_id not in users.keys():62 return63 user = users[event.principal_id]64 user.notifyLocalRoleChanged(event.object, event.role_id, event.granted)65 return66 67 @grok.subscribe(Interface, grok.IObjectRemovedEvent)68 def handle_local_roles_on_obj_removed(obj, event):69 try:70 role_map = IPrincipalRoleMap(obj)71 except TypeError:72 # no map, no roles to remove73 return74 for local_role, user_name, setting in role_map.getPrincipalsAndRoles():75 notify(LocalRoleSetEvent(76 obj, local_role, user_name, granted=False))77 return78 79 @grok.subscribe(IUserAccount, grok.IObjectAddedEvent)80 def handle_user_added(account, event):81 """If an account is added the local owner role must be set.82 """83 # First we have to set the local owner role of the account object84 role_manager = IPrincipalRoleManager(account)85 role_manager.assignRoleToPrincipal(86 'waeup.local.Owner', account.name)87 # Then we have to notify the user account that the local role88 # of the same object has changed89 notify(LocalRoleSetEvent(90 account, 'waeup.local.Owner', account.name, granted=True))91 return -
main/waeup.sirp/trunk/src/waeup/sirp/users.txt
r5140 r7169 1 User for the WAeUP portal2 ************************* 1 User container for the WAeUP portal 2 *********************************** 3 3 4 4 .. :doctest: … … 10 10 ... PlacelessSetup) 11 11 >>> PlacelessSetup().setUp() 12 13 User Containers14 ===============15 12 16 13 We can create a user container which will hold the useraccounts for
Note: See TracChangeset for help on using the changeset viewer.