diff --git a/seahub/constants.py b/seahub/constants.py index fd69e97839..836e22d45a 100644 --- a/seahub/constants.py +++ b/seahub/constants.py @@ -14,3 +14,13 @@ DEFAULT_ADMIN = 'default_admin' SYSTEM_ADMIN = 'system_admin' DAILY_ADMIN = 'daily_admin' AUDIT_ADMIN = 'audit_admin' + +HASH_URLS = { + 'VIEW_COMMON_LIB_DIR': u'/#common/lib/%(repo_id)s/%(path)s', + 'GROUP_INFO': u'/#group/%(group_id)s/', + 'GROUP_MEMBERS': u'/#group/%(group_id)s/members/', + 'GROUP_DISCUSS': u'/#group/%(group_id)s/discussions/', + 'GROUP_LIST': u'/#groups/', + 'SYS_REPO_ADMIN': u'/sysadmin/#all-libs/', + + } diff --git a/seahub/group/templates/group/group_base.html b/seahub/group/templates/group/group_base.html index 85e55368d5..0af8c35b03 100644 --- a/seahub/group/templates/group/group_base.html +++ b/seahub/group/templates/group/group_base.html @@ -13,7 +13,7 @@ {% block left_panel %}

- {% grp_avatar group.props.id 32 %} {{ group.group_name }} + {% grp_avatar group.props.id 32 %} {{ group.group_name }}

