Beispiel #1
0
def test_group_permissions(users, independent_action_object):
    user, creator = users
    object_id = independent_action_object.object_id
    group_id = groups.create_group("Example Group", "", creator.id).id

    assert object_permissions.get_object_permissions_for_users(object_id=object_id) == {
        creator.id: Permissions.GRANT
    }
    assert not object_permissions.object_is_public(object_id)
    assert object_permissions.get_user_object_permissions(object_id=object_id, user_id=user.id) == Permissions.NONE

    object_permissions.set_group_object_permissions(object_id=object_id, group_id=group_id, permissions=Permissions.WRITE)

    assert object_permissions.get_object_permissions_for_users(object_id=object_id) == {
        creator.id: Permissions.GRANT
    }
    assert not object_permissions.object_is_public(object_id)
    assert object_permissions.get_user_object_permissions(object_id=object_id, user_id=user.id) == Permissions.NONE

    groups.add_user_to_group(group_id=group_id, user_id=user.id)

    assert object_permissions.get_object_permissions_for_users(object_id=object_id) == {
        creator.id: Permissions.GRANT,
        user.id: Permissions.WRITE
    }
    assert not object_permissions.object_is_public(object_id)
    assert object_permissions.get_user_object_permissions(object_id=object_id, user_id=user.id) == Permissions.WRITE

    object_permissions.set_user_object_permissions(object_id=object_id, user_id=user.id, permissions=Permissions.READ)

    assert object_permissions.get_object_permissions_for_users(object_id=object_id) == {
        creator.id: Permissions.GRANT,
        user.id: Permissions.WRITE
    }
    assert not object_permissions.object_is_public(object_id)
    assert object_permissions.get_user_object_permissions(object_id=object_id, user_id=user.id) == Permissions.WRITE

    object_permissions.set_group_object_permissions(object_id=object_id, group_id=group_id, permissions=Permissions.READ)
    object_permissions.set_user_object_permissions(object_id=object_id, user_id=user.id, permissions=Permissions.WRITE)

    assert object_permissions.get_object_permissions_for_users(object_id=object_id) == {
        creator.id: Permissions.GRANT,
        user.id: Permissions.WRITE
    }
    assert not object_permissions.object_is_public(object_id)
    assert object_permissions.get_user_object_permissions(object_id=object_id, user_id=user.id) == Permissions.WRITE

    object_permissions.set_user_object_permissions(object_id=object_id, user_id=user.id, permissions=Permissions.READ)
    object_permissions.set_group_object_permissions(object_id=object_id, group_id=group_id, permissions=Permissions.GRANT)
    groups.remove_user_from_group(group_id=group_id, user_id=user.id)

    assert object_permissions.get_object_permissions_for_users(object_id=object_id) == {
        creator.id: Permissions.GRANT,
        user.id: Permissions.READ
    }
    assert not object_permissions.object_is_public(object_id)
    assert object_permissions.get_user_object_permissions(object_id=object_id, user_id=user.id) == Permissions.READ
def test_group_permissions(users, user_action):
    user, creator = users
    action_id = user_action.id
    group_id = groups.create_group("Example Group", "", creator.id).id

    assert action_permissions.get_action_permissions_for_users(action_id=action_id) == {
        creator.id: Permissions.GRANT
    }
    assert not action_permissions.action_is_public(action_id)
    assert action_permissions.get_user_action_permissions(action_id=action_id, user_id=user.id) == Permissions.NONE

    action_permissions.set_group_action_permissions(action_id=action_id, group_id=group_id, permissions=Permissions.WRITE)

    assert action_permissions.get_action_permissions_for_users(action_id=action_id) == {
        creator.id: Permissions.GRANT
    }
    assert not action_permissions.action_is_public(action_id)
    assert action_permissions.get_user_action_permissions(action_id=action_id, user_id=user.id) == Permissions.NONE

    groups.add_user_to_group(group_id=group_id, user_id=user.id)

    assert action_permissions.get_action_permissions_for_users(action_id=action_id) == {
        creator.id: Permissions.GRANT,
        user.id: Permissions.WRITE
    }
    assert not action_permissions.action_is_public(action_id)
    assert action_permissions.get_user_action_permissions(action_id=action_id, user_id=user.id) == Permissions.WRITE

    action_permissions.set_user_action_permissions(action_id=action_id, user_id=user.id, permissions=Permissions.READ)

    assert action_permissions.get_action_permissions_for_users(action_id=action_id) == {
        creator.id: Permissions.GRANT,
        user.id: Permissions.WRITE
    }
    assert not action_permissions.action_is_public(action_id)
    assert action_permissions.get_user_action_permissions(action_id=action_id, user_id=user.id) == Permissions.WRITE

    action_permissions.set_group_action_permissions(action_id=action_id, group_id=group_id, permissions=Permissions.READ)
    action_permissions.set_user_action_permissions(action_id=action_id, user_id=user.id, permissions=Permissions.WRITE)

    assert action_permissions.get_action_permissions_for_users(action_id=action_id) == {
        creator.id: Permissions.GRANT,
        user.id: Permissions.WRITE
    }
    assert not action_permissions.action_is_public(action_id)
    assert action_permissions.get_user_action_permissions(action_id=action_id, user_id=user.id) == Permissions.WRITE

    action_permissions.set_user_action_permissions(action_id=action_id, user_id=user.id, permissions=Permissions.READ)
    action_permissions.set_group_action_permissions(action_id=action_id, group_id=group_id, permissions=Permissions.GRANT)
    groups.remove_user_from_group(group_id=group_id, user_id=user.id)

    assert action_permissions.get_action_permissions_for_users(action_id=action_id) == {
        creator.id: Permissions.GRANT,
        user.id: Permissions.READ
    }
    assert not action_permissions.action_is_public(action_id)
    assert action_permissions.get_user_action_permissions(action_id=action_id, user_id=user.id) == Permissions.READ