diff --git a/group/templates/group/group_info.html b/group/templates/group/group_info.html index 1d16310bfd..70dc04ce84 100644 --- a/group/templates/group/group_info.html +++ b/group/templates/group/group_info.html @@ -111,7 +111,7 @@ {% else %} {% endif %} - {{ msg.attachment.path }} : + {{ msg.attachment.name }} : {% endif %} {{ msg.message|linebreaksbr|seahub_urlize|find_at }} diff --git a/group/views.py b/group/views.py index 223326bd67..e7b4cff33d 100644 --- a/group/views.py +++ b/group/views.py @@ -1,4 +1,5 @@ # encoding: utf-8 +import os import simplejson as json from django.core.urlresolvers import reverse from django.contrib import messages @@ -211,8 +212,24 @@ def render_group_info(request, group_id, form): group_msgs = msgs_plus_one[:per_page] for msg in group_msgs: msg.reply_cnt = len(MessageReply.objects.filter(reply_to=msg)) - msg.attachment = get_first_object_or_none( + # Get message attachment if exists. + attachment = get_first_object_or_none( MessageAttachment.objects.filter(group_message=msg)) + if not attachment: + continue + # Attachment name is file name or directory name. + # If is top directory, use repo name instead. + path = attachment.path + if path == '/': + repo = get_repo(attachment.repo_id) + if not repo: + # TODO: what should we do here, tell user the repo is no longer + # exists? + continue + attachment.name = repo.name + else: + attachment.name = os.path.basename(path) + msg.attachment = attachment return render_to_response("group/group_info.html", { "managers": managers, diff --git a/templates/repo.html b/templates/repo.html index 90f392cd3c..1840351e16 100644 --- a/templates/repo.html +++ b/templates/repo.html @@ -273,6 +273,9 @@ $(function() { {% for group in groups %} group_list.push('{{ group.props.group_name }} <{{ group.props.creator_name }}>'); {% endfor %} + if (group_list.length == 1) { + $('#recommend-form #groups').val(group_list[0]); + } addAutocomplete('#groups', '#recommend-form', group_list); $('.ui-autocomplete').css({'max-height': window.innerHeight - $('.ui-autocomplete-input').offset().top - $('.ui-autocomplete-input').height() - 10, 'overflow': 'auto'}); diff --git a/templates/repo_view_file.html b/templates/repo_view_file.html index 0fbc4f52ff..3b5ddcb7b8 100644 --- a/templates/repo_view_file.html +++ b/templates/repo_view_file.html @@ -218,6 +218,9 @@ $(function() { {% for group in groups %} group_list.push('{{ group.props.group_name }} <{{ group.props.creator_name }}>'); {% endfor %} + if (group_list.length == 1) { + $('#recommend-form #groups').val(group_list[0]); + } addAutocomplete('#groups', '#recommend-form', group_list); $('.ui-autocomplete').css({'max-height': window.innerHeight - $('.ui-autocomplete-input').offset().top - $('.ui-autocomplete-input').height() - 10, 'overflow': 'auto'}); diff --git a/templates/snippets/bottom_bar.html b/templates/snippets/bottom_bar.html index 2ba51bf26b..a0d05b8a0f 100644 --- a/templates/snippets/bottom_bar.html +++ b/templates/snippets/bottom_bar.html @@ -1,4 +1,9 @@ +{% if groups %} var Bottom_bar = '
'; +{% else %} +var Bottom_bar = '
'; +{% endif %} + $('#wrapper').append(Bottom_bar); $('#bottom-bar').css({'position':'fixed', 'bottom':0, 'left':$('#main').offset().left + $('#main').width() + 15}); $('#recommend').click(function() { diff --git a/thirdpart/seaserv/__init__.py b/thirdpart/seaserv/__init__.py index 922c3aaccf..c7c964fba5 100644 --- a/thirdpart/seaserv/__init__.py +++ b/thirdpart/seaserv/__init__.py @@ -6,7 +6,7 @@ from service import send_command from service import get_emailusers from service import get_org_groups, get_personal_groups, get_group_repoids, \ check_group_staff, remove_group_user, get_group, get_org_id_by_group, \ - get_group_members + get_group_members, check_group_repo from service import get_repos, get_repo, get_commits, get_branches, \ get_org_repos, is_repo_owner, create_org_repo from service import get_binding_peerids, is_valid_filename diff --git a/thirdpart/seaserv/service.py b/thirdpart/seaserv/service.py index d603d41163..e2f225913f 100644 --- a/thirdpart/seaserv/service.py +++ b/thirdpart/seaserv/service.py @@ -147,6 +147,16 @@ def get_group_members(group_id): members = [] return members +def check_group_repo(group_id, repo_id, user): + group_id_int = int(group_id) + + try: + ret = seafserv_threaded_rpc.check_group_repo(group_id_int, repo_id, + user) + except SearpcError: + ret = 0 + return ret + def get_org_id_by_group(group_id): try: org_id = ccnet_threaded_rpc.get_org_id_by_group(group_id) diff --git a/utils.py b/utils.py index c594e5ff74..3c86b7fde5 100644 --- a/utils.py +++ b/utils.py @@ -25,7 +25,7 @@ EMPTY_SHA1 = '0000000000000000000000000000000000000000' MAX_INT = 2147483647 PREVIEW_FILEEXT = { - 'Text': ('ac', 'am', 'bat', 'c', 'cc', 'cmake', 'cpp', 'css', 'diff', 'h', 'html', 'htm', 'java', 'js', 'json', 'less', 'make', 'org', 'php', 'pl', 'properties', 'py', 'rb', 'scala', 'script', 'sh', 'sql', 'txt','text', 'tex', 'vi', 'vim', 'xhtml', 'xml'), + 'Text': ('ac', 'am', 'bat', 'c', 'cc', 'cmake', 'cpp', 'css', 'diff', 'el', 'h', 'html', 'htm', 'java', 'js', 'json', 'less', 'make', 'org', 'php', 'pl', 'properties', 'py', 'rb', 'scala', 'script', 'sh', 'sql', 'txt', 'text', 'tex', 'vi', 'vim', 'xhtml', 'xml'), 'Image': ('gif', 'jpeg', 'jpg', 'png'), 'Document': ('doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'), 'SVG': ('svg',), diff --git a/views.py b/views.py index 99b2e6d7ce..89f17bd499 100644 --- a/views.py +++ b/views.py @@ -33,7 +33,7 @@ from seaserv import ccnet_rpc, ccnet_threaded_rpc, get_repos, get_emailusers, \ get_repo, get_commits, get_branches, is_valid_filename, remove_group_user,\ seafserv_threaded_rpc, seafserv_rpc, get_binding_peerids, \ get_group_repoids, check_group_staff, get_personal_groups, is_repo_owner, \ - get_group + get_group, check_group_repo from pysearpc import SearpcError from seahub.base.accounts import User @@ -225,9 +225,13 @@ def render_repo(request, repo_id, error=''): # generate path and link zipped = gen_path_link(path, repo.name) - # my groups - groups = get_personal_groups(request.user.username) - + # get groups this repo is shared to + groups = [] + personal_groups = get_personal_groups(request.user.username) + for group in personal_groups: + if check_group_repo(group.id, repo_id, request.user.username): + groups.append(group) + return render_to_response('repo.html', { "repo": repo, "can_access": can_access, @@ -237,10 +241,10 @@ def render_repo(request, repo_id, error=''): "repo_size": repo_size, "dir_list": dir_list, "file_list": file_list, - "path" : path, - "zipped" : zipped, - "error" : error, - "accessible_repos" : accessible_repos, + "path": path, + "zipped": zipped, + "error": error, + "accessible_repos": accessible_repos, "applet_root": get_ccnetapplet_root(), "groups": groups, }, context_instance=RequestContext(request)) @@ -818,8 +822,12 @@ def repo_view_file(request, repo_id): # my constacts contacts = Contact.objects.filter(user_email=request.user.username) - # my groups - groups = get_personal_groups(request.user.username) + # get groups this repo is shared to + groups = [] + personal_groups = get_personal_groups(request.user.username) + for group in personal_groups: + if check_group_repo(group.id, repo_id, request.user.username): + groups.append(group) return render_to_response('repo_view_file.html', { 'repo': repo,