Exemplo n.º 1
0
def getRoles(container, name, value, default):

    global rolesForPermissionOn  # XXX:  avoid import loop

    if rolesForPermissionOn is None:
        from PermissionRole import rolesForPermissionOn

    roles = getattr(value, '__roles__', _noroles)
    if roles is _noroles:
        if not name or not isinstance(name, basestring):
            return default

        if type(value) is MethodType:
            container = value.im_self

        cls = getattr(container, '__class__', None)
        if cls is None:
            return default

        roles = getattr(cls, name + '__roles__', _noroles)
        if roles is _noroles:
            return default

        value = container

    if roles is None or isinstance(roles, tuple_or_list):
        return roles

    rolesForPermissionOn = getattr(roles, 'rolesForPermissionOn', None)
    if rolesForPermissionOn is not None:
        roles = rolesForPermissionOn(value)

    return roles
Exemplo n.º 2
0
def getRoles(container, name, value, default):

    global rolesForPermissionOn  # XXX:  avoid import loop

    if rolesForPermissionOn is None:
        from PermissionRole import rolesForPermissionOn

    roles = getattr(value, '__roles__', _noroles)
    if roles is _noroles:
        if not name or not isinstance(name, basestring):
            return default

        if type(value) is MethodType:
            container = value.im_self

        cls = getattr(container, '__class__', None)
        if cls is None:
            return default
        
        roles = getattr(cls, name+'__roles__', _noroles)
        if roles is _noroles:
            return default

        value = container

    if roles is None or isinstance(roles, tuple_or_list):
        return roles
    
    rolesForPermissionOn = getattr(roles, 'rolesForPermissionOn', None)
    if rolesForPermissionOn is not None:
        roles = rolesForPermissionOn(value)

    return roles
Exemplo n.º 3
0
 def has_permission(self, permission, object):
     """Check to see if a user has a given permission on an object."""
     roles=rolesForPermissionOn(permission, object)
     if isinstance(roles, str):
         roles=[roles]
     return self.allowed(object, roles)
Exemplo n.º 4
0
 def has_permission(self, permission, object):
     """Check to see if a user has a given permission on an object."""
     roles=rolesForPermissionOn(permission, object)
     if isinstance(roles, str):
         roles=[roles]
     return self.allowed(object, roles)
 def checkPermission(self, permission, object, context):
     # XXX proxy roles and executable owner are not checked
     roles=rolesForPermissionOn(permission, object)
     if type(roles) is StringType:
         roles=[roles]
     return context.user.allowed(object, roles)