Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(10)  |  Call(8)  |  Derive(0)  |  Import(2)
calculates local roles for userid 

        def get_local_roles(userid, request=None,
                    context=None, get_cfg_storage=config.get_cfg_storage):
    """ calculates local roles for userid """
    if context is None:
        context = getattr(request, 'context', None)
        if context is None:
            context = getattr(request, 'root', None)

    roles = OrderedDict()

    if IOwnersAware.providedBy(context):
        if userid == context.__owner__:
            roles[Owner.id] = Allow

    for location in lineage(context):
        if ILocalRolesAware.providedBy(location):
            local_roles = location.__local_roles__
            if local_roles:
                user_props = getattr(ptah.resolve(userid), 'properties', dict())
                user_roles = []

                for r in local_roles.get(userid, ()):
                    if r not in user_roles:
                        user_roles.append(r)
                for grp in user_props.get('groups', ()):
                    for r in local_roles.get(grp, ()):
                        if r not in roles:
                            user_roles.append(r)

                for r in user_roles:
                    if r not in roles:
                        roles[r] = Allow

    data = []
    for r, val in roles.items():
        if val is Allow:
            data.append(r)

    registry = get_current_registry()
    for provider in get_cfg_storage(ID_ROLES_PROVIDER, registry).values():
        data.extend(provider(context, userid, registry))

    return data
        


src/p/t/ptah-0.8.0/ptah/__init__.py   ptah(Download)
from ptah.security import Role
from ptah.security import get_roles
from ptah.security import get_local_roles
from ptah.security import roles_provider
from ptah.interfaces import IOwnersAware

src/p/t/ptah-HEAD/ptah/__init__.py   ptah(Download)
from ptah.security import Role
from ptah.security import get_roles
from ptah.security import get_local_roles
from ptah.security import roles_provider
from ptah.interfaces import IOwnersAware

src/p/t/ptah-0.8.0/ptah/tests/test_security.py   ptah(Download)
        content = Content(iface=security.ILocalRolesAware)
 
        roles = security.get_local_roles('userid', context=content)
        self.assertIn('role1', roles)
        self.assertIn('role2', roles)
 
        content = Content()
        roles = security.get_local_roles('userid', context=content)
        self.assertIn('role1', roles)
        self.assertIn('role2', roles)
        content.__local_roles__['userid'] = ('role:test2',)
 
        lr = sorted(security.get_local_roles('userid', context=content))
 
        self.assertTrue(lr == ['role:test', 'role:test2'])
        content = Content()
 
        roles = security.get_local_roles('userid', context=content)
        self.assertIn('Role1', roles)
        self.assertIn('Role2', roles)

src/p/t/ptah-HEAD/ptah/tests/test_security.py   ptah(Download)
        content = Content(iface=security.ILocalRolesAware)
 
        roles = security.get_local_roles('userid', context=content)
        self.assertIn('role1', roles)
        self.assertIn('role2', roles)
 
        content = Content()
        roles = security.get_local_roles('userid', context=content)
        self.assertIn('role1', roles)
        self.assertIn('role2', roles)
        content.__local_roles__['userid'] = ('role:test2',)
 
        lr = sorted(security.get_local_roles('userid', context=content))
 
        self.assertTrue(lr == ['role:test', 'role:test2'])
        content = Content()
 
        roles = security.get_local_roles('userid', context=content)
        self.assertIn('Role1', roles)
        self.assertIn('Role2', roles)