Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
borg.localrole.factory_adapter.FactoryTempFolderProvider Class Reference

List of all members.

Public Member Functions

def __init__
def getRoles
def getAllRoles

Public Attributes


Detailed Description

A simple local role provider which just gathers the roles from
the desired context::

    >>> from import placelesssetup
    >>> placelesssetup.setUp()
    >>> from zope.component import provideAdapter
    >>> from zope.interface import Interface, implements, directlyProvides
    >>> from borg.localrole.workspace import WorkspaceLocalRoleManager
    >>> rm = WorkspaceLocalRoleManager('rm', 'A Role Manager')

    >>> from Acquisition import Implicit
    >>> class DummyObject(Implicit):
    ...     implements(Interface)
    >>> root = DummyObject()

Let's construct a hierarchy similar to the way portal factory is used::

    root --> folder -------|
      |------------> PortalFactory --> TempFolder --> NewObject 

    >>> fold = DummyObject().__of__(root)
    >>> factory = DummyObject().__of__(root)
    >>> wrapped_factory = factory.__of__(fold)
    >>> temp = DummyObject().__of__(wrapped_factory)
    >>> newob = DummyObject().__of__(temp)

    >>> from borg.localrole.tests import SimpleLocalRoleProvider
    >>> from borg.localrole.tests import DummyUser
    >>> user1 = DummyUser('bogus_user1')

To test our adapter we need an acl_users, and our user needs a
getRolesInContext method::

    >>> class FakeUF(object):
    ...     def getUserById(self, userid, default=None):
    ...         if userid == user1.getId():
    ...             return user1
    ...         return None
    >>> root.acl_users = FakeUF()

    >>> def getRolesInContext(user, context):
    ...     return rm.getRolesInContext(user, context)
    >>> from new import instancemethod
    >>> user1.getRolesInContext = instancemethod(getRolesInContext, user1,
    ...                                          DummyUser)

We add special interface to our Folder which allows us to provide
some local roles, these roles will be inherited by any contained
objects but not by our 'newob' because though the folder is its
acquisition chain it is not contained by it::

    >>> class ISpecialInterface(Interface):
    ...     pass
    >>> directlyProvides(fold, ISpecialInterface)
    >>> provideAdapter(SimpleLocalRoleProvider, adapts=(ISpecialInterface,))
    >>> rm.getRolesInContext(user1, fold)
    >>> contained = DummyObject().__of__(fold)
    >>> rm.getRolesInContext(user1, contained)
    >>> rm.getRolesInContext(user1, newob)

Now we mark our TempFolder, and check that roles are now inherited
from the intended location ('fold')::

    >>> directlyProvides(temp, IFactoryTempFolder)
    >>> provideAdapter(FactoryTempFolderProvider)
    >>> rm.getRolesInContext(user1, newob)

The getAllRoles method always returns an empty dict, becuas it is
only used for thing which are irrelevant for temporary objects::

    >>> rm.getAllLocalRolesInContext(newob)

    >>> placelesssetup.tearDown()

Definition at line 8 of file

Constructor & Destructor Documentation

Definition at line 96 of file

00097     def __init__(self, obj):
00098         self.folder = obj

Here is the caller graph for this function:

Member Function Documentation

Definition at line 109 of file

00110     def getAllRoles(self):
00111         # This should not be used in any meaningful way, so we'll make it cheap
00112         return {}

Definition at line 99 of file

00100     def getRoles(self, principal_id):
00101         uf = aq_inner(getToolByName(self.folder, 'acl_users'))
00102         user = aq_inner(uf.getUserById(principal_id, default=None))
00103         # use the folder we are creating in as role generating context
00104         source = aq_parent(aq_parent(self.folder))
00105         if user is not None:
00106             return user.getRolesInContext(source)
00107         else:
00108             return []

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Definition at line 97 of file

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