{% endblock %} diff --git a/seahub/group/views.py b/seahub/group/views.py index 777ff0d012..a678f2d1a7 100644 --- a/seahub/group/views.py +++ b/seahub/group/views.py @@ -38,6 +38,7 @@ from seahub.views import is_registered_user, check_folder_permission from seahub.views.modules import get_enabled_mods_by_group, \ get_available_mods_by_group from seahub.share.models import ExtraGroupsSharePermission +from seahub.constants import HASH_URLS from seahub.forms import SharedRepoCreateForm @@ -93,7 +94,7 @@ def group_check(func): group_id_int = int(group_id) # Checked by URL Conf group = get_group(group_id_int) if not group: - return HttpResponseRedirect(reverse('group_list', args=[])) + return HttpResponseRedirect(HASH_URLS['GROUP_LIST']) group.is_staff = False if PublicGroup.objects.filter(group_id=group.id): group.is_pub = True diff --git a/seahub/institutions/templates/institutions/user_info.html b/seahub/institutions/templates/institutions/user_info.html index 867867a40b..435205b6ce 100644 --- a/seahub/institutions/templates/institutions/user_info.html +++ b/seahub/institutions/templates/institutions/user_info.html @@ -78,7 +78,7 @@ {% if repo.encrypted %} {{ repo.name }} {% elif enable_sys_admin_view_repo %} - {{ repo.name }} + {{ repo.name }} {% else %} {{ repo.name }} {% endif %} diff --git a/seahub/notifications/management/commands/send_notices.py b/seahub/notifications/management/commands/send_notices.py index f0a379a69a..9e52e49671 100644 --- a/seahub/notifications/management/commands/send_notices.py +++ b/seahub/notifications/management/commands/send_notices.py @@ -22,6 +22,7 @@ from seahub.avatar.util import get_default_avatar_url from seahub.base.templatetags.seahub_tags import email2nickname from seahub.invitations.models import Invitation from seahub.profile.models import Profile +from seahub.constants import HASH_URLS # Get an instance of a logger logger = logging.getLogger(__name__) @@ -73,7 +74,7 @@ class Command(BaseCommand): message = d['message'] group = ccnet_api.get_group(int(group_id)) - notice.group_url = reverse('group_discuss', args=[group.id]) + notice.group_url = HASH_URLS['GROUP_DISCUSS'] % {'group_id': group.id} notice.notice_from = escape(email2nickname(d['msg_from'])) notice.group_name = group.group_name notice.avatar_src = self.get_avatar_src(d['msg_from']) @@ -85,7 +86,7 @@ class Command(BaseCommand): repo_id = d['repo_id'] repo = seafile_api.get_repo(repo_id) - notice.repo_url = reverse("view_common_lib_dir", args=[repo_id, '']) + notice.repo_url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': ''} notice.notice_from = escape(email2nickname(d['share_from'])) notice.repo_name = repo.name notice.avatar_src = self.get_avatar_src(d['share_from']) @@ -100,11 +101,11 @@ class Command(BaseCommand): group_id = d['group_id'] group = ccnet_api.get_group(group_id) - notice.repo_url = reverse("view_common_lib_dir", args=[repo_id, '']) + notice.repo_url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': ''} notice.notice_from = escape(email2nickname(d['share_from'])) notice.repo_name = repo.name notice.avatar_src = self.get_avatar_src(d['share_from']) - notice.group_url = reverse("group_info", args=[group.id]) + notice.group_url = HASH_URLS['GROUP_INFO'] % {'group_id': group.id} notice.group_name = group.group_name return notice @@ -117,7 +118,7 @@ class Command(BaseCommand): uploaded_to = d['uploaded_to'].rstrip('/') file_path = uploaded_to + '/' + file_name file_link = reverse('view_lib_file', args=[repo_id, file_path]) - folder_link = reverse('view_common_lib_dir', args=[repo_id, uploaded_to.strip('/')]) + folder_link = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': uploaded_to.strip('/')} folder_name = os.path.basename(uploaded_to) notice.file_link = file_link @@ -137,7 +138,7 @@ class Command(BaseCommand): notice.grpjoin_user_profile_url = reverse('user_profile', args=[username]) - notice.grpjoin_group_url = reverse('group_members', args=[group_id]) + notice.grpjoin_group_url = HASH_URLS['GROUP_MEMBERS'] % {'group_id': group_id} notice.notice_from = escape(email2nickname(username)) notice.grpjoin_group_name = group.group_name notice.grpjoin_request_msg = join_request_msg @@ -155,7 +156,7 @@ class Command(BaseCommand): notice.avatar_src = self.get_avatar_src(group_staff) notice.group_staff_profile_url = reverse('user_profile', args=[group_staff]) - notice.group_url = reverse('group_info', args=[group_id]) + notice.group_url = HASH_URLS['GROUP_INFO'] % {'group_id': group_id} notice.group_name = group.group_name return notice diff --git a/seahub/notifications/models.py b/seahub/notifications/models.py index 5771468a84..1f1e911ee6 100644 --- a/seahub/notifications/models.py +++ b/seahub/notifications/models.py @@ -21,6 +21,7 @@ from seahub.invitations.models import Invitation from seahub.utils.repo import get_repo_shared_users from seahub.utils import normalize_cache_key from seahub.utils.timeutils import datetime_to_isoformat_timestr +from seahub.constants import HASH_URLS # Get an instance of a logger logger = logging.getLogger(__name__) @@ -460,12 +461,13 @@ class UserNotification(models.Model): if d['uploaded_to'] == '/': # current upload path is '/' file_path = '/' + filename - link = reverse('view_common_lib_dir', args=[repo_id, '']) + link = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': ''} name = repo.name else: uploaded_to = d['uploaded_to'].rstrip('/') file_path = uploaded_to + '/' + filename - link = reverse('view_common_lib_dir', args=[repo_id, uploaded_to.lstrip('/')]) + link = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, + 'path': uploaded_to.lstrip('/')} name = os.path.basename(uploaded_to) file_link = reverse('view_lib_file', args=[repo_id, file_path]) @@ -521,7 +523,7 @@ class UserNotification(models.Model): msg = _(u"%(user)s has shared a library named %(repo_name)s to you.") % { 'user': escape(share_from), - 'href': reverse('view_common_lib_dir', args=[repo.id, '']), + 'href': HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id':repo.id, 'path': ''}, 'repo_name': escape(repo.name), } @@ -568,9 +570,9 @@ class UserNotification(models.Model): msg = _(u"%(user)s has shared a library named %(repo_name)s to group %(group_name)s.") % { 'user': escape(share_from), - 'repo_href': reverse('view_common_lib_dir', args=[repo.id, '']), + 'repo_href': HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo.id, 'path': ''}, 'repo_name': escape(repo.name), - 'group_href': reverse('group_info', args=[group.id]), + 'group_href': HASH_URLS['GROUP_INFO'] % {'group_id': group.id}, 'group_name': escape(group.group_name), } @@ -598,11 +600,11 @@ class UserNotification(models.Model): if msg_from is None: msg = _(u"%(group_name)s has a new discussion.") % { - 'href': reverse('group_discuss', args=[group.id]), + 'href': HASH_URLS['GROUP_DISCUSS'] % {'group_id': group.id}, 'group_name': group.group_name} else: msg = _(u"%(user)s posted a new discussion in %(group_name)s.") % { - 'href': reverse('group_discuss', args=[group.id]), + 'href': HASH_URLS['GROUP_DISCUSS'] % {'group_id': group.id}, 'user': escape(email2nickname(msg_from)), 'group_name': escape(group.group_name) } @@ -650,7 +652,7 @@ class UserNotification(models.Model): msg = _(u"User %(username)s has asked to join group %(group_name)s, verification message: %(join_request_msg)s") % { 'user_profile': reverse('user_profile', args=[username]), 'username': username, - 'href': reverse('group_members', args=[group_id]), + 'href': HASH_URLS['GROUP_MEMBERS'] % {'group_id': group_id}, 'group_name': escape(group.group_name), 'join_request_msg': escape(join_request_msg), } @@ -679,7 +681,7 @@ class UserNotification(models.Model): msg = _(u"User %(group_staff)s has added you to group %(group_name)s") % { 'user_profile': reverse('user_profile', args=[group_staff]), 'group_staff': group_staff, - 'href': reverse('group_info', args=[group_id]), + 'href': HASH_URLS['GROUP_INFO'] % {'group_id': group_id}, 'group_name': escape(group.group_name)} return msg diff --git a/seahub/profile/templates/profile/set_profile.html b/seahub/profile/templates/profile/set_profile.html index 5a8e038676..a40f3c046d 100644 --- a/seahub/profile/templates/profile/set_profile.html +++ b/seahub/profile/templates/profile/set_profile.html @@ -118,7 +118,7 @@

{% trans "Default Library Setting" %}

{% if default_repo %} -

{% trans "Your default library:" %} {{default_repo.name}}.

+

{% trans "Your default library:" %} {{default_repo.name}}.

{% endif %}

{% trans "Default library is the default place to store your personal documents and pictures." %}

diff --git a/seahub/templates/file_access.html b/seahub/templates/file_access.html index 5605f2d2af..65538812eb 100644 --- a/seahub/templates/file_access.html +++ b/seahub/templates/file_access.html @@ -10,7 +10,7 @@ {% trans 'Current Path:' %} {% for name, link in zipped %} {% if not forloop.last %} - {{ name }} / + {{ name }} / {% else %} {{ name }} {% endif %} diff --git a/seahub/templates/file_edit.html b/seahub/templates/file_edit.html index fc6eb54c27..ea9485cd85 100644 --- a/seahub/templates/file_edit.html +++ b/seahub/templates/file_edit.html @@ -89,7 +89,7 @@ {% trans "Current path: " %} {% for name, link in zipped %} {% if not forloop.last %} - {{ name }} / + {{ name }} / {% else %} {{ name }} {% endif %} diff --git a/seahub/templates/file_revisions.html b/seahub/templates/file_revisions.html index aa0a67b59a..a674b710a6 100644 --- a/seahub/templates/file_revisions.html +++ b/seahub/templates/file_revisions.html @@ -26,7 +26,7 @@ {% trans 'Current Path:' %} {% for name, link in zipped %} {% if not forloop.last %} - {{ name }} / + {{ name }} / {% else %} {{ name }} {% endif %} diff --git a/seahub/templates/home_base.html b/seahub/templates/home_base.html index 3d28f8f2ed..b55bb6de94 100644 --- a/seahub/templates/home_base.html +++ b/seahub/templates/home_base.html @@ -23,7 +23,7 @@ {% trans "Shared with groups" %} <% if (cur_tab == 'libraries') { %> <% if (option == 'all') { %> -
+
<% } %> <% if (option == 'trash') { %> -
+
<% } %> <% } %> <% if (cur_tab == 'groups') { %> -
+
<% } %> diff --git a/seahub/templates/js/templates.html b/seahub/templates/js/templates.html index 24ac745d07..cb07c577f3 100644 --- a/seahub/templates/js/templates.html +++ b/seahub/templates/js/templates.html @@ -1323,7 +1323,7 @@
  • {% trans "Shared with groups" %}
  • - + {% if can_lock_unlock_file %} {% if not file_locked %} diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index d0477c3356..789a144858 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -54,6 +54,7 @@ import seahub.settings as settings from seahub.settings import AVATAR_FILE_STORAGE, ENABLE_STORAGE_CLASSES, \ ENABLE_SUB_LIBRARY, ENABLE_FOLDER_PERM, ENABLE_REPO_SNAPSHOT_LABEL, \ UNREAD_NOTIFICATIONS_REQUEST_INTERVAL +from seahub.constants import HASH_URLS LIBRARY_TEMPLATES = getattr(settings, 'LIBRARY_TEMPLATES', {}) @@ -175,7 +176,7 @@ def get_repo_dirents(request, repo, commit, path, offset=-1, limit=-1): uploadlinks = UploadLinkShare.objects.filter(repo_id=repo.id).filter(username=username) - view_dir_base = reverse("view_common_lib_dir", args=[repo.id, '']) + view_dir_base = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo.id, 'path': ''} dl_dir_base = reverse('repo_download_dir', args=[repo.id]) file_history_base = reverse('file_revisions', args=[repo.id]) for dirent in dirs: @@ -471,7 +472,8 @@ def repo_history(request, repo_id): return render_error(request, e.msg) if not password_set: - return HttpResponseRedirect(reverse("view_common_lib_dir", args=[repo_id, ''])) + reverse_url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': ''} + return HttpResponseRedirect(reverse_url) try: current_page = int(request.GET.get('page', '1')) @@ -555,7 +557,8 @@ def repo_revert_history(request, repo_id): return render_error(request, e.msg) if not password_set: - return HttpResponseRedirect(reverse("view_common_lib_dir", args=[repo_id, ''])) + reverse_url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': ''} + return HttpResponseRedirect(reverse_url) commit_id = request.GET.get('commit_id', '') if not commit_id: @@ -579,7 +582,7 @@ def repo_revert_history(request, repo_id): def fpath_to_link(repo_id, path, is_dir=False): """Translate file path of a repo to its view link""" if is_dir: - href = reverse("view_common_lib_dir", args=[repo_id, path.encode('utf-8').strip('/')]) + href = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': path.encode('utf-8').strip('/')} else: if not path.startswith('/'): p = '/' + path @@ -736,8 +739,9 @@ def libraries(request): def repo_set_access_property(request, repo_id): ap = request.GET.get('ap', '') seafserv_threaded_rpc.repo_set_access_property(repo_id, ap) + reverse_url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': ''} - return HttpResponseRedirect(reverse("view_common_lib_dir", args=[repo_id, ''])) + return HttpResponseRedirect(reverse_url) @login_required def validate_filename(request): @@ -1003,15 +1007,14 @@ def convert_cmmt_desc_link(request): elif d.status == 'mov': # Move or Rename non-empty file/folder if '/' in d.new_name: new_dir_name = d.new_name.split('/')[0] - return HttpResponseRedirect( - reverse('view_common_lib_dir', - args=[repo_id, new_dir_name])) + reverse_url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': new_dir_name} + return HttpResponseRedirect(reverse_url) else: return HttpResponseRedirect( reverse('view_lib_file', args=[repo_id, '/' + d.new_name])) elif d.status == 'newdir': - return HttpResponseRedirect( - reverse('view_common_lib_dir', args=[repo_id, d.name.strip('/')])) + reverse_url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': d.name.strip('/')}, + return HttpResponseRedirect(reverse_url) else: continue diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py index 37945bc9b0..e02c44dc1e 100644 --- a/seahub/views/ajax.py +++ b/seahub/views/ajax.py @@ -55,6 +55,7 @@ from seahub.share.utils import is_repo_admin from seahub.base.templatetags.seahub_tags import translate_seahub_time, \ email2nickname, tsstr_sec from seahub.constants import PERMISSION_ADMIN +from seahub.constants import HASH_URLS # Get an instance of a logger logger = logging.getLogger(__name__) @@ -752,7 +753,7 @@ def mv_dirents(request, src_repo_id, src_path, dst_repo_id, dst_path, success.append(obj_name) if len(success) > 0: - url = reverse("view_common_lib_dir", args=[dst_repo_id, dst_path.strip('/')]) + url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': dst_repo_id, 'path': dst_path.strip('/')}, result = {'success': success, 'failed': failed, 'url': url} return HttpResponse(json.dumps(result), content_type=content_type) @@ -795,7 +796,7 @@ def cp_dirents(request, src_repo_id, src_path, dst_repo_id, dst_path, obj_file_n success.append(obj_name) if len(success) > 0: - url = reverse("view_common_lib_dir", args=[dst_repo_id, dst_path.strip('/')]) + url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': dst_repo_id, 'path': dst_path.strip('/')}, result = {'success': success, 'failed': failed, 'url': url} return HttpResponse(json.dumps(result), content_type=content_type) diff --git a/seahub/views/file.py b/seahub/views/file.py index b8dc848188..716618d7a8 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -67,6 +67,8 @@ from seahub.utils.file_op import check_file_lock from seahub.views import check_folder_permission, \ get_unencry_rw_repos_by_user +from seahub.constants import HASH_URLS + if HAS_OFFICE_CONVERTER: from seahub.utils import ( query_office_convert_status, add_office_convert_task, @@ -1381,7 +1383,8 @@ def download_file(request, repo_id, obj_id): raise Http404 if repo.encrypted and not seafile_api.is_password_set(repo_id, username): - return HttpResponseRedirect(reverse('view_common_lib_dir', args=[repo_id, ''])) + reverse_url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': ''} + return HttpResponseRedirect(reverse_url) # only check the permissions at the repo level # to prevent file can not be downloaded on the history page diff --git a/seahub/views/repo.py b/seahub/views/repo.py index ae646d4588..7d80cd074d 100644 --- a/seahub/views/repo.py +++ b/seahub/views/repo.py @@ -31,6 +31,7 @@ from seahub.settings import ENABLE_UPLOAD_FOLDER, \ MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD from seahub.utils.file_types import IMAGE, VIDEO from seahub.thumbnail.utils import get_share_link_thumbnail_src +from seahub.constants import HASH_URLS # Get an instance of a logger logger = logging.getLogger(__name__) @@ -127,17 +128,18 @@ def repo_history_view(request, repo_id): # Assume server_crypto is ``False`` if this option is not set. server_crypto = False + reverse_url = HASH_URLS["VIEW_COMMON_LIB_DIR"] % {'repo_id': repo_id, 'path': ''} if repo.encrypted and \ (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \ and not is_password_set(repo.id, username): return render(request, 'decrypt_repo_form.html', { 'repo': repo, - 'next': get_next_url_from_request(request) or reverse("view_common_lib_dir", args=[repo_id, '']), + 'next': get_next_url_from_request(request) or reverse_url, }) commit_id = request.GET.get('commit_id', None) if commit_id is None: - return HttpResponseRedirect(reverse("view_common_lib_dir", args=[repo_id, ''])) + return HttpResponseRedirect(reverse_url) current_commit = get_commit(repo.id, repo.version, commit_id) if not current_commit: current_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id) diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index 1ebf35592b..135fb21542 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -36,7 +36,7 @@ from seahub.base.templatetags.seahub_tags import tsstr_sec, email2nickname from seahub.auth import authenticate from seahub.auth.decorators import login_required, login_required_ajax from seahub.constants import GUEST_USER, DEFAULT_USER, DEFAULT_ADMIN, \ - SYSTEM_ADMIN, DAILY_ADMIN, AUDIT_ADMIN + SYSTEM_ADMIN, DAILY_ADMIN, AUDIT_ADMIN, HASH_URLS from seahub.institutions.models import (Institution, InstitutionAdmin, InstitutionQuota) from seahub.institutions.utils import get_institution_space_usage @@ -1713,7 +1713,7 @@ def sys_repo_delete(request, repo_id): """ next = request.META.get('HTTP_REFERER', None) if not next: - next = reverse('sys_repo_admin') + next = HASH_URLS['SYS_REPO_ADMIN'] if get_system_default_repo_id() == repo_id: messages.error(request, _('System library can not be deleted.')) diff --git a/tests/seahub/group/views/test_group.py b/tests/seahub/group/views/test_group.py index 91dfbf608b..55b8167bdd 100644 --- a/tests/seahub/group/views/test_group.py +++ b/tests/seahub/group/views/test_group.py @@ -1,6 +1,7 @@ from django.core.urlresolvers import reverse from seahub.test_utils import BaseTestCase +from seahub.constants import HASH_URLS class GroupDiscussTest(BaseTestCase): @@ -11,5 +12,5 @@ class GroupDiscussTest(BaseTestCase): self.remove_group() def test_can_render(self): - resp = self.client.get(reverse('group_discuss', args=[self.group.id])) + resp = self.client.get(HASH_URLS['GROUP_DISCUSS']% {'group_id': self.group.id}) self.assertEqual(200, resp.status_code) diff --git a/tests/seahub/notifications/management/commands/test_send_notices.py b/tests/seahub/notifications/management/commands/test_send_notices.py index c7b918b44a..f1621f8136 100644 --- a/tests/seahub/notifications/management/commands/test_send_notices.py +++ b/tests/seahub/notifications/management/commands/test_send_notices.py @@ -4,9 +4,12 @@ from django.core.management import call_command from seahub.invitations.models import Invitation from seahub.notifications.models import ( UserNotification, repo_share_msg_to_json, file_comment_msg_to_json, - guest_invitation_accepted_msg_to_json) + guest_invitation_accepted_msg_to_json, repo_share_to_group_msg_to_json, + file_uploaded_msg_to_json, group_join_request_to_json, + add_user_to_group_to_json, group_msg_to_json) from seahub.profile.models import Profile from seahub.test_utils import BaseTestCase +from seahub.notifications.management.commands.send_notices import Command class CommandTest(BaseTestCase): @@ -60,3 +63,51 @@ class CommandTest(BaseTestCase): self.assertEqual(len(mail.outbox), 1) assert mail.outbox[0].to[0] == self.user.username assert 'Guest test@test.com' in mail.outbox[0].body + + def test_format_repo_share_msg(self): + detail = repo_share_msg_to_json('share@share.com', self.repo.id, '', -1) + notice = UserNotification.objects.add_repo_share_msg('to@to.com', detail) + resp = Command().format_repo_share_msg(notice) + + assert resp.repo_url == '/#common/lib/%(repo_id)s/%(path)s' % {'repo_id': self.repo.id, + 'path': ''} + + def test_format_group_message(self): + detail = group_msg_to_json(self.group.id, 'from@email.com', 'message') + notice = UserNotification(to_user= 'to@user.com', msg_type='group_msg', detail=detail) + resp = Command().format_group_message(notice) + assert resp.group_url == '/#group/%(group_id)s/discussions/' % {'group_id': self.group.id} + + def test_format_repo_share_to_group_msg(self): + detail = repo_share_to_group_msg_to_json('repo@share.com', self.repo.id, self.group.id, '', -1) + notice = UserNotification.objects.add_repo_share_to_group_msg('group@share.com', detail) + resp = Command().format_repo_share_to_group_msg(notice) + + assert resp.repo_url == '/#common/lib/%(repo_id)s/%(path)s' % {'repo_id': self.repo.id, + 'path': ''} + assert resp.group_url == '/#group/%(group_id)s/' % {'group_id': self.group.id} + + def test_format_file_uploaded_msg(self): + upload_to = '/' + detail = file_uploaded_msg_to_json('upload_msg', self.repo.id, upload_to) + notice = UserNotification.objects.add_file_uploaded_msg('file@upload.com', detail) + resp = Command().format_file_uploaded_msg(notice) + + assert resp.folder_link == '/#common/lib/%(repo_id)s/%(path)s' % {'repo_id': self.repo.id, + 'path': upload_to.strip('/')} + + def test_format_group_join_request(self): + detail = group_join_request_to_json('group_join', self.group.id, 'join_request_msg') + notice = UserNotification.objects.add_group_join_request_notice('group_join', + detail=detail) + resp = Command().format_group_join_request(notice) + + assert resp.grpjoin_group_url == '/#group/%(group_id)s/members/' % {'group_id': self.group.id} + + def test_format_add_user_to_group(self): + detail = add_user_to_group_to_json(self.user.username, self.group.id) + notice = UserNotification.objects.set_add_user_to_group_notice(self.user.username, + detail=detail) + resp = Command().format_add_user_to_group(notice) + + assert resp.group_url == '/#group/%(group_id)s/' % {'group_id': self.group.id} diff --git a/tests/seahub/notifications/test_models.py b/tests/seahub/notifications/test_models.py index d3f19adea0..85f81ef4d7 100644 --- a/tests/seahub/notifications/test_models.py +++ b/tests/seahub/notifications/test_models.py @@ -1,5 +1,8 @@ from seahub.notifications.models import ( - UserNotification, repo_share_msg_to_json, file_comment_msg_to_json) + UserNotification, repo_share_msg_to_json, file_comment_msg_to_json, + repo_share_to_group_msg_to_json, file_uploaded_msg_to_json, + group_join_request_to_json, add_user_to_group_to_json, group_msg_to_json) + from seahub.test_utils import BaseTestCase @@ -12,3 +15,48 @@ class UserNotificationTest(BaseTestCase): msg = notice.format_file_comment_msg() assert msg is not None assert 'new comment from user' in msg + + def test_format_file_uploaded_msg(self): + upload_to = '/' + detail = file_uploaded_msg_to_json('upload_msg', self.repo.id, upload_to) + notice = UserNotification.objects.add_file_uploaded_msg('file@upload.com', detail) + + msg = notice.format_file_uploaded_msg() + assert '/#common/lib/%(repo_id)s/%(path)s' % {'repo_id': self.repo.id, + 'path': upload_to.strip('/')} in msg + + def test_format_repo_share_msg(self): + detail = repo_share_msg_to_json('share@share.com', self.repo.id, '/', -1) + notice = UserNotification.objects.add_repo_share_msg('to@to.com', detail) + + msg = notice.format_repo_share_msg() + assert '/#common/lib/%(repo_id)s/%(path)s' % {'repo_id': self.repo.id, + 'path': ''} in msg + + def test_format_repo_share_to_group_msg(self): + detail = repo_share_to_group_msg_to_json('repo@share.com', self.repo.id, self.group.id, '/', -1) + notice = UserNotification.objects.add_repo_share_to_group_msg('group@share.com', detail) + + msg = notice.format_repo_share_to_group_msg() + assert '/#common/lib/%(repo_id)s/%(path)s' % {'repo_id': self.repo.id, 'path': ''} in msg + assert '/#group/%(group_id)s/' % {'group_id': self.group.id} in msg + + def test_format_group_message_title(self): + detail = group_msg_to_json(self.group.id, 'from@email.com', 'message') + notice = UserNotification(to_user= 'to@user.com', msg_type='group_msg', detail=detail) + msg = notice.format_group_message_title() + assert '/#group/%(group_id)s/discussions/' % {'group_id': self.group.id} in msg + + def test_format_group_join_request(self): + detail = group_join_request_to_json('group_join', self.group.id, 'join_request_msg') + notice = UserNotification.objects.add_group_join_request_notice('group_join', + detail=detail) + msg = notice.format_group_join_request() + assert '/#group/%(group_id)s/members/' % {'group_id': self.group.id} in msg + + def test_format_add_user_to_group(self): + detail = add_user_to_group_to_json(self.user.username, self.group.id) + notice = UserNotification.objects.set_add_user_to_group_notice(self.user.username, + detail=detail) + msg = notice.format_add_user_to_group() + assert '/#group/%(group_id)s/' % {'group_id': self.group.id} in msg diff --git a/tests/seahub/views/init/test_fpath_to_link.py b/tests/seahub/views/init/test_fpath_to_link.py new file mode 100644 index 0000000000..e9f06b152b --- /dev/null +++ b/tests/seahub/views/init/test_fpath_to_link.py @@ -0,0 +1,10 @@ +from seahub.test_utils import BaseTestCase +from seahub.views import fpath_to_link + + +class FpathToLinkTest(BaseTestCase): + def test_fpath_to_link(self): + path = '/' + resp = fpath_to_link(self.repo.id, path, is_dir=True) + assert '/#common/lib/%(repo_id)s/%(path)s' % {'repo_id': self.repo.id, + 'path': path.encode('utf-8').strip('/')} in resp diff --git a/tests/seahub/views/init/test_repo_history.py b/tests/seahub/views/init/test_repo_history.py index 496a0710e6..c901298605 100644 --- a/tests/seahub/views/init/test_repo_history.py +++ b/tests/seahub/views/init/test_repo_history.py @@ -12,3 +12,10 @@ class RepoHistoryTest(BaseTestCase): self.assertEqual(200, resp.status_code) self.assertTemplateUsed(resp, 'repo_history.html') assert len(resp.context['commits']) == 1 + + def test_passwd_true(self): + resp = self.client.get(reverse('repo_history', args=[self.enc_repo.id])) + + self.assertEqual(302, resp.status_code) + assert '/#common/lib/%(repo_id)s/%(path)s' % { + 'repo_id': self.enc_repo.id, 'path': ''} in resp.url diff --git a/tests/seahub/views/init/test_repo_revert_history.py b/tests/seahub/views/init/test_repo_revert_history.py index 897ff14f35..ec762f70bc 100644 --- a/tests/seahub/views/init/test_repo_revert_history.py +++ b/tests/seahub/views/init/test_repo_revert_history.py @@ -12,3 +12,10 @@ class RepoRevertHistoryTest(BaseTestCase): }) self.assertEqual(200, resp.status_code) assert 'Invalid arguments' in resp.content + + def test_passwd_true(self): + resp = self.client.post(reverse('repo_revert_history', args=[self.enc_repo.id]) + '?commit_id=xxx', {}) + + self.assertEqual(302, resp.status_code) + assert '/#common/lib/%(repo_id)s/%(path)s' % { + 'repo_id': self.enc_repo.id, 'path': ''} in resp.url