コード例 #1
0
ファイル: utils.py プロジェクト: sunbit/guillotina
def get_roles_with_access_content(obj, request=None):
    """ Return the roles that has access to the content that are global roles"""
    if obj is None:
        return []
    roles = cached_roles(obj, "guillotina.AccessContent", "o")
    result = []
    all_roles = role.global_roles() + role.local_roles()
    for r in roles.keys():
        if r in all_roles:
            result.append(r)
    return result
コード例 #2
0
ファイル: utils.py プロジェクト: sunbit/guillotina
def get_principals_with_access_content(obj, request=None):
    if obj is None:
        return []
    roles = cached_roles(obj, "guillotina.AccessContent", "o")
    result = []
    all_roles = role.global_roles() + role.local_roles()
    for r in roles.keys():
        if r in all_roles:
            result.append(r)
    users = cached_principals(obj, result, "guillotina.AccessContent", "o")
    return list(users.keys())
コード例 #3
0
async def test_cached_access_roles(dummy_guillotina):
    db = get_db(dummy_guillotina, "db")
    tm = db.get_transaction_manager()
    utils.login()
    async with tm.transaction():
        root_ob = await tm.get_root()
        container = await create_container(root_ob, "test-container")
        folder = await create_content_in_container(container, "Folder",
                                                   "foobar-folder")
        item = await create_content_in_container(folder, "Item", "foobar")

        folder_manager = IRolePermissionManager(folder)
        folder_manager.grant_permission_to_role_no_inherit(
            "guillotina.AccessContent", "guillotina.ContainerCreator")

        roles = cached_roles(folder, "guillotina.AccessContent", "o")
        assert roles.get("guillotina.ContainerCreator") == 1

        roles = cached_roles(item, "guillotina.AccessContent", "o")
        assert roles.get("guillotina.ContainerCreator") is None

        roles = cached_roles(folder, "guillotina.AccessContent", "o")
        assert roles.get("guillotina.ContainerCreator") == 1
コード例 #4
0
async def test_cached_access_roles(dummy_guillotina):
    db = get_db(dummy_guillotina, 'db')
    tm = db.get_transaction_manager()
    utils.login()
    async with tm.transaction():
        root_ob = await tm.get_root()
        container = await create_container(root_ob, 'test-container')
        folder = await create_content_in_container(container, 'Folder',
                                                   'foobar-folder')
        item = await create_content_in_container(folder, 'Item', 'foobar')

        folder_manager = IRolePermissionManager(folder)
        folder_manager.grant_permission_to_role_no_inherit(
            'guillotina.AccessContent', 'guillotina.ContainerCreator')

        roles = cached_roles(folder, 'guillotina.AccessContent', 'o')
        assert roles.get('guillotina.ContainerCreator') == 1

        roles = cached_roles(item, 'guillotina.AccessContent', 'o')
        assert roles.get('guillotina.ContainerCreator') is None

        roles = cached_roles(folder, 'guillotina.AccessContent', 'o')
        assert roles.get('guillotina.ContainerCreator') == 1