def get_user_repos(user): """ Get all repos that user can access, including owns, shared, public, and repo in groups. NOTE: collumn names in shared_repo struct are not same as owned or group repos. """ email = user.username shared_repos = list_share_repos(email, 'to_email', -1, -1) if CLOUD_MODE: if user.org: org_id = user.org['org_id'] owned_repos = list_org_repos_by_owner(org_id, email) groups_repos = [] for group in get_org_groups_by_user(org_id, email): groups_repos += get_org_group_repos(org_id, group.id, email) public_repos = list_org_inner_pub_repos(org_id, email, -1, -1) else: owned_repos = list_personal_repos_by_owner(email) groups_repos = [] for group in get_personal_groups_by_user(email): groups_repos += get_group_repos(group.id, email) public_repos = [] else: owned_repos = list_personal_repos_by_owner(email) groups_repos = [] for group in get_personal_groups_by_user(email): groups_repos += get_group_repos(group.id, email) public_repos = list_inner_pub_repos(email) return (owned_repos, shared_repos, groups_repos, public_repos)
def get(self, request, format=None): username = request.user.username shared_repos = [] shared_repos += list_share_repos(username, 'from_email', -1, -1) shared_repos += get_group_repos_by_owner(username) if not CLOUD_MODE: shared_repos += list_inner_pub_repos_by_owner(username) return HttpResponse(json.dumps(shared_repos, cls=SearpcObjEncoder), status=200, content_type=json_content_type)
def share_admin(request): """ List personal shared repos and shared links. """ username = request.user.username shared_repos = [] # personal repos shared by this user shared_repos += list_share_repos(username, 'from_email', -1, -1) # repos shared to groups group_repos = get_group_repos_by_owner(username) for repo in group_repos: group = ccnet_threaded_rpc.get_group(int(repo.group_id)) if not group: repo.props.user = '' continue repo.props.user = group.props.group_name repo.props.user_info = repo.group_id shared_repos += group_repos if not CLOUD_MODE: # public repos shared by this user pub_repos = list_inner_pub_repos_by_owner(username) for repo in pub_repos: repo.props.user = _(u'all members') repo.props.user_info = 'all' shared_repos += pub_repos for repo in shared_repos: if repo.props.permission == 'rw': repo.share_permission = _(u'Read-Write') elif repo.props.permission == 'r': repo.share_permission = _(u'Read-Only') else: repo.share_permission = '' if repo.props.share_type == 'personal': repo.props.user_info = repo.props.user shared_repos.sort(lambda x, y: cmp(x.repo_id, y.repo_id)) # Repo anonymous share links # out_links = AnonymousShare.objects.filter(repo_owner=request.user.username) # for link in out_links: # repo = get_repo(link.repo_id) # link.repo_name = repo.name # link.remain_time = anon_share_token_generator.get_remain_time(link.token) # Shared links fileshares = FileShare.objects.filter(username=username) p_fileshares = [] # personal file share for fs in fileshares: if is_personal_repo(fs.repo_id): # only list files in personal repos if fs.s_type == 'f': fs.filename = os.path.basename(fs.path) fs.shared_link = gen_shared_link(request, fs.token, 'f') else: fs.filename = os.path.basename(fs.path[:-1]) fs.shared_link = gen_shared_link(request, fs.token, 'd') r = get_repo(fs.repo_id) if not r: # get_repo may returns None continue fs.repo = r p_fileshares.append(fs) return render_to_response( 'repo/share_admin.html', { "org": None, "shared_repos": shared_repos, # "out_links": out_links, "fileshares": p_fileshares, }, context_instance=RequestContext(request))
def share_admin(request): """ List personal shared repos and shared links. """ username = request.user.username shared_repos = [] # personal repos shared by this user shared_repos += list_share_repos(username, 'from_email', -1, -1) # repos shared to groups group_repos = get_group_repos_by_owner(username) for repo in group_repos: group = ccnet_threaded_rpc.get_group(int(repo.group_id)) if not group: repo.props.user = '' continue repo.props.user = group.props.group_name repo.props.user_info = repo.group_id shared_repos += group_repos if not CLOUD_MODE: # public repos shared by this user pub_repos = list_inner_pub_repos_by_owner(username) for repo in pub_repos: repo.props.user = _(u'all members') repo.props.user_info = 'all' shared_repos += pub_repos for repo in shared_repos: if repo.props.permission == 'rw': repo.share_permission = _(u'Read-Write') elif repo.props.permission == 'r': repo.share_permission = _(u'Read-Only') else: repo.share_permission = '' if repo.props.share_type == 'personal': repo.props.user_info = repo.props.user shared_repos.sort(lambda x, y: cmp(x.repo_id, y.repo_id)) # Repo anonymous share links # out_links = AnonymousShare.objects.filter(repo_owner=request.user.username) # for link in out_links: # repo = get_repo(link.repo_id) # link.repo_name = repo.name # link.remain_time = anon_share_token_generator.get_remain_time(link.token) # Shared links fileshares = FileShare.objects.filter(username=username) p_fileshares = [] # personal file share for fs in fileshares: if is_personal_repo(fs.repo_id): # only list files in personal repos if fs.s_type == 'f': fs.filename = os.path.basename(fs.path) fs.shared_link = gen_shared_link(request, fs.token, 'f') else: fs.filename = os.path.basename(fs.path[:-1]) fs.shared_link = gen_shared_link(request, fs.token, 'd') r = get_repo(fs.repo_id) if not r: # get_repo may returns None continue fs.repo = r p_fileshares.append(fs) return render_to_response('repo/share_admin.html', { "org": None, "shared_repos": shared_repos, # "out_links": out_links, "fileshares": p_fileshares, }, context_instance=RequestContext(request))