Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
borg.localrole.default_adapter.DefaultLocalRoleAdapter Class Reference

List of all members.

Public Member Functions

def __init__
def getRoles
def getAllRoles

Public Attributes

 context

Private Member Functions

def _rolemap

Detailed Description

Looks at __ac_local_roles__ to find local roles stored
persistently on an object::

    >>> class Dummy(object):
    ...     pass
    >>> obj = Dummy()
    >>> roles = DefaultLocalRoleAdapter(obj)


Let's make sure the behavior is sane for objects with no local
role awareness::

    >>> roles.getRoles('dummy')
    []
    >>> tuple(roles.getAllRoles())
    ()

Same goes if the RoleManager role map is set to None::

    >>> obj.__ac_local_roles__ = None
    >>> roles.getRoles('dummy')
    []
    >>> tuple(roles.getAllRoles())
    ()

And if we have some roles assigned, we get the expected behavior::

    >>> obj.__ac_local_roles__ = {'dummy': ['Role1', 'Role2']}
    >>> roles.getRoles('dummy')
    ['Role1', 'Role2']
    >>> roles.getRoles('dummy2')
    []
    >>> tuple(roles.getAllRoles())
    (('dummy', ['Role1', 'Role2']),)

The __ac__local_roles__ attribute may be a callable::

    >>> obj.__ac_local_roles__ = lambda: {'dummy2': ['Role1']}
    >>> roles.getRoles('dummy')
    []
    >>> roles.getRoles('dummy2')
    ['Role1']
    >>> tuple(roles.getAllRoles())
    (('dummy2', ['Role1']),)

Definition at line 6 of file default_adapter.py.


Constructor & Destructor Documentation

Definition at line 56 of file default_adapter.py.

00056 
00057     def __init__(self, context):
00058         self.context = context

Here is the caller graph for this function:


Member Function Documentation

Definition at line 60 of file default_adapter.py.

00060 
00061     def _rolemap(self):
00062         rolemap = getattr(self.context, '__ac_local_roles__', {})
00063         # None is the default value from AccessControl.Role.RoleMananger
00064         if rolemap is None:
00065             return {}
00066         if callable(rolemap):
00067             rolemap = rolemap()
00068         return rolemap

Returns all the local roles assigned in this context:
(principal_id, [role1, role2])

Definition at line 73 of file default_adapter.py.

00073 
00074     def getAllRoles(self):
00075         """Returns all the local roles assigned in this context:
00076         (principal_id, [role1, role2])"""
00077         return self._rolemap.iteritems()
Returns the roles for the given principal in context

Definition at line 69 of file default_adapter.py.

00069 
00070     def getRoles(self, principal_id):
00071         """Returns the roles for the given principal in context"""
00072         return self._rolemap.get(principal_id, [])

Here is the caller graph for this function:


Member Data Documentation

Definition at line 57 of file default_adapter.py.


The documentation for this class was generated from the following file: