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 %}
-
+
{% 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