Ignore:
Timestamp:
21 May 2011, 01:31:03 (13 years ago)
Author:
uli
Message:

Add local roles dicts for user accounts. That seems to
need pretty much machinery, but seems also to work. So,
why not?

We have a new event type, that should be fired when
a local role is set or unset somewhere.

We have also two new event subscribers, one listening
to the new event (and then updates the user account
local roles listings), and another one listening to
IObjectRemoved events.

The latter is the trick to keep the local role listings
in user accounts more or less up-to-date. Without it
these lists would grow and grow, not noticing that
the objects they refer to, have gone already.

We now must think about subscribing to other events.
What happens, when an object is moved or copied.
Will the local roles then be copied as well? And would
that fact be reflected in user accounts?

Beside this we have to find all places in sources
where local roles are set/unset and trigger the new
LocalRoleSetEvent? defined in users.py.

Samples for the whole new stuff are in authentication.txt.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/users.py

    r4920 r6180  
    22"""
    33import grok
     4from zope.event import notify
     5from zope.interface import Interface
     6from zope.securitypolicy.interfaces import IPrincipalRoleMap
    47from waeup.sirp.authentication import Account
    5 from waeup.sirp.interfaces import IUserContainer
     8from waeup.sirp.interfaces import IUserContainer, ILocalRoleSetEvent
    69
    710class UserContainer(grok.Container):
     
    2629        """
    2730        self[account.name] = account
    28        
     31
    2932    def delUser(self, name):
    3033        """Delete user, if an account with the given name exists.
     
    3437        if name in self.keys():
    3538            del self[name]
     39
     40class LocalRoleSetEvent(object):
     41
     42    grok.implements(ILocalRoleSetEvent)
     43
     44    def __init__(self, object, role_id, principal_id, granted=True):
     45        self.object = object
     46        self.role_id = role_id
     47        self.principal_id = principal_id
     48        self.granted = granted
     49
     50@grok.subscribe(Interface, ILocalRoleSetEvent)
     51def handle_local_role_changed(obj, event):
     52    site = grok.getSite()
     53    if site is None:
     54        return
     55    users = site['users']
     56    role_id = event.role_id
     57    if event.principal_id not in users.keys():
     58        return
     59    user = users[event.principal_id]
     60    user.notifyLocalRoleChanged(event.object, event.role_id, event.granted)
     61    return
     62
     63@grok.subscribe(Interface, grok.IObjectRemovedEvent)
     64def handle_local_roles_on_obj_removal(obj, event):
     65    role_map = IPrincipalRoleMap(obj)
     66    for local_role, user_name, setting in role_map.getPrincipalsAndRoles():
     67        notify(LocalRoleSetEvent(
     68                obj, local_role, user_name, granted=False))
     69    return
Note: See TracChangeset for help on using the changeset viewer.