Beispiel #1
0
    def has_permission(cls, rid, resource_name, resource_type, app_id, perm):
        resource_type = ResourceType.get_by(app_id=app_id,
                                            name=resource_type,
                                            first=True,
                                            to_dict=False)
        resource_type or abort(
            404, "ResourceType <{0}> is not found".format(resource_type))
        type_id = resource_type.id
        resource = Resource.get_by(name=resource_name,
                                   resource_type_id=type_id,
                                   first=True,
                                   to_dict=False)
        resource = resource or abort(
            403, "Resource <{0}> is not in ACL".format(resource_name))

        parent_ids = RoleRelationCRUD.recursive_parent_ids(rid)

        group_ids = cls.get_group_ids(resource.id)
        for parent_id in parent_ids:
            id2perms = RoleRelationCache.get_resources(parent_id)
            perms = id2perms['id2perms'].get(resource.id, [])
            if perms and {perm}.issubset(set(perms)):
                return True

            for group_id in group_ids:
                perms = id2perms['group2perms'].get(group_id, [])
                if perms and {perm}.issubset(set(perms)):
                    return True

        return False
Beispiel #2
0
    def get_permissions(cls, rid, resource_name):
        resource = Resource.get_by(name=resource_name,
                                   first=True,
                                   to_dict=False)
        resource = resource or abort(
            403, "Resource <{0}> is not in ACL".format(resource_name))

        parent_ids = RoleRelationCRUD.recursive_parent_ids(rid)
        group_ids = cls.get_group_ids(resource.id)

        perms = []
        for parent_id in parent_ids:
            id2perms = RoleRelationCache.get_resources(parent_id)
            perms += id2perms['id2perms'].get(parent_id, [])

            for group_id in group_ids:
                perms += id2perms['group2perms'].get(group_id, [])

        return set(perms)