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_user_repos(user): """ Get all repos that user can access, including owns, shared, and repo in groups. NOTE: collumn names in shared_repo struct are not same as owned or group repos. """ email = user.username if user.org: # org context org_id = user.org['org_id'] owned_repos = list_org_repos_by_owner(org_id, email) shared_repos = list_personal_shared_repos(email, 'to_email', -1, -1) groups_repos = [] for group in get_org_groups_by_user(org_id, email): groups_repos += get_org_group_repos(org_id, group.id, email) else: # personal context owned_repos = list_personal_repos_by_owner(email) shared_repos = list_personal_shared_repos(email, 'to_email', -1, -1) groups_repos = [] for group in get_personal_groups_by_user(email): groups_repos += get_group_repos(group.id, email) return (owned_repos, shared_repos, groups_repos)
def find_wiki_repo(request, group): try: groupwiki = GroupWiki.objects.get(group_id=group.id) repos = get_group_repos(group.id, request.user.username) for repo in repos: if repo.id == groupwiki.repo_id: return repo return None except GroupWiki.DoesNotExist: return None
def get_group_wiki_repo(group, username): try: groupwiki = GroupWiki.objects.get(group_id=group.id) except GroupWiki.DoesNotExist: raise WikiDoesNotExist repos = seaserv.get_group_repos(group.id, username) for repo in repos: if repo.id == groupwiki.repo_id: return repo raise WikiDoesNotExist
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 = [] for group in seaserv.get_personal_groups_by_user(username): # TODO: use seafile_api.get_group_repos groups_repos += seaserv.get_group_repos(group.id, username) if CLOUD_MODE: public_repos = [] else: public_repos = seaserv.list_inner_pub_repos(username) 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.desc = r.repo_desc 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 = [] for group in seaserv.get_org_groups_by_user(org_id, username): groups_repos += seafile_api.get_org_group_repos(org_id, group.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.desc = r.repo_desc r.last_modify = r.last_modified return (owned_repos, shared_repos, groups_repos, public_repos)
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 = seaserv.list_personal_repos_by_owner(username) shared_repos = seafile_api.get_share_in_repo_list(username, -1, -1) groups_repos = [] for group in seaserv.get_personal_groups_by_user(username): # TODO: use seafile_api.get_group_repos groups_repos += seaserv.get_group_repos(group.id, username) if CLOUD_MODE: public_repos = [] else: public_repos = seaserv.list_inner_pub_repos(username) 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.desc = r.repo_desc 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 = [] for group in seaserv.get_org_groups_by_user(org_id, username): groups_repos += seafile_api.get_org_group_repos(org_id, group.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.desc = r.repo_desc r.last_modify = r.last_modified return (owned_repos, shared_repos, groups_repos, public_repos)
def get_user_repos(username): """ 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 = username shared_repos = seafile_api.get_share_in_repo_list(email, -1, -1) 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) if CLOUD_MODE: public_repos = [] else: public_repos = list_inner_pub_repos(email) return (owned_repos, shared_repos, groups_repos, public_repos)
def get_user_repos(username): """ 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 = username shared_repos = wingufile_api.get_share_in_repo_list(email, -1, -1) 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) if CLOUD_MODE: public_repos = [] else: public_repos = list_inner_pub_repos(email) return (owned_repos, shared_repos, groups_repos, public_repos)
def group_wiki(request, group, page_name="home"): username = request.user.username # get available modules(wiki, etc) mods_available = get_available_mods_by_group(group.id) mods_enabled = get_enabled_mods_by_group(group.id) wiki_exists = True try: content, repo, dirent = get_group_wiki_page(username, group, page_name) except WikiDoesNotExist: wiki_exists = False group_repos = get_group_repos(group.id, username) group_repos = [r for r in group_repos if not r.encrypted] return render_to_response("group/group_wiki.html", { "group": group, "is_staff": group.is_staff, "wiki_exists": wiki_exists, "mods_enabled": mods_enabled, "mods_available": mods_available, "group_repos": group_repos, }, context_instance=RequestContext(request)) except WikiPageMissing: '''create that page for user if he/she is a group member''' if not is_group_user(group.id, username): raise Http404 repo = get_group_wiki_repo(group, username) # No need to check whether repo is none, since repo is already created filename = page_name_to_file_name(clean_page_name(page_name)) if not post_empty_file(repo.id, "/", filename, username): return render_error( request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect( reverse('group_wiki', args=[group.id, page_name])) else: # fetch file modified time and modifier path = '/' + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) if dirent: latest_contributor, last_modified = dirent.modifier, dirent.mtime else: latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 if is_registered_user(username): repo_perm = seafile_api.check_permission_by_path( repo.id, '/', username) else: # when anonymous user visit public group wiki, set permission as 'r' repo_perm = 'r' wiki_index_exists = True index_pagename = 'index' index_content = None try: index_content, index_repo, index_dirent = get_group_wiki_page( username, group, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False return render_to_response( "group/group_wiki.html", { "group": group, "is_staff": group.is_staff, "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor or _("Unknown"), "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "mods_enabled": mods_enabled, "mods_available": mods_available, "repo_perm": repo_perm, "wiki_index_exists": wiki_index_exists, "index_content": index_content, }, context_instance=RequestContext(request))
def get(self, request): email = request.user.username owned_repos = seafserv_threaded_rpc.list_owned_repos(email) calculate_repo_info (owned_repos, email) owned_repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify)) n_repos = seafserv_threaded_rpc.list_share_repos(email, 'to_email', -1, -1) calculate_repo_info (n_repos, email) owned_repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify)) repos_json = [] for r in owned_repos: repo = { "type":"repo", "id":r.id, "owner":email, "name":r.name, "desc":r.desc, "mtime":r.latest_modify, "root":r.root, "size":r.size, "encrypted":r.encrypted, "password_need":r.password_need, } repos_json.append(repo) for r in n_repos: repo = { "type":"srepo", "id":r.id, "owner":r.shared_email, "name":r.name, "desc":r.desc, "mtime":r.latest_modify, "root":r.root, "size":r.size, "encrypted":r.encrypted, "password_need":r.password_need, } repos_json.append(repo) groups = get_personal_groups_by_user(email) for group in groups: g_repos = get_group_repos(group.id, email) calculate_repo_info (g_repos, email) owned_repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify)) for r in g_repos: repo = { "type":"grepo", "id":r.id, "owner":group.group_name, "name":r.name, "desc":r.desc, "mtime":r.latest_modify, "root":r.root, "size":r.size, "encrypted":r.encrypted, "password_need":r.password_need, } repos_json.append(repo) response = Response(200, repos_json) return self.render(response)
def group_wiki(request, group, page_name="home"): username = request.user.username # get available modules(wiki, etc) mods_available = get_available_mods_by_group(group.id) mods_enabled = get_enabled_mods_by_group(group.id) wiki_exists = True try: content, repo, dirent = get_group_wiki_page(username, group, page_name) except WikiDoesNotExist: wiki_exists = False group_repos = get_group_repos(group.id, username) group_repos = [r for r in group_repos if not r.encrypted] return render_to_response( "group/group_wiki.html", { "group": group, "is_staff": group.is_staff, "wiki_exists": wiki_exists, "mods_enabled": mods_enabled, "mods_available": mods_available, "group_repos": group_repos, }, context_instance=RequestContext(request), ) except WikiPageMissing: """create that page for user if he/she is a group member""" if not is_group_user(group.id, username): raise Http404 repo = get_group_wiki_repo(group, username) # No need to check whether repo is none, since repo is already created filename = page_name_to_file_name(clean_page_name(page_name)) if not post_empty_file(repo.id, "/", filename, username): return render_error(request, _("Failed to create wiki page. Please retry later.")) return HttpResponseRedirect(reverse("group_wiki", args=[group.id, page_name])) else: url_prefix = reverse("group_wiki", args=[group.id]) # fetch file modified time and modifier path = "/" + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) if dirent: latest_contributor, last_modified = dirent.modifier, dirent.mtime else: latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 repo_perm = seafile_api.check_repo_access_permission(repo.id, username) wiki_index_exists = True index_pagename = "index" index_content = None try: index_content, index_repo, index_dirent = get_group_wiki_page(username, group, index_pagename) except (WikiDoesNotExist, WikiPageMissing) as e: wiki_index_exists = False return render_to_response( "group/group_wiki.html", { "group": group, "is_staff": group.is_staff, "wiki_exists": wiki_exists, "content": content, "page": os.path.splitext(dirent.obj_name)[0], "last_modified": last_modified, "latest_contributor": latest_contributor or _("Unknown"), "path": path, "repo_id": repo.id, "search_repo_id": repo.id, "search_wiki": True, "mods_enabled": mods_enabled, "mods_available": mods_available, "repo_perm": repo_perm, "wiki_index_exists": wiki_index_exists, "index_content": index_content, }, context_instance=RequestContext(request), )
def get(self, request, format=None): email = request.user.username repos_json = [] owned_repos = list_personal_repos_by_owner(email) calculate_repo_info(owned_repos, email) owned_repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify)) for r in owned_repos: repo = { "type": "repo", "id": r.id, "owner": email, "name": r.name, "desc": r.desc, "mtime": r.latest_modify, "root": r.root, "size": r.size, "encrypted": r.encrypted, "permission": 'rw', # Always have read-write permission to owned repo } repos_json.append(repo) shared_repos = seafile_api.get_share_in_repo_list(email, -1, -1) for r in shared_repos: commit = get_commits(r.repo_id, 0, 1)[0] if not commit: continue r.latest_modify = commit.ctime r.root = commit.root_id r.size = server_repo_size(r.repo_id) r.password_need = is_passwd_set(r.repo_id, email) r.permission = check_permission(r.repo_id, email) repo = { "type": "srepo", "id": r.repo_id, "owner": r.user, "name": r.repo_name, "desc": r.repo_desc, "mtime": r.latest_modify, "root": r.root, "size": r.size, "encrypted": r.encrypted, "permission": r.permission, } repos_json.append(repo) groups = get_personal_groups_by_user(email) for group in groups: g_repos = get_group_repos(group.id, email) calculate_repo_info(g_repos, email) g_repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify)) for r in g_repos: repo = { "type": "grepo", "id": r.id, "owner": group.group_name, "name": r.name, "desc": r.desc, "mtime": r.latest_modify, "root": r.root, "size": r.size, "encrypted": r.encrypted, "permission": check_permission(r.id, email), } repos_json.append(repo) return Response(repos_json)
def get(self, request, format=None): email = request.user.username repos_json = [] owned_repos = list_personal_repos_by_owner(email) calculate_repo_info(owned_repos, email) owned_repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify)) for r in owned_repos: repo = { "type":"repo", "id":r.id, "owner":email, "name":r.name, "desc":r.desc, "mtime":r.latest_modify, "root":r.root, "size":r.size, "encrypted":r.encrypted, "permission": 'rw', # Always have read-write permission to owned repo } repos_json.append(repo) shared_repos = seafile_api.get_share_in_repo_list(email, -1, -1) for r in shared_repos: commit = get_commits(r.repo_id, 0, 1)[0] if not commit: continue r.latest_modify = commit.ctime r.root = commit.root_id r.size = server_repo_size(r.repo_id) r.password_need = is_passwd_set(r.repo_id, email) r.permission = check_permission(r.repo_id, email) repo = { "type":"srepo", "id":r.repo_id, "owner":r.user, "name":r.repo_name, "desc":r.repo_desc, "mtime":r.latest_modify, "root":r.root, "size":r.size, "encrypted":r.encrypted, "permission": r.permission, } repos_json.append(repo) groups = get_personal_groups_by_user(email) for group in groups: g_repos = get_group_repos(group.id, email) calculate_repo_info (g_repos, email) g_repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify)) for r in g_repos: repo = { "type":"grepo", "id":r.id, "owner":group.group_name, "name":r.name, "desc":r.desc, "mtime":r.latest_modify, "root":r.root, "size":r.size, "encrypted":r.encrypted, "permission": check_permission(r.id, email), } repos_json.append(repo) return Response(repos_json)
def render_group_info(request, group_id, form): group_id_int = int(group_id) # Checkeb by URL Conf # remove user notifications UserNotification.objects.filter(to_user=request.user.username, msg_type='group_msg', detail=str(group_id)).delete() group = get_group(group_id_int) if not group: return HttpResponseRedirect(reverse('group_list', args=[])) # Get all group members. members = get_group_members(group_id_int) # Check whether user belongs to the group. joined = is_group_user(group_id_int, request.user.username) if not joined and not request.user.is_staff: # Return group public info page. return render_to_response('group/group_pubinfo.html', { 'members': members, 'group': group, }, context_instance=RequestContext(request)) is_staff = True if check_group_staff(group.id, request.user) else False managers = [] common_members = [] for member in members: if member.is_staff == 1: managers.append(member) else: common_members.append(member) org = request.user.org if org: repos = get_org_group_repos(org['org_id'], group_id_int, request.user.username) else: repos = get_group_repos(group_id_int, request.user.username) for repo in repos: repo.user_perm = check_permission(repo.props.id, request.user.username) """group messages""" # Make sure page request is an int. If not, deliver first page. try: current_page = int(request.GET.get('page', '1')) per_page= int(request.GET.get('per_page', '15')) except ValueError: current_page = 1 per_page = 15 msgs_plus_one = GroupMessage.objects.filter( group_id=group_id).order_by( '-timestamp')[per_page*(current_page-1) : per_page*current_page+1] if len(msgs_plus_one) == per_page + 1: page_next = True else: page_next = False group_msgs = msgs_plus_one[:per_page] attachments = MessageAttachment.objects.filter(group_message__in=group_msgs) msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs) reply_to_list = [ r.reply_to_id for r in msg_replies ] for msg in group_msgs: msg.reply_cnt = reply_to_list.count(msg.id) for att in attachments: if msg.id == att.group_message_id: # Attachment name is file name or directory name. # If is top directory, use repo name instead. path = att.path if path == '/': repo = get_repo(att.repo_id) if not repo: # TODO: what should we do here, tell user the repo # is no longer exists? continue att.name = repo.name else: # cut out last '/' if path[-1] == '/': path = path[:-1] att.name = os.path.basename(path) msg.attachment = att contacts = Contact.objects.filter(user_email=request.user.username) return render_to_response("group/group_info.html", { "managers": managers, "common_members": common_members, "members": members, "repos": repos, "group_id": group_id, "group" : group, "is_staff": is_staff, "is_join": joined, "group_msgs": group_msgs, "form": form, 'current_page': current_page, 'prev_page': current_page-1, 'next_page': current_page+1, 'per_page': per_page, 'page_next': page_next, 'create_shared_repo': True, 'contacts': contacts, 'group_members_default_display': GROUP_MEMBERS_DEFAULT_DISPLAY, }, context_instance=RequestContext(request));
def render_group_info(request, group_id, form): group_id_int = int(group_id) # Checkeb by URL Conf # remove user notifications UserNotification.objects.filter(to_user=request.user.username, msg_type='group_msg', detail=str(group_id)).delete() group = get_group(group_id_int) if not group: return HttpResponseRedirect(reverse('group_list', args=[])) # Get all group members. members = get_group_members(group_id_int) # Check whether user belongs to the group. joined = is_group_user(group_id_int, request.user.username) if not joined and not request.user.is_staff: # Return group public info page. return render_to_response('group/group_pubinfo.html', { 'members': members, 'group': group, }, context_instance=RequestContext(request)) is_staff = True if check_group_staff(group.id, request.user) else False org = request.user.org if org: repos = get_org_group_repos(org['org_id'], group_id_int, request.user.username) else: repos = get_group_repos(group_id_int, request.user.username) recent_commits = [] cmt_repo_dict = {} for repo in repos: repo.user_perm = check_permission(repo.props.id, request.user.username) cmmts = get_commits(repo.props.id, 0, 10) for c in cmmts: cmt_repo_dict[c.id] = repo recent_commits += cmmts recent_commits.sort(lambda x, y : cmp(y.props.ctime, x.props.ctime)) recent_commits = recent_commits[:15] for cmt in recent_commits: cmt.repo = cmt_repo_dict[cmt.id] cmt.repo.password_set = is_passwd_set(cmt.props.repo_id, request.user.username) cmt.tp = cmt.props.desc.split(' ')[0] return render_to_response("group/group_info.html", { "members": members, "repos": repos, "recent_commits": recent_commits, "group_id": group_id, "group" : group, "is_staff": is_staff, "is_join": joined, "form": form, 'create_shared_repo': True, 'group_members_default_display': GROUP_MEMBERS_DEFAULT_DISPLAY, }, context_instance=RequestContext(request));