def list_inner_pub_repos(username, org_id, is_guest): if is_guest: return [] if org_id: return seafile_api.list_org_inner_pub_repos(org_id) return seafile_api.get_inner_pub_repo_list()
def test_get_inner_pub_repos(repo): repo = api.get_repo(repo.id) api.add_inner_pub_repo(repo.id, 'rw') repos = api.get_inner_pub_repo_list() assert_public_repos_attr(repo, repos[0]) repos = api.list_inner_pub_repos_by_owner(USER) assert_public_repos_attr(repo, repos[0]) assert api.remove_inner_pub_repo(repo.id) == 0
def list_inner_pub_repos(request): """List inner pub repos. """ username = request.user.username if is_org_context(request): org_id = request.user.org.org_id return seafile_api.list_org_inner_pub_repos(org_id) if not request.cloud_mode: return seafile_api.get_inner_pub_repo_list() return []
def get_user_repos(username, org_id=None): """ Get all repos that user can access, including owns, shared, public, and repo in groups. If ``org_id`` is not None, get org repos that user can access. """ if org_id is None: owned_repos = seafile_api.get_owned_repo_list(username) shared_repos = seafile_api.get_share_in_repo_list(username, -1, -1) groups_repos = seafile_api.get_group_repos_by_user(username) if CLOUD_MODE: public_repos = [] else: public_repos = seafile_api.get_inner_pub_repo_list() for r in shared_repos + public_repos: # collumn names in shared_repo struct are not same as owned or group # repos. r.id = r.repo_id r.name = r.repo_name r.last_modify = r.last_modified else: owned_repos = seafile_api.get_org_owned_repo_list(org_id, username) shared_repos = seafile_api.get_org_share_in_repo_list(org_id, username, -1, -1) groups_repos = seafile_api.get_org_group_repos_by_user(username, org_id) public_repos = seaserv.seafserv_threaded_rpc.list_org_inner_pub_repos(org_id) for r in shared_repos + groups_repos + public_repos: # collumn names in shared_repo struct are not same as owned # repos. r.id = r.repo_id r.name = r.repo_name r.last_modify = r.last_modified return (owned_repos, shared_repos, groups_repos, public_repos)
def delete(self, request, repo_id, format=None): """ Unshare a repo. Permission checking: 1. Only repo owner and system admin can unshare a publib library. """ # argument check share_type = request.GET.get('share_type', None) if not share_type: error_msg = 'share_type invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) if share_type not in ('personal', 'group', 'public'): error_msg = "share_type can only be 'personal' or 'group' or 'public'." return api_error(status.HTTP_400_BAD_REQUEST, error_msg) # resource check repo = seafile_api.get_repo(repo_id) if not repo: return api_error(status.HTTP_404_NOT_FOUND, 'Library %s not found.' % repo_id) # permission check username = request.user.username if is_org_context(request): repo_owner = seafile_api.get_org_repo_owner(repo_id) else: repo_owner = seafile_api.get_repo_owner(repo_id) if not request.user.is_staff and not username == repo_owner: error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) # delete share org_id = None is_org = False if is_org_context(request): org_id = request.user.org.org_id is_org = True if share_type == 'personal': user = request.GET.get('user', None) if not user or not is_valid_username(user): error_msg = 'user invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) permission = check_user_share_out_permission( repo_id, '/', user, is_org) try: if org_id: seafile_api.org_remove_share(org_id, repo_id, username, user) else: seafile_api.remove_share(repo_id, username, user) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) send_perm_audit_msg('delete-repo-perm', username, user, repo_id, '/', permission) if share_type == 'group': group_id = request.GET.get('group_id', None) if not group_id: error_msg = 'group_id invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) try: group_id = int(group_id) except ValueError: error_msg = 'group_id must be integer.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) permission = check_group_share_out_permission( repo_id, '/', group_id, is_org) try: if is_org: seaserv.del_org_group_repo(repo_id, org_id, group_id) else: seafile_api.unset_group_repo(repo_id, group_id, username) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) send_perm_audit_msg('delete-repo-perm', username, group_id, repo_id, '/', permission) if share_type == 'public': pub_repos = [] if org_id: pub_repos = seafile_api.list_org_inner_pub_repos(org_id) if not request.cloud_mode: pub_repos = seafile_api.get_inner_pub_repo_list() try: if org_id: seaserv.seafserv_threaded_rpc.unset_org_inner_pub_repo( org_id, repo_id) else: seafile_api.remove_inner_pub_repo(repo_id) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) permission = '' for repo in pub_repos: if repo.repo_id == repo_id: permission = repo.permission break if permission: send_perm_audit_msg('delete-repo-perm', username, 'all', repo_id, '/', permission) return Response({'success': True})