def test_share_repo_to_group(repo, group, permission): assert api.check_permission(repo.id, USER) == 'rw' assert api.check_permission(repo.id, USER2) is None repos = api.get_repos_by_group(group.id) assert len(repos) == 0 group_list = ccnet_api.get_groups(USER) assert len(group_list) == 1 group_list = ccnet_api.get_groups(USER2) assert len(group_list) == 0 api.group_share_repo(repo.id, group.id, USER, permission) repos = api.get_repos_by_group(group.id) assert_repo_with_permission(repo, repos, permission) ccnet_api.group_add_member(group.id, USER, USER2) group_list = ccnet_api.get_groups(USER2) assert len(group_list) == 1 group = group_list[0] assert group.id == group.id repos2 = api.get_repos_by_group(group.id) assert_repo_with_permission(repo, repos2, permission) assert api.check_permission(repo.id, USER2) == permission api.group_unshare_repo(repo.id, group.id, USER) repos = api.get_repos_by_group(group.id) assert len(repos) == 0 assert api.check_permission(repo.id, USER2) is None
def set_group_repo_permission(repo, group, permission_to_share, permission_to_set): ccnet_api.group_add_member(group.id, USER, USER2) assert api.check_permission(repo.id, USER2) == None api.set_group_repo(repo.id, group.id, USER, permission_to_share) assert api.check_permission(repo.id, USER2) == permission_to_share api.set_group_repo_permission(group.id, repo.id, permission_to_set) assert api.check_permission(repo.id, USER2) == permission_to_set api.group_unshare_repo(repo.id, group.id, USER)
def test_get_shared_users_by_repo(repo, group, permission): ccnet_api.group_add_member(group.id, USER, USER2) t_users = api.get_shared_users_by_repo(repo.id) assert len(t_users) == 0 api.share_repo(repo.id, USER, USER2, permission) api.set_group_repo(repo.id, group.id, ADMIN_USER, permission) t_users = api.get_shared_users_by_repo(repo.id) assert len(t_users) == 2 api.remove_share(repo.id, USER, USER2) api.group_unshare_repo(repo.id, group.id, USER)
def test_repo_perm_in_structure(repo, permission): id1 = ccnet_api.create_group('group1', USER, parent_group_id=-1) id2 = ccnet_api.create_group('group2', USER, parent_group_id=id1) assert id1 != -1 and id2 != -1 assert ccnet_api.group_add_member(id2, USER, USER2) != -1 assert api.group_share_repo(repo.id, id1, USER2, permission) != -1 assert api.check_permission(repo.id, USER2) == permission assert api.group_unshare_repo(repo.id, id1, USER2) != -1 assert api.check_permission(repo.id, USER2) == None assert ccnet_api.remove_group(id2) != -1 assert ccnet_api.remove_group(id1) != -1
def test_get_group_repos(repo, group): repo = api.get_repo(repo.id) api.group_share_repo(repo.id, group.id, USER, 'rw') repos = api.get_repos_by_group(group.id) assert_group_repos_attr(repo, repos[0]) repos = api.get_group_repos_by_owner(USER) assert_group_repos_attr(repo, repos[0]) v_repo_id = api.share_subdir_to_group(repo.id, '/dir1', USER, group.id, 'rw') v_repo = api.get_repo(v_repo_id) v_repo_to_test = api.get_group_shared_repo_by_path(repo.id, '/dir1', group.id) assert_group_repos_attr(v_repo, v_repo_to_test) api.unshare_subdir_for_group(repo.id, '/dir1', USER, group.id) repos = api.get_group_repos_by_user(USER) assert_group_repos_attr(repo, repos[0]) assert api.group_unshare_repo(repo.id, group.id, USER) == 0
def test_share_repo_to_group(repo, group, permission): assert api.check_permission(repo.id, USER) == 'rw' assert api.check_permission(repo.id, USER2) is None repos = api.get_repos_by_group(group.id) assert len(repos) == 0 group_list = ccnet_api.get_groups(USER) assert len(group_list) == 1 group_list = ccnet_api.get_groups(USER2) assert len(group_list) == 0 api.group_share_repo(repo.id, group.id, USER, permission) repos = api.get_repos_by_group(group.id) assert_repo_with_permission(repo, repos, permission) group_ids = api.get_shared_group_ids_by_repo(repo.id) assert group_ids[0] == str(group.id) group_list = api.list_repo_shared_group_by_user(USER, repo.id) assert len(group_list) == 1 group_list = api.list_repo_shared_group_by_user(USER2, repo.id) assert len(group_list) == 0 repo_get = api.get_group_shared_repo_by_path(repo.id, None, group.id) assert repo_get and repo_get.repo_id == repo.id ccnet_api.group_add_member(group.id, USER, USER2) group_list = ccnet_api.get_groups(USER2) assert len(group_list) == 1 group = group_list[0] assert group.id == group.id repos2 = api.get_repos_by_group(group.id) assert_repo_with_permission(repo, repos2, permission) assert api.check_permission(repo.id, USER2) == permission repos = api.get_group_repos_by_user(USER) assert len(repos) == 1 repoids = api.get_group_repoids(group.id) assert len(repoids) == 1 repos = api.get_group_repos_by_owner(USER) assert len(repos) == 1 api.remove_group_repos_by_owner(group.id, USER) repos = api.get_group_repos_by_owner(USER) assert len(repos) == 0 api.set_group_repo(repo.id, group.id, USER, permission) repos = api.get_repos_by_group(group.id) assert len(repos) == 1 api.remove_group_repos(group.id) repos = api.get_repos_by_group(group.id) assert len(repos) == 0 api.group_unshare_repo(repo.id, group.id, USER) repos = api.get_repos_by_group(group.id) assert len(repos) == 0 assert api.check_permission(repo.id, USER2) is None