From 8124fa4a79290bde50276de41468d60f86f3c8a1 Mon Sep 17 00:00:00 2001 From: lian Date: Fri, 19 Feb 2016 15:47:04 +0800 Subject: [PATCH 1/3] update admin default repo view page & rm unused code --- seahub/forms.py | 3 - .../management/commands/send_notices.py | 4 +- seahub/share/views.py | 82 - seahub/templates/repo.html | 2375 ----------------- .../templates/sysadmin/admin_repo_view.html | 268 +- .../templates/sysadmin/repoadmin_table.html | 4 +- .../templates/sysadmin/sys_list_system.html | 2 +- seahub/urls.py | 6 +- seahub/views/__init__.py | 100 +- seahub/views/ajax.py | 294 +- seahub/views/repo.py | 174 +- seahub/views/sysadmin.py | 6 +- tests/seahub/views/test_list_lib_dir.py | 24 + 13 files changed, 368 insertions(+), 2974 deletions(-) delete mode 100644 seahub/templates/repo.html create mode 100644 tests/seahub/views/test_list_lib_dir.py diff --git a/seahub/forms.py b/seahub/forms.py index 8eed7d8239..822173af79 100644 --- a/seahub/forms.py +++ b/seahub/forms.py @@ -146,9 +146,6 @@ class RepoPassowrdForm(forms.Form): except SearpcError, e: if e.msg == 'Bad arguments': raise forms.ValidationError(_(u'Bad url format')) - # elif e.msg == 'Repo is not encrypted': - # return HttpResponseRedirect(reverse('repo', - # args=[self.repo_id])) elif e.msg == 'Incorrect password': raise forms.ValidationError(_(u'Wrong password')) elif e.msg == 'Internal server error': diff --git a/seahub/notifications/management/commands/send_notices.py b/seahub/notifications/management/commands/send_notices.py index d1578bdcf3..afe4236d3d 100644 --- a/seahub/notifications/management/commands/send_notices.py +++ b/seahub/notifications/management/commands/send_notices.py @@ -124,7 +124,7 @@ class Command(BaseCommand): if repo is None: notice.delete() - notice.repo_url = reverse('repo', args=[repo.id]) + notice.repo_url = reverse("view_common_lib_dir", args=[repo_id, '/']) notice.notice_from = escape(email2nickname(d['share_from'])) notice.repo_name = repo.name notice.avatar_src = self.get_avatar_src(d['share_from']) @@ -138,7 +138,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, urlquote(file_path)]) - folder_link = reverse('repo', args=[repo_id]) + '?p=' + urlquote(uploaded_to) + folder_link = reverse('view_common_lib_dir', args=[repo_id, urlquote(uploaded_to).strip('/')]) folder_name = os.path.basename(uploaded_to) notice.file_link = file_link diff --git a/seahub/share/views.py b/seahub/share/views.py index a30d8ea11a..d54a28c618 100644 --- a/seahub/share/views.py +++ b/seahub/share/views.py @@ -716,88 +716,6 @@ def share_permission_admin(request): else: return HttpResponse(json.dumps({'success': False}), status=400, content_type=content_type) - -# 2 views for anonymous share: -# - anonymous_share records share infomation to db and sends the mail -# - anonymous_share_confirm checks the link use clicked and -# adds token to client COOKIE, then redirect client to repo page - -# def anonymous_share(request, email_template_name='repo/anonymous_share_email.html', **kwargs): -# repo_id = kwargs['repo_id'] -# repo_owner = kwargs['repo_owner'] -# anon_email = kwargs['anon_email'] -# is_encrypted = kwargs['is_encrypted'] - -# # Encrypt repo can not be shared to unregistered user. -# if is_encrypted: -# msg = _(u'Failed to share to %s, as encrypted libraries cannot be shared to emails outside the site.') % anon_email -# messages.error(request, msg) -# return - -# token = anon_share_token_generator.make_token() - -# anon_share = AnonymousShare() -# anon_share.repo_owner = repo_owner -# anon_share.repo_id = repo_id -# anon_share.anonymous_email = anon_email -# anon_share.token = token - -# try: -# anon_share.save() -# except: -# msg = _(u'Failed to share to %s.') % anon_email -# messages.add_message(request, messages.ERROR, msg) -# else: -# # send mail -# use_https = request.is_secure() -# site_name = domain = RequestSite(request).domain - -# t = loader.get_template(email_template_name) -# c = { -# 'email': repo_owner, -# 'anon_email': anon_email, -# 'domain': domain, -# 'site_name': site_name, -# 'token': token, -# 'protocol': use_https and 'https' or 'http', -# } - -# try: -# send_mail(_(u'You are shared with a library in Seafile'), t.render(Context(c)), None, -# [anon_email], fail_silently=False) -# except: -# AnonymousShare.objects.filter(token=token).delete() -# msg = _(u'Failed to share to %s.') % anon_email -# messages.add_message(request, messages.ERROR, msg) -# else: -# msg = _(u'Shared to %(email)s successfully, go check it at Share.') % \ -# {'email':anon_email, 'share':reverse('share_admin')} -# messages.add_message(request, messages.INFO, msg) - -# def anonymous_share_confirm(request, token=None): -# assert token is not None # checked by URLconf - -# # Check whether token in db -# try: -# anon_share = AnonymousShare.objects.get(token=token) -# except AnonymousShare.DoesNotExist: -# raise Http404 -# else: -# res = HttpResponseRedirect(reverse('repo', args=[anon_share.repo_id])) -# res.set_cookie("anontoken", token, -# max_age=ANONYMOUS_SHARE_COOKIE_TIMEOUT) -# return res - -# def remove_anonymous_share(request, token): -# AnonymousShare.objects.filter(token=token).delete() - -# next = request.META.get('HTTP_REFERER', None) -# if not next: -# next = reverse('share_admin') - -# messages.add_message(request, messages.INFO, _(u'Deleted successfully.')) - -# return HttpResponseRedirect(next) ########## share link @login_required_ajax diff --git a/seahub/templates/repo.html b/seahub/templates/repo.html deleted file mode 100644 index 6952568c27..0000000000 --- a/seahub/templates/repo.html +++ /dev/null @@ -1,2375 +0,0 @@ -{% extends "myhome_base.html" %} - -{% load seahub_tags avatar_tags i18n upload_tags %} - -{% block sub_title %}{{repo.name}} - {% endblock %} -{% block extra_style %} - - - - -{% endblock %} - -{% block main_panel %} -
-

{{repo.props.name}}{% if user_perm == 'r' %} ({% trans "Read-Only" %}){% endif %}

-
- {{ repo.props.desc|truncatechars:25 }} - {% trans 'Size: ' %}{{ repo_size|filesizeformat }} - {% if show_repo_download_button or show_repo_settings or user_perm == 'rw' %} - - {% if show_repo_download_button %} - {% trans "Download" %} - {% endif %} - {% if show_repo_settings %} - {% trans "Settings" %} - {% endif %} - {% if user_perm == 'rw' %} - {% trans "Trash"%} - {% endif %} - - {% endif %} -
-
- - {% if repo.enc_version == 2 and not server_crypto and repo.encrypted %} -
- {% else %} -
- {% include 'snippets/repo_dir_data.html' %} -
- {% endif %} - - - {% if user_perm == 'rw' %} -
- - - -
- {% endif %} - -
- {% if no_quota %} -

{% trans "Upload Files" %}

-

{% trans "The owner of this library has run out of space." %}

- - {% else %} - - {% if repo.enc_version == 2 and not server_crypto and repo.encrypted %} -
{% csrf_token %} -

{% trans "Upload Files" %}

-
-

{% trans "Please select a file at first." %}

- -
- - {% else %} -

{% trans "File Upload" %}

-
- - close -
-
-
- -
-

- - {% trans "Saving..." %} -

-
-
- {% endif %} - {% endif %} -
- -
-

{% trans "Update %(file_name)s" %}

- {% if no_quota %} -

{% trans "The owner of this library has run out of space." %}

- {% else %} -
{% csrf_token %} - - - {% if repo.enc_version == 2 and not server_crypto and repo.encrypted %} -
-

{% trans "Please select a file at first." %}

- - {% else %} - -
- - {% trans "Choose a file" %} - - - {% if max_upload_file_size %} - ({% blocktrans with max_file_size=max_upload_file_size|filesizeformat %}Smaller than {{ max_file_size }}{% endblocktrans %}) - {% endif %} -
-
-
-
-
-
-

- - {% trans "Saving..." %} -

-
-
- {% endif %} -
- {% endif %} -
- -
{% csrf_token %} -

{% trans "New Directory" %}

-
-
-

- - -
- -
{% csrf_token %} -

{% trans "New File" %}

- -
-
-

- - -
- -
{% csrf_token %} -
-
{% trans "Current Library"%}
- -
- {% if not repo.encrypted %} -
{% trans "Other Libraries"%}
- -
- {% endif %} -
- - - - - -

{% trans "Please click and choose a directory."%}

- - -
- -
-

-
-

- -
- -
{% csrf_token %} -

{% trans "Rename %(name)s as:" %}

- -
-

- - -
- - {% include "snippets/file_share_popup.html" %} - - {% with attach_type='dir' %} - {% include "snippets/group_recommend_form.html" %} - {% endwith %} - - {% if repo.enc_version == 2 and not server_crypto and repo.encrypted %} -
-

{% trans "This library is encrypted. Please input the password if you want to browse it online. And the password will be kept in the browser for only 1 hour." %}

- - - -

- {% url 'edit_profile' as profile_edit_url %} -

{% blocktrans %}You can change how to view encrypted libraries online here.{% endblocktrans %}

-
- {% endif %} - -
- -
- - {% if groups|length > 1 %} -
-

{% trans "Groups" %}

- {{ repo_group_str }} -
-
- {% endif %} - -{% endblock %} - -{% block extra_script %} -{% if repo.enc_version == 2 and not server_crypto and repo.encrypted %} - -{% else %} - {% if not no_quota and user_perm == 'rw' %} -{% upload_js %} - -{% endif %} -{% endif %} - -{% endblock %} diff --git a/seahub/templates/sysadmin/admin_repo_view.html b/seahub/templates/sysadmin/admin_repo_view.html index 77056a8045..5a3777ed7a 100644 --- a/seahub/templates/sysadmin/admin_repo_view.html +++ b/seahub/templates/sysadmin/admin_repo_view.html @@ -25,8 +25,16 @@ {% endif %} {% endfor %}

-
+ {% if is_default_repo %} +
+
+ {% trans "Upload"%} + +
+
+ {% endif %} +
@@ -49,6 +57,15 @@ {{ dirent.last_modified|translate_seahub_time }} {% endfor %} @@ -67,6 +84,11 @@
+ {% if is_default_repo %} +
+
+ + + +
+
+ {% endif %}
+ {% if is_default_repo %} + + + + {% endif %} @@ -78,9 +100,41 @@
+ {% if is_default_repo %} +
{% csrf_token %} +

{% trans "New Directory" %}

+
+
+

+ + +
+ +
+

{% trans "File Upload" %}

+
+ + close +
+
+
+ +
+

+ + {% trans "Saving..." %} +

+
+
+
+ {% endif %} + {% endblock %} {% block extra_script %} +{% if is_default_repo %} +{% upload_js %} +{% endif %} {% endblock %} diff --git a/seahub/templates/sysadmin/repoadmin_table.html b/seahub/templates/sysadmin/repoadmin_table.html index 0eac76c4be..910bc549f1 100644 --- a/seahub/templates/sysadmin/repoadmin_table.html +++ b/seahub/templates/sysadmin/repoadmin_table.html @@ -15,9 +15,7 @@ {{ repo.props.name }} {% else %} {% trans - {% if repo.is_default_repo %} - {{ repo.props.name }} - {% elif enable_sys_admin_view_repo and is_pro_version %} + {% if enable_sys_admin_view_repo and is_pro_version %} {{ repo.props.name }} {% else %} {{ repo.props.name }} diff --git a/seahub/templates/sysadmin/sys_list_system.html b/seahub/templates/sysadmin/sys_list_system.html index 84358aab1b..20e11091a8 100644 --- a/seahub/templates/sysadmin/sys_list_system.html +++ b/seahub/templates/sysadmin/sys_list_system.html @@ -26,7 +26,7 @@ {% for repo in repos %} - {{ repo.props.name }} + {{ repo.props.name }} {{ repo.id }} {{ repo.props.desc }} diff --git a/seahub/urls.py b/seahub/urls.py index 3d3fa680b9..27f416ea4e 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -8,7 +8,7 @@ from seahub.views.file import view_repo_file, view_history_file, view_trash_file view_snapshot_file, file_edit, view_shared_file, view_file_via_shared_dir,\ text_diff, view_priv_shared_file, view_raw_file, view_raw_shared_file, \ download_file, view_lib_file, file_access -from seahub.views.repo import repo, repo_history_view, view_shared_dir, \ +from seahub.views.repo import repo_history_view, view_shared_dir, \ view_shared_upload_link from notifications.views import notification_list from message.views import user_msg_list, user_msg_remove, user_received_msg_remove @@ -72,7 +72,6 @@ urlpatterns = patterns( url(r'^repo/file_revisions/(?P[-0-9a-f]{36})/$', file_revisions, name='file_revisions'), url(r'^repo/file-access/(?P[-0-9a-f]{36})/$', file_access, name='file_access'), url(r'^repo/text_diff/(?P[-0-9a-f]{36})/$', text_diff, name='text_diff'), - url(r'^repo/(?P[-0-9a-f]{36})/$', repo, name='repo'), url(r'^repo/history/(?P[-0-9a-f]{36})/$', repo_history, name='repo_history'), url(r'^repo/history/view/(?P[-0-9a-f]{36})/$', repo_history_view, name='repo_history_view'), url(r'^repo/recycle/(?P[-0-9a-f]{36})/$', repo_recycle_view, name='repo_recycle_view'), @@ -127,14 +126,11 @@ urlpatterns = patterns( url(r'^choose_register/$', TemplateView.as_view(template_name="choose_register.html"), name="choose_register"), ### Ajax ### - url(r'^ajax/repo/create/$', repo_create, name="repo_create"), (r'^ajax/repo/(?P[-0-9a-f]{36})/remove/$', repo_remove), url(r'^ajax/repo/(?P[-0-9a-f]{36})/dirents/$', get_dirents, name="get_dirents"), url(r'^ajax/repo/(?P[-0-9a-f]{36})/dirents/delete/$', delete_dirents, name='delete_dirents'), url(r'^ajax/repo/(?P[-0-9a-f]{36})/dirents/move/$', mv_dirents, name='mv_dirents'), url(r'^ajax/repo/(?P[-0-9a-f]{36})/dirents/copy/$', cp_dirents, name='cp_dirents'), - url(r'^ajax/repo/(?P[-0-9a-f]{36})/dir/$', list_dir, name='repo_dir_data'), - url(r'^ajax/repo/(?P[-0-9a-f]{36})/dir/more/$', list_dir_more, name='list_dir_more'), url(r'^ajax/repo/(?P[-0-9a-f]{36})/dir/new/$', new_dir, name='new_dir'), url(r'^ajax/repo/(?P[-0-9a-f]{36})/dir/rename/$', rename_dirent, name='rename_dir'), url(r'^ajax/repo/(?P[-0-9a-f]{36})/dir/delete/$', delete_dirent, name='delete_dir'), diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index 22688c5b68..b124143fdc 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -226,93 +226,6 @@ def get_file_download_link(repo_id, obj_id, path): return reverse('download_file', args=[repo_id, obj_id]) + '?p=' + \ urlquote(path) -def get_repo_dirents_with_perm(request, repo, commit, path, offset=-1, limit=-1): - """List repo dirents with perm based on commit id and path. - Use ``offset`` and ``limit`` to do paginating. - - Returns: A tupple of (file_list, dir_list, dirent_more) - - TODO: Some unrelated parts(file sharing, stars, modified info, etc) need - to be pulled out to multiple functions. - """ - - if get_system_default_repo_id() == repo.id: - return get_repo_dirents(request, repo, commit, path, offset, limit) - - dir_list = [] - file_list = [] - dirent_more = False - username = request.user.username - if commit.root_id == EMPTY_SHA1: - return ([], [], False) if limit == -1 else ([], [], False) - else: - try: - dir_id = seafile_api.get_dir_id_by_path(repo.id, path) - if not dir_id: - return ([], [], False) - dirs = seafserv_threaded_rpc.list_dir_with_perm(repo.id, path, - dir_id, username, - offset, limit) - except SearpcError as e: - logger.error(e) - return ([], [], False) - - if limit != -1 and limit == len(dirs): - dirent_more = True - - starred_files = get_dir_starred_files(username, repo.id, path) - fileshares = FileShare.objects.filter(repo_id=repo.id).filter(username=username) - uploadlinks = UploadLinkShare.objects.filter(repo_id=repo.id).filter(username=username) - - view_dir_base = reverse('repo', args=[repo.id]) - dl_dir_base = reverse('repo_download_dir', args=[repo.id]) - view_file_base = reverse('repo_view_file', args=[repo.id]) - file_history_base = reverse('file_revisions', args=[repo.id]) - for dirent in dirs: - dirent.last_modified = dirent.mtime - dirent.sharelink = '' - dirent.uploadlink = '' - if stat.S_ISDIR(dirent.props.mode): - dpath = posixpath.join(path, dirent.obj_name) - if dpath[-1] != '/': - dpath += '/' - for share in fileshares: - if dpath == share.path: - dirent.sharelink = gen_dir_share_link(share.token) - dirent.sharetoken = share.token - break - for link in uploadlinks: - if dpath == link.path: - dirent.uploadlink = gen_shared_upload_link(link.token) - dirent.uploadtoken = link.token - break - p_dpath = posixpath.join(path, dirent.obj_name) - dirent.view_link = view_dir_base + '?p=' + urlquote(p_dpath) - dirent.dl_link = dl_dir_base + '?p=' + urlquote(p_dpath) - dir_list.append(dirent) - else: - file_list.append(dirent) - if repo.version == 0: - dirent.file_size = get_file_size(repo.store_id, repo.version, dirent.obj_id) - else: - dirent.file_size = dirent.size - dirent.starred = False - fpath = posixpath.join(path, dirent.obj_name) - p_fpath = posixpath.join(path, dirent.obj_name) - dirent.view_link = view_file_base + '?p=' + urlquote(p_fpath) - dirent.dl_link = get_file_download_link(repo.id, dirent.obj_id, - p_fpath) - dirent.history_link = file_history_base + '?p=' + urlquote(p_fpath) - if fpath in starred_files: - dirent.starred = True - for share in fileshares: - if fpath == share.path: - dirent.sharelink = gen_file_share_link(share.token) - dirent.sharetoken = share.token - break - - return (file_list, dir_list, dirent_more) - def get_repo_dirents(request, repo, commit, path, offset=-1, limit=-1): """List repo dirents based on commit id and path. Use ``offset`` and ``limit`` to do paginating. @@ -347,7 +260,8 @@ def get_repo_dirents(request, repo, commit, path, offset=-1, limit=-1): fileshares = FileShare.objects.filter(repo_id=repo.id).filter(username=username) uploadlinks = UploadLinkShare.objects.filter(repo_id=repo.id).filter(username=username) - view_dir_base = reverse('repo', args=[repo.id]) + + view_dir_base = reverse("view_common_lib_dir", args=[repo.id, '/']) dl_dir_base = reverse('repo_download_dir', args=[repo.id]) file_history_base = reverse('file_revisions', args=[repo.id]) for dirent in dirs: @@ -922,7 +836,7 @@ def repo_folder_perm(request, repo_id): for folder_perm in user_folder_perms: folder_path = folder_perm.path - folder_perm.folder_link = reverse('repo', args=[repo_id]) + '?p=' + urlquote(folder_path) + folder_perm.folder_link = reverse("view_common_lib_dir", args=[repo_id, urlquote(folder_path).strip('/')]) if folder_path == '/': folder_perm.folder_name = _(u'Root Directory') else: @@ -936,7 +850,7 @@ def repo_folder_perm(request, repo_id): for folder_perm in group_folder_perms: folder_path = folder_perm.path - folder_perm.folder_link = reverse('repo', args=[repo_id]) + '?p=' + urlquote(folder_path) + folder_perm.folder_link = reverse("view_common_lib_dir", args=[repo_id, urlquote(folder_path).strip('/')]) if folder_path == '/': folder_perm.folder_name = _(u'Root Directory') else: @@ -1054,7 +968,7 @@ def repo_history(request, repo_id): return render_error(request, e.msg) if not password_set: - return HttpResponseRedirect(reverse('repo', args=[repo_id])) + return HttpResponseRedirect(reverse("view_common_lib_dir", args=[repo_id, '/'])) try: current_page = int(request.GET.get('page', '1')) @@ -1124,7 +1038,7 @@ def repo_revert_history(request, repo_id): return render_error(request, e.msg) if not password_set: - return HttpResponseRedirect(reverse('repo', args=[repo_id])) + return HttpResponseRedirect(reverse("view_common_lib_dir", args=[repo_id, '/'])) commit_id = request.GET.get('commit_id', '') if not commit_id: @@ -1416,7 +1330,7 @@ def repo_set_access_property(request, repo_id): ap = request.GET.get('ap', '') seafserv_threaded_rpc.repo_set_access_property(repo_id, ap) - return HttpResponseRedirect(reverse('repo', args=[repo_id])) + return HttpResponseRedirect(reverse("view_common_lib_dir", args=[repo_id, '/'])) @login_required def file_upload_progress_page(request): diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py index b464cff428..801851fa15 100644 --- a/seahub/views/ajax.py +++ b/seahub/views/ajax.py @@ -16,11 +16,10 @@ from django.contrib import messages from django.template.defaultfilters import filesizeformat import seaserv -from seaserv import seafile_api, seafserv_rpc, is_passwd_set, \ +from seaserv import seafile_api, is_passwd_set, \ get_related_users_by_repo, get_related_users_by_org_repo, \ CALC_SHARE_USAGE, seafserv_threaded_rpc, ccnet_threaded_rpc, \ - get_user_quota_usage, get_user_share_usage, edit_repo, \ - set_repo_history_limit + edit_repo, set_repo_history_limit from pysearpc import SearpcError from seahub.auth.decorators import login_required_ajax @@ -35,13 +34,9 @@ from seahub.message.models import UserMessage from seahub.share.models import UploadLinkShare from seahub.group.models import PublicGroup from seahub.signals import upload_file_successful, repo_created, repo_deleted -from seahub.views import get_repo_dirents_with_perm, validate_owner, \ - check_repo_access_permission, get_unencry_rw_repos_by_user, \ - get_system_default_repo_id, get_diff, group_events_data, \ - get_owned_repo_list, check_folder_permission, is_registered_user, \ - check_file_lock -from seahub.views.repo import get_nav_path, get_fileshare, get_dir_share_link, \ - get_uploadlink, get_dir_shared_upload_link +from seahub.views import validate_owner, check_repo_access_permission, \ + get_unencry_rw_repos_by_user, get_system_default_repo_id, get_diff, group_events_data, \ + get_owned_repo_list, check_folder_permission, is_registered_user from seahub.views.modules import get_enabled_mods_by_group, \ get_available_mods_by_group, enable_mod_for_group, \ disable_mod_for_group, MOD_GROUP_WIKI, MOD_PERSONAL_WIKI, \ @@ -49,7 +44,7 @@ from seahub.views.modules import get_enabled_mods_by_group, \ from seahub.group.views import is_group_staff import seahub.settings as settings from seahub.settings import ENABLE_THUMBNAIL, THUMBNAIL_ROOT, \ - THUMBNAIL_DEFAULT_SIZE, ENABLE_SUB_LIBRARY, ENABLE_REPO_HISTORY_SETTING, \ + THUMBNAIL_DEFAULT_SIZE, ENABLE_SUB_LIBRARY, \ ENABLE_FOLDER_PERM, SHOW_TRAFFIC, MEDIA_URL from constance import config from seahub.utils import check_filename_with_rename, EMPTY_SHA1, \ @@ -59,7 +54,7 @@ from seahub.utils import check_filename_with_rename, EMPTY_SHA1, \ get_org_user_events, get_user_events, get_file_type_and_ext, \ is_valid_username, send_perm_audit_msg, get_origin_repo_info, is_pro_version from seahub.utils.repo import get_sub_repo_abbrev_origin_path -from seahub.utils.star import star_file, unstar_file +from seahub.utils.star import star_file, unstar_file, get_dir_starred_files from seahub.base.accounts import User from seahub.thumbnail.utils import get_thumbnail_src from seahub.utils.file_types import IMAGE @@ -238,165 +233,6 @@ def unenc_rw_repos(request): repo_list.sort(lambda x, y: cmp(x['name'].lower(), y['name'].lower())) return HttpResponse(json.dumps(repo_list), content_type=content_type) -@login_required_ajax -def list_dir(request, repo_id): - """ - List directory entries in AJAX. - """ - content_type = 'application/json; charset=utf-8' - - repo = get_repo(repo_id) - if not repo: - err_msg = _(u'Library does not exist.') - return HttpResponse(json.dumps({'error': err_msg}), - status=400, content_type=content_type) - - username = request.user.username - user_perm = check_repo_access_permission(repo.id, request.user) - if user_perm is None: - err_msg = _(u'Permission denied.') - return HttpResponse(json.dumps({'error': err_msg}), - status=403, content_type=content_type) - - sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username) - - try: - server_crypto = UserOptions.objects.is_server_crypto(username) - except CryptoOptionNotSetError: - # Assume server_crypto is ``False`` if this option is not set. - server_crypto = False - - if repo.encrypted and \ - (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \ - and not seafile_api.is_password_set(repo.id, username): - err_msg = _(u'Library is encrypted.') - return HttpResponse(json.dumps({'error': err_msg}), - status=403, content_type=content_type) - - head_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id) - if not head_commit: - err_msg = _(u'Error: no head commit id') - return HttpResponse(json.dumps({'error': err_msg}), - status=500, content_type=content_type) - - if new_merge_with_no_conflict(head_commit): - info_commit = get_commit_before_new_merge(head_commit) - else: - info_commit = head_commit - - path = request.GET.get('p', '/') - if path[-1] != '/': - path = path + '/' - - more_start = None - file_list, dir_list, dirent_more = get_repo_dirents_with_perm(request, repo, - head_commit, path, - offset=0, limit=100) - if dirent_more: - more_start = 100 - zipped = get_nav_path(path, repo.name) - fileshare = get_fileshare(repo.id, username, path) - dir_shared_link = get_dir_share_link(fileshare) - uploadlink = get_uploadlink(repo.id, username, path) - dir_shared_upload_link = get_dir_shared_upload_link(uploadlink) - - ctx = { - 'repo': repo, - 'zipped': zipped, - 'user_perm': user_perm, - 'path': path, - 'server_crypto': server_crypto, - 'fileshare': fileshare, - 'dir_shared_link': dir_shared_link, - 'uploadlink': uploadlink, - 'dir_shared_upload_link': dir_shared_upload_link, - 'dir_list': dir_list, - 'file_list': file_list, - 'dirent_more': dirent_more, - 'more_start': more_start, - 'ENABLE_SUB_LIBRARY': ENABLE_SUB_LIBRARY, - 'sub_lib_enabled': sub_lib_enabled, - 'enable_upload_folder': settings.ENABLE_UPLOAD_FOLDER, - 'current_commit': head_commit, - 'info_commit': info_commit, - } - html = render_to_string('snippets/repo_dir_data.html', ctx, - context_instance=RequestContext(request)) - return HttpResponse(json.dumps({'html': html, 'path': path}), - content_type=content_type) - -@login_required_ajax -def list_dir_more(request, repo_id): - """ - List 'more' entries in a directory with AJAX. - """ - content_type = 'application/json; charset=utf-8' - - repo = get_repo(repo_id) - if not repo: - err_msg = _(u'Library does not exist.') - return HttpResponse(json.dumps({'error': err_msg}), - status=400, content_type=content_type) - - username = request.user.username - user_perm = check_repo_access_permission(repo.id, request.user) - if user_perm is None: - err_msg = _(u'Permission denied.') - return HttpResponse(json.dumps({'error': err_msg}), - status=403, content_type=content_type) - - sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username) - - try: - server_crypto = UserOptions.objects.is_server_crypto(username) - except CryptoOptionNotSetError: - # Assume server_crypto is ``False`` if this option is not set. - server_crypto = False - - if repo.encrypted and \ - (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \ - and not seafile_api.is_password_set(repo.id, username): - err_msg = _(u'Library is encrypted.') - return HttpResponse(json.dumps({'error': err_msg}), - status=403, content_type=content_type) - - head_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id) - if not head_commit: - err_msg = _(u'Error: no head commit id') - return HttpResponse(json.dumps({'error': err_msg}), - status=500, content_type=content_type) - - path = request.GET.get('p', '/') - if path[-1] != '/': - path = path + '/' - - offset = int(request.GET.get('start')) - if not offset: - err_msg = _(u'Argument missing') - return HttpResponse(json.dumps({'error': err_msg}), - status=400, content_type=content_type) - more_start = None - file_list, dir_list, dirent_more = get_repo_dirents_with_perm(request, repo, - head_commit, path, - offset, limit=100) - if dirent_more: - more_start = offset + 100 - - ctx = { - 'repo': repo, - 'user_perm': user_perm, - 'path': path, - 'server_crypto': server_crypto, - 'dir_list': dir_list, - 'file_list': file_list, - 'ENABLE_SUB_LIBRARY': ENABLE_SUB_LIBRARY, - 'sub_lib_enabled': sub_lib_enabled, - } - html = render_to_string('snippets/repo_dirents.html', ctx, - context_instance=RequestContext(request)) - return HttpResponse(json.dumps({'html': html, 'dirent_more': dirent_more, 'more_start': more_start}), - content_type=content_type) - @login_required_ajax def list_lib_dir(request, repo_id): ''' @@ -436,9 +272,51 @@ def list_lib_dir(request, repo_id): status=500, content_type=content_type) offset = int(request.GET.get('start', 0)) - file_list, dir_list, dirent_more = get_repo_dirents_with_perm(request, repo, head_commit, path, offset, limit=100) + limit = 100 + dir_list = [] + file_list = [] + dirent_more = False + + try: + dir_id = seafile_api.get_dir_id_by_path(repo.id, path) + except SearpcError as e: + logger.error(e) + err_msg = 'Internal Server Error' + return HttpResponse(json.dumps({'error': err_msg}), + status=500, content_type=content_type) + + if not dir_id: + err_msg = 'Folder not found.' + return HttpResponse(json.dumps({'error': err_msg}), + status=404, content_type=content_type) + + dirs = seafserv_threaded_rpc.list_dir_with_perm(repo_id, path, dir_id, username, offset, limit) + starred_files = get_dir_starred_files(username, repo_id, path) + + for dirent in dirs: + dirent.last_modified = dirent.mtime + if stat.S_ISDIR(dirent.mode): + dpath = posixpath.join(path, dirent.obj_name) + if dpath[-1] != '/': + dpath += '/' + dir_list.append(dirent) + else: + if repo.version == 0: + file_size = seafile_api.get_file_size(repo.store_id, repo.version, dirent.obj_id) + else: + file_size = dirent.size + dirent.file_size = file_size if file_size else 0 + + dirent.starred = False + fpath = posixpath.join(path, dirent.obj_name) + if fpath in starred_files: + dirent.starred = True + + file_list.append(dirent) + more_start = None - if dirent_more: + if limit == len(dirs): + dirent_more = True more_start = offset + 100 if is_org_context(request): @@ -462,8 +340,7 @@ def list_lib_dir(request, repo_id): d_['obj_name'] = d.obj_name d_['last_modified'] = d.last_modified d_['last_update'] = translate_seahub_time(d.last_modified) - p_dpath = posixpath.join(path, d.obj_name) - d_['p_dpath'] = p_dpath # for 'view_link' & 'dl_link' + d_['p_dpath'] = posixpath.join(path, d.obj_name) d_['perm'] = d.permission # perm for sub dir in current dir dirent_list.append(d_) @@ -1072,7 +949,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('repo', args=[dst_repo_id]) + '?p=' + urlquote(dst_path) + url = reverse("view_common_lib_dir", args=[dst_repo_id, urlquote(dst_path).strip('/')]) result = {'success': success, 'failed': failed, 'url': url} return HttpResponse(json.dumps(result), content_type=content_type) @@ -1115,7 +992,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('repo', args=[dst_repo_id]) + '?p=' + urlquote(dst_path) + url = reverse("view_common_lib_dir", args=[dst_repo_id, urlquote(dst_path).strip('/')]) result = {'success': success, 'failed': failed, 'url': url} return HttpResponse(json.dumps(result), content_type=content_type) @@ -1956,69 +1833,6 @@ def _create_repo_common(request, repo_name, repo_desc, encryption, return repo_id -@login_required_ajax -def repo_create(request): - ''' - Handle ajax post to create a library. - - ''' - if request.method != 'POST': - return Http404 - - result = {} - content_type = 'application/json; charset=utf-8' - - if not request.user.permissions.can_add_repo(): - result['error'] = _(u"You do not have permission to create library") - return HttpResponse(json.dumps(result), status=403, - content_type=content_type) - - form = RepoCreateForm(request.POST) - if not form.is_valid(): - result['error'] = str(form.errors.values()[0]) - return HttpResponseBadRequest(json.dumps(result), - content_type=content_type) - - repo_name = form.cleaned_data['repo_name'] - repo_desc = form.cleaned_data['repo_desc'] - encryption = int(form.cleaned_data['encryption']) - - uuid = form.cleaned_data['uuid'] - magic_str = form.cleaned_data['magic_str'] - encrypted_file_key = form.cleaned_data['encrypted_file_key'] - - repo_id = _create_repo_common(request, repo_name, repo_desc, encryption, - uuid, magic_str, encrypted_file_key) - if repo_id is None: - result['error'] = _(u"Internal Server Error") - return HttpResponse(json.dumps(result), status=500, - content_type=content_type) - - username = request.user.username - try: - default_lib = (int(request.GET.get('default_lib', 0)) == 1) - except ValueError: - default_lib = False - if default_lib: - UserOptions.objects.set_default_repo(username, repo_id) - - if is_org_context(request): - org_id = request.user.org.org_id - else: - org_id = -1 - repo_created.send(sender=None, - org_id=org_id, - creator=username, - repo_id=repo_id, - repo_name=repo_name) - result = { - 'repo_id': repo_id, - 'repo_name': repo_name, - 'repo_desc': repo_desc, - 'repo_enc': encryption, - } - return HttpResponse(json.dumps(result), content_type=content_type) - @login_required_ajax def public_repo_create(request): ''' diff --git a/seahub/views/repo.py b/seahub/views/repo.py index 2dd580bb1b..9ddc0c0054 100644 --- a/seahub/views/repo.py +++ b/seahub/views/repo.py @@ -4,12 +4,10 @@ import posixpath import logging from django.core.urlresolvers import reverse -from django.contrib.sites.models import RequestSite from django.db.models import F from django.http import Http404, HttpResponseRedirect from django.shortcuts import render_to_response from django.template import RequestContext -from django.template.loader import render_to_string from django.utils.translation import ugettext as _ from django.utils.http import urlquote @@ -17,28 +15,21 @@ import seaserv from seaserv import seafile_api from seahub.auth.decorators import login_required -from seahub.avatar.templatetags.avatar_tags import avatar -from seahub.avatar.templatetags.group_avatar_tags import grp_avatar -from seahub.contacts.models import Contact -from seahub.forms import RepoPassowrdForm from seahub.options.models import UserOptions, CryptoOptionNotSetError from seahub.share.models import FileShare, UploadLinkShare, \ check_share_link_common from seahub.views import gen_path_link, get_repo_dirents, \ - check_repo_access_permission, get_repo_dirents_with_perm, \ - get_system_default_repo_id + check_repo_access_permission -from seahub.utils import gen_file_upload_url, is_org_context, \ - get_fileserver_root, gen_dir_share_link, gen_shared_upload_link, \ - get_max_upload_file_size, new_merge_with_no_conflict, \ - get_commit_before_new_merge, user_traffic_over_limit, render_error, \ +from seahub.utils import gen_file_upload_url, gen_dir_share_link, \ + gen_shared_upload_link, user_traffic_over_limit, render_error, \ get_file_type_and_ext -from seahub.settings import ENABLE_SUB_LIBRARY, FORCE_SERVER_CRYPTO, \ +from seahub.settings import FORCE_SERVER_CRYPTO, \ ENABLE_UPLOAD_FOLDER, ENABLE_RESUMABLE_FILEUPLOAD, ENABLE_THUMBNAIL, \ THUMBNAIL_ROOT, THUMBNAIL_DEFAULT_SIZE, THUMBNAIL_SIZE_FOR_GRID from seahub.utils import gen_file_get_url from seahub.utils.file_types import IMAGE -from seahub.thumbnail.utils import get_thumbnail_src, get_share_link_thumbnail_src +from seahub.thumbnail.utils import get_share_link_thumbnail_src # Get an instance of a logger logger = logging.getLogger(__name__) @@ -157,157 +148,6 @@ def get_dir_shared_upload_link(uploadlink): dir_shared_upload_link = '' return dir_shared_upload_link -def render_repo(request, repo): - """Steps to show repo page: - If user has permission to view repo - If repo is encrypt and password is not set on server - return decrypt repo page - If repo is not encrypt or password is set on server - Show repo direntries based on requested path - If user does not have permission to view repo - return permission deny page - """ - username = request.user.username - path = get_path_from_request(request) - user_perm = check_repo_access_permission(repo.id, request.user) - if user_perm is None: - return render_error(request, _(u'Permission denied')) - - sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username) - - server_crypto = False - if repo.encrypted: - try: - server_crypto = UserOptions.objects.is_server_crypto(username) - except CryptoOptionNotSetError: - return render_to_response('options/set_user_options.html', { - }, context_instance=RequestContext(request)) - - if (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \ - and not is_password_set(repo.id, username): - return render_to_response('decrypt_repo_form.html', { - 'repo': repo, - 'next': get_next_url_from_request(request) or reverse('repo', args=[repo.id]), - 'force_server_crypto': FORCE_SERVER_CRYPTO, - }, context_instance=RequestContext(request)) - - # query context args - fileserver_root = get_fileserver_root() - max_upload_file_size = get_max_upload_file_size() - - protocol = request.is_secure() and 'https' or 'http' - domain = RequestSite(request).domain - - for g in request.user.joined_groups: - g.avatar = grp_avatar(g.id, 20) - - head_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id) - if not head_commit: - raise Http404 - - if new_merge_with_no_conflict(head_commit): - info_commit = get_commit_before_new_merge(head_commit) - else: - info_commit = head_commit - - repo_size = get_repo_size(repo.id) - no_quota = is_no_quota(repo.id) - if is_org_context(request): - repo_owner = seafile_api.get_org_repo_owner(repo.id) - else: - repo_owner = seafile_api.get_repo_owner(repo.id) - is_repo_owner = True if repo_owner == username else False - if is_repo_owner and not repo.is_virtual: - show_repo_settings = True - else: - show_repo_settings = False - - file_list, dir_list, dirent_more = get_repo_dirents_with_perm( - request, repo, head_commit, path, offset=0, limit=100) - more_start = None - if dirent_more: - more_start = 100 - zipped = get_nav_path(path, repo.name) - repo_groups = get_shared_groups_by_repo_and_user(repo.id, username) - if len(repo_groups) > 1: - repo_group_str = render_to_string("snippets/repo_group_list.html", - {'groups': repo_groups}) - else: - repo_group_str = '' - - fileshare = get_fileshare(repo.id, username, path) - dir_shared_link = get_dir_share_link(fileshare) - uploadlink = get_uploadlink(repo.id, username, path) - dir_shared_upload_link = get_dir_shared_upload_link(uploadlink) - - for f in file_list: - file_type, file_ext = get_file_type_and_ext(f.obj_name) - if file_type == IMAGE: - f.is_img = True - file_path = posixpath.join(path, f.obj_name) - if os.path.exists(os.path.join(THUMBNAIL_ROOT, str(THUMBNAIL_DEFAULT_SIZE), f.obj_id)): - src = get_thumbnail_src(repo.id, THUMBNAIL_DEFAULT_SIZE, file_path) - f.encoded_thumbnail_src = urlquote(src) - - return render_to_response('repo.html', { - 'repo': repo, - 'user_perm': user_perm, - 'repo_owner': repo_owner, - 'is_repo_owner': is_repo_owner, - 'show_repo_settings': show_repo_settings, - 'current_commit': head_commit, - 'info_commit': info_commit, - 'password_set': True, - 'repo_size': repo_size, - 'dir_list': dir_list, - 'file_list': file_list, - 'dirent_more': dirent_more, - 'more_start': more_start, - 'path': path, - 'zipped': zipped, - 'groups': repo_groups, - 'repo_group_str': repo_group_str, - 'no_quota': no_quota, - 'max_upload_file_size': max_upload_file_size, - 'fileserver_root': fileserver_root, - 'protocol': protocol, - 'domain': domain, - 'fileshare': fileshare, - 'dir_shared_link': dir_shared_link, - 'uploadlink': uploadlink, - 'dir_shared_upload_link': dir_shared_upload_link, - 'ENABLE_SUB_LIBRARY': ENABLE_SUB_LIBRARY, - 'server_crypto': server_crypto, - 'sub_lib_enabled': sub_lib_enabled, - 'enable_upload_folder': ENABLE_UPLOAD_FOLDER, - 'ENABLE_THUMBNAIL': ENABLE_THUMBNAIL, - }, context_instance=RequestContext(request)) - -@login_required -def repo(request, repo_id): - """Show repo page and handle POST request to decrypt repo. - """ - repo = get_repo(repo_id) - - if not repo: - raise Http404 - - if request.method == 'GET': - return render_repo(request, repo) - elif request.method == 'POST': - form = RepoPassowrdForm(request.POST) - next = get_next_url_from_request(request) or reverse('repo', - args=[repo_id]) - if form.is_valid(): - return HttpResponseRedirect(next) - else: - return render_to_response('decrypt_repo_form.html', { - 'repo': repo, - 'form': form, - 'next': next, - 'force_server_crypto': FORCE_SERVER_CRYPTO, - }, context_instance=RequestContext(request)) - @login_required def repo_history_view(request, repo_id): """View repo in history. @@ -333,13 +173,13 @@ def repo_history_view(request, repo_id): and not is_password_set(repo.id, username): return render_to_response('decrypt_repo_form.html', { 'repo': repo, - 'next': get_next_url_from_request(request) or reverse('repo', args=[repo.id]), + 'next': get_next_url_from_request(request) or reverse("view_common_lib_dir", args=[repo_id, '/']), 'force_server_crypto': FORCE_SERVER_CRYPTO, }, context_instance=RequestContext(request)) commit_id = request.GET.get('commit_id', None) if commit_id is None: - return HttpResponseRedirect(reverse('repo', args=[repo.id])) + return HttpResponseRedirect(reverse("view_common_lib_dir", args=[repo_id, '/'])) 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 da52201427..4b00d99e7b 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -163,9 +163,7 @@ def sys_repo_admin(request): page_next = False repos = filter(lambda r: not r.is_virtual, repos) - default_repo_id = get_system_default_repo_id() for repo in repos: - repo.is_default_repo = True if repo.id == default_repo_id else False try: repo.owner = seafile_api.get_repo_owner(repo.id) except: @@ -272,6 +270,8 @@ def sys_admin_repo(request, repo_id): file_list.append(dirent) zipped = gen_path_link(path, repo.name) + default_repo_id = get_system_default_repo_id() + is_default_repo = True if repo_id == default_repo_id else False return render_to_response('sysadmin/admin_repo_view.html', { 'repo': repo, @@ -280,6 +280,8 @@ def sys_admin_repo(request, repo_id): 'file_list': file_list, 'path': path, 'zipped': zipped, + 'is_default_repo': is_default_repo, + 'max_upload_file_size': seaserv.MAX_UPLOAD_FILE_SIZE, }, context_instance=RequestContext(request)) @login_required diff --git a/tests/seahub/views/test_list_lib_dir.py b/tests/seahub/views/test_list_lib_dir.py new file mode 100644 index 0000000000..be46797bd1 --- /dev/null +++ b/tests/seahub/views/test_list_lib_dir.py @@ -0,0 +1,24 @@ +import json +import os + +from django.core.urlresolvers import reverse + +from seahub.test_utils import BaseTestCase + +class ListLibDirTest(BaseTestCase): + def setUp(self): + self.login_as(self.user) + self.endpoint = reverse('list_lib_dir', args=[self.repo.id]) + self.folder_name = os.path.basename(self.folder) + + def tearDown(self): + self.remove_repo() + + def test_can_list(self): + resp = self.client.get(self.endpoint, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + self.assertEqual(200, resp.status_code) + + json_resp = json.loads(resp.content) + assert len(json_resp) == 8 + assert self.folder_name == json_resp['dirent_list'][0]['obj_name'] + assert self.repo.name == json_resp['repo_name'] From 262fae05904f94e4fbc7929b09a997f531f0d117 Mon Sep 17 00:00:00 2001 From: llj Date: Mon, 22 Feb 2016 15:44:23 +0800 Subject: [PATCH 2/3] [system repo view] bugfix & improvement; rm unused files --- seahub/templates/snippets/bottom_bar.html | 161 ------------------ seahub/templates/snippets/current_commit.html | 15 -- .../snippets/group_recommend_form.html | 37 ---- seahub/templates/snippets/repo_dir_data.html | 73 -------- seahub/templates/snippets/repo_dirents.html | 98 ----------- .../templates/snippets/repo_group_list.html | 9 - .../templates/sysadmin/admin_repo_view.html | 20 +-- .../templates/sysadmin/sys_list_system.html | 7 - 8 files changed, 10 insertions(+), 410 deletions(-) delete mode 100644 seahub/templates/snippets/bottom_bar.html delete mode 100644 seahub/templates/snippets/current_commit.html delete mode 100644 seahub/templates/snippets/group_recommend_form.html delete mode 100644 seahub/templates/snippets/repo_dir_data.html delete mode 100644 seahub/templates/snippets/repo_dirents.html delete mode 100644 seahub/templates/snippets/repo_group_list.html diff --git a/seahub/templates/snippets/bottom_bar.html b/seahub/templates/snippets/bottom_bar.html deleted file mode 100644 index 127a7100ab..0000000000 --- a/seahub/templates/snippets/bottom_bar.html +++ /dev/null @@ -1,161 +0,0 @@ -{% load i18n %} -{% load url from future %} - -// set 'side toolbar' & 'groups' popup position -function setToolbarPos() { - var toolbar = $('#side-toolbar'); - - // set toolbar pos - toolbar.css({'top': ($(window).height() - toolbar.outerHeight())/2}); - - // set 'groups' popup position - $('#to-group').css({'top': parseInt(toolbar.css('top')) + 59}); -} -$(window).load(function() { - var to_top = $('
  • {% trans
'); - to_top.click(function() { - $(window).scrollTop(0); - }).appendTo($('#side-toolbar')); - $(window).scroll(function() { - if ($(window).scrollTop() > 0) { - to_top.show(); - } else { - to_top.hide(); - } - }); - setToolbarPos(); -}).resize(setToolbarPos); - - -{% if groups %} -function getAndHandleDiscussions(data_html) { - $('#discussions-to-grp').html(data_html).css({'max-height': parseInt($(window).height() * 0.8 - $('#discuss-to-group-form').outerHeight())}).removeClass('hide'); // 'parseInt' to fix '.msg-main top border missing when the ul's max-height is xxx.5px' - var popup = $('#discuss-to-group'); - popup.css({'top':($(window).height() - popup.outerHeight())/2}); - {% include 'group/msg_js.html' %} -} -$('#discuss').click(function() { - var popup = $('#discuss-to-group'), - form = $('#discuss-to-group-form'), - path = '{{ path }}'; - - // for repo.html: when get dir data with ajax - if ($('#repo-file-list').length > 0) { - path = cur_path; - $('[name="path"]', form).val(path); - // modify attachment dir name - $('.att-name', form).html($('#cur-dir-name').html()); - } - - if (popup.hasClass('hide')) { - $.ajax({ - url: form.attr('action'), - dataType: 'json', - data: { - 'repo_id': '{{ repo.id }}', - 'path': path - }, - success: function(data) { - getAndHandleDiscussions(data['html']); - popup.removeClass('hide'); - }, - error: function(jqXHR, textStatus, errorThrown) { - var err_str = ''; - if (jqXHR.responseText) { - err_str = $.parseJSON(jqXHR.responseText).error; - feedback(err_str, 'error'); - } - } - }); - } else { - popup.addClass('hide'); - } -}); - -// click 'close' to close discuss popup -$('#discuss-to-group .close').click(function () { - $('#discuss-to-group').addClass('hide'); -}); - -$(document).click(function(e) { - var target = e.target || event.srcElement; - if (!$('#discuss, #discuss-to-group').is(target) && !($('#discuss, #discuss-to-group').find('*').is(target))) { - $('#discuss-to-group').addClass('hide'); - } -}); - -$('#discuss-submit').click(function() { - var form = $('#discuss-to-group-form'), - form_id = form.attr('id'); - - if (form.find('.checkbox-checked').length == 0) { - apply_form_error(form_id, "{% trans "Please select at least 1 group." %}"); - return false; - } - - if (!$.trim($('#discuss-to-group-form .input').val())) { - apply_form_error(form_id, "{% trans "Please input a discussion." %}"); - return false; - } - form.find('.error').addClass('hide'); - - var groups = []; - form.find('.checkbox-checked .checkbox-orig').each(function() { - groups.push($(this).val()); - }); - - $.ajax({ - url: form.attr('action'), - type: 'POST', - dataType: 'json', - beforeSend: prepareCSRFToken, - traditional: true, - data: { - 'groups': groups, - 'message': $('[name="message"]', form).val(), - 'repo_id': '{{ repo.id }}', - 'path': $('[name="path"]', form).val(), - 'attach_type': $('[name="attach_type"]', form).val() - }, - success: function(data) { - if(data['success']) { - feedback(data['success'], 'success'); - getAndHandleDiscussions(data['html']); - form.find('.input').val(''); - } - if(data['error']) { - feedback(data['error'], 'error'); - } - }, - error: function(jqXHR, textStatus, errorThrown) { - var err_str = ''; - if (jqXHR.responseText) { - err_str = $.parseJSON(jqXHR.responseText).error; - } else { - err_str = "{% trans "Failed. Please check the network." %}"; - } - apply_form_error(form_id, err_str); - } - }); - return false; -}); - -$('#click-into-group').click(function() { - {% if groups|length == 1 %} - // only one group, just turn to group page - {% for group in groups %} - location.href= "{% url 'group_info' group.id %}"; - {% endfor %} - - {% else %} - // more than one group, then let user choose - $('#to-group').toggleClass('hide'); - {% endif %} -}); -$(document).click(function(e) { - var target = e.target || event.srcElement; - if (!$('#click-into-group, #to-group').is(target) && !($('#click-into-group, #to-group').find('*').is(target))) { - $('#to-group').addClass('hide'); - } -}); -{% endif %} diff --git a/seahub/templates/snippets/current_commit.html b/seahub/templates/snippets/current_commit.html deleted file mode 100644 index 5cde50dd48..0000000000 --- a/seahub/templates/snippets/current_commit.html +++ /dev/null @@ -1,15 +0,0 @@ -{% load seahub_tags avatar_tags i18n %} - - {{ info_commit.props.desc|translate_commit_desc }} - {% trans "Details"%} - - - {% if info_commit.props.creator_name %} - {% avatar info_commit.props.creator_name 20 %} - {{ info_commit.creator_name|email2nickname }} - {% else %} - {% trans "Unknown"%} - {% endif %} - {{ info_commit.props.ctime|translate_seahub_time }} - - {% trans "History"%} diff --git a/seahub/templates/snippets/group_recommend_form.html b/seahub/templates/snippets/group_recommend_form.html deleted file mode 100644 index a1c0e02beb..0000000000 --- a/seahub/templates/snippets/group_recommend_form.html +++ /dev/null @@ -1,37 +0,0 @@ -{% load seahub_tags i18n %} -{% load url from future %} -
-
{% csrf_token %} -

{% trans "Post a discussion to group" %}

-
- {% for group in groups %} - - {% endfor %} -
- - - - -

- - - {% if attach_type == 'dir' %} - {% trans 'Directory icon' %} - {% endif %} - - {% for name,link in zipped %} - {% if forloop.last %} - {% if attach_type == 'file' %} - {% trans 'File' %} - {% endif %} - {{ name }} - {% endif %} - {% endfor %} - -
-
    - {% trans -
    diff --git a/seahub/templates/snippets/repo_dir_data.html b/seahub/templates/snippets/repo_dir_data.html deleted file mode 100644 index 04df791eb3..0000000000 --- a/seahub/templates/snippets/repo_dir_data.html +++ /dev/null @@ -1,73 +0,0 @@ -{% load seahub_tags i18n %} -
    -

    - {% for name, link in zipped %} - {% if forloop.first or not forloop.last %} - {{ name }} / - {% else %} - {{ name }} / - {% endif %} - {% endfor %} -

    -
    - {% if user_perm == 'rw' %} - - {% if repo.encrypted and repo.enc_version == 2 and not server_crypto %} - - {% else %} - {% if no_quota %} - - {% else %} -
    - {% trans "Upload"%} - -
    - {% if enable_upload_folder %} -
      -
    • - {% trans "Upload Files" %} - -
    • -
    • - {% trans "Upload Folder" %} - -
    • -
    - {% endif %} - {% endif %} - {% endif %} - - {% if repo.encrypted and repo.enc_version == 2 and not server_crypto %} - {% else %} - - {% endif %} - {% endif %} - - {% if path != '/' %} - {% if not repo.encrypted %} - - {% endif %} - {% endif %} -
    -
    - {% include 'snippets/current_commit.html' %} -
    -
    - - - - - - - - - - - - {% include 'snippets/repo_dirents.html' %} -
    - - {% trans "Name"%} {% trans "Size"%}{% trans "Last Update" %} {% trans "Operations"%}
    -{% if dirent_more %} - -{% endif %} diff --git a/seahub/templates/snippets/repo_dirents.html b/seahub/templates/snippets/repo_dirents.html deleted file mode 100644 index 96b488f91c..0000000000 --- a/seahub/templates/snippets/repo_dirents.html +++ /dev/null @@ -1,98 +0,0 @@ -{% load seahub_tags i18n %} - {% for dirent in dir_list %} - - - - - - {% if dirent.permission = 'r' %} - {% trans - {% else %} - {% trans - {% endif %} - - {{ dirent.obj_name }} - - - - - {{ dirent.last_modified|translate_seahub_time }} - - -
    -
    - - - - {% if not repo.encrypted %} - - - - {% endif %} -
    - {% if user_perm == 'rw' %} - {% trans 'More operations'%} - - {% endif %} -
    - - - {% endfor %} - {% for dirent in file_list %} - - - - - - {% if dirent.starred %} - - {% else %} - - {% endif %} - - - {% trans - - - {% if repo.encrypted and repo.enc_version == 2 and not server_crypto %} - {{ dirent.obj_name }} - {% else %} - {{ dirent.obj_name }} - {% endif %} - - {{ dirent.file_size|filesizeformat }} - - {{ dirent.last_modified|translate_seahub_time }} - - -
    -
    - - - - {% if not repo.encrypted %} - - - - {% endif %} -
    - {% if user_perm == 'rw' %} - {% trans - - {% endif %} -
    - - - {% endfor %} diff --git a/seahub/templates/snippets/repo_group_list.html b/seahub/templates/snippets/repo_group_list.html deleted file mode 100644 index e5e5073f2c..0000000000 --- a/seahub/templates/snippets/repo_group_list.html +++ /dev/null @@ -1,9 +0,0 @@ -{% load url from future %} -{% autoescape off %} - -{% endautoescape %} - diff --git a/seahub/templates/sysadmin/admin_repo_view.html b/seahub/templates/sysadmin/admin_repo_view.html index 5a3777ed7a..4bb189a79a 100644 --- a/seahub/templates/sysadmin/admin_repo_view.html +++ b/seahub/templates/sysadmin/admin_repo_view.html @@ -34,7 +34,7 @@
    {% endif %} -
    +
    @@ -106,7 +106,7 @@

    - + @@ -224,12 +224,14 @@ $(function() { } }) .bind('fileuploadstop', function() { - location.reload(true); + setTimeout(function() { location.reload(true); }, 1000); }) // after tpl has rendered .bind('fileuploadcompleted', function() { // 'done' if ($('.files .cancel', popup).length == 0) { - location.reload(true); + saving_tip.hide(); + total_progress.addClass('hide'); + fu_status.html(fu_status_.complete); } }) .bind('fileuploadfailed', function(e, data) { // 'fail' @@ -301,10 +303,8 @@ $('#add-new-dir').click(function () { $('#add-new-dir-form').submit(function() { var form = $(this), form_id = form.attr('id'), - dirent_name = $.trim(form.find('input[name="name"]').val()), - submit_btn = form.children('input[type="submit"]'), - post_data = {'dirent_name': dirent_name}, - path = '{{path}}'; + dirent_name = $.trim($('[name="name"]', form).val()), + submit_btn = $('[type="submit"]', form); if (!dirent_name) { apply_form_error(form_id, "{% trans "It is required." %}"); @@ -314,11 +314,11 @@ $('#add-new-dir-form').submit(function() { disable(submit_btn); $.ajax({ - url: '{% url 'new_dir' repo.id %}?parent_dir=' + e(path), + url: '{% url 'new_dir' repo.id %}?parent_dir=' + e(cur_path), type: 'POST', dataType: 'json', beforeSend: prepareCSRFToken, - data: post_data, + data: {'dirent_name': dirent_name}, success: function(data) { location.reload(true); }, diff --git a/seahub/templates/sysadmin/sys_list_system.html b/seahub/templates/sysadmin/sys_list_system.html index 20e11091a8..b12a494e39 100644 --- a/seahub/templates/sysadmin/sys_list_system.html +++ b/seahub/templates/sysadmin/sys_list_system.html @@ -2,12 +2,6 @@ {% load i18n %} {% block cur_repo %}tab-cur{% endblock %} -{% block left_panel %}{{block.super}} - - - -{% endblock %} - {% block right_panel %}