From d9dd62e4b2af25d731c71394631f027d1b262263 Mon Sep 17 00:00:00 2001 From: zhengxie Date: Tue, 18 Sep 2018 15:31:14 +0800 Subject: [PATCH 01/14] [sysadmin] refactor traffic stats --- seahub/base/context_processors.py | 4 +- .../templates/snippets/space_and_traffic.html | 4 - .../sysadmin/sys_statistic_traffic.html | 2 - .../templates/sysadmin/sys_trafficadmin.html | 24 ++++- seahub/urls.py | 6 -- seahub/utils/__init__.py | 28 +----- seahub/views/ajax.py | 18 +--- seahub/views/sysadmin.py | 95 +++++++++++-------- 8 files changed, 81 insertions(+), 100 deletions(-) diff --git a/seahub/base/context_processors.py b/seahub/base/context_processors.py index c982b5893e..f48e65f277 100644 --- a/seahub/base/context_processors.py +++ b/seahub/base/context_processors.py @@ -29,8 +29,7 @@ try: except ImportError: SEACLOUD_MODE = False -from seahub.utils import HAS_FILE_SEARCH, EVENTS_ENABLED, \ - TRAFFIC_STATS_ENABLED, is_pro_version +from seahub.utils import HAS_FILE_SEARCH, EVENTS_ENABLED, is_pro_version try: from seahub.settings import ENABLE_PUBFILE @@ -102,7 +101,6 @@ def base(request): 'share_link_password_min_length': config.SHARE_LINK_PASSWORD_MIN_LENGTH, 'repo_password_min_length': config.REPO_PASSWORD_MIN_LENGTH, 'events_enabled': EVENTS_ENABLED, - 'traffic_stats_enabled': TRAFFIC_STATS_ENABLED, 'sysadmin_extra_enabled': ENABLE_SYSADMIN_EXTRA, 'multi_tenancy': MULTI_TENANCY, 'multi_institution': getattr(dj_settings, 'MULTI_INSTITUTION', False), diff --git a/seahub/templates/snippets/space_and_traffic.html b/seahub/templates/snippets/space_and_traffic.html index 4995e478d3..93cadbf3f2 100644 --- a/seahub/templates/snippets/space_and_traffic.html +++ b/seahub/templates/snippets/space_and_traffic.html @@ -13,10 +13,6 @@ {% endif %} -{% if SHOW_TRAFFIC and TRAFFIC_STATS_ENABLED %} -
{% trans "Traffic this month:" %} {{ traffic_stat|filesizeformat }}
-{% endif %} - {% if ENABLE_PAYMENT %} {% trans "Payment" %} {% endif %} diff --git a/seahub/templates/sysadmin/sys_statistic_traffic.html b/seahub/templates/sysadmin/sys_statistic_traffic.html index 0901885b15..9f59979146 100644 --- a/seahub/templates/sysadmin/sys_statistic_traffic.html +++ b/seahub/templates/sysadmin/sys_statistic_traffic.html @@ -17,7 +17,6 @@ -{% if traffic_stats_enabled %} -{% endif %}
diff --git a/seahub/templates/sysadmin/sys_trafficadmin.html b/seahub/templates/sysadmin/sys_trafficadmin.html index 2930fc3b01..7eddb7e8d8 100644 --- a/seahub/templates/sysadmin/sys_trafficadmin.html +++ b/seahub/templates/sysadmin/sys_trafficadmin.html @@ -14,7 +14,6 @@
-{% if traffic_stats_enabled %} -{% endif %}

{% trans "Tip: the traffic only includes the traffic used by sharing links." %}

@@ -35,12 +33,28 @@ - + + + + + + {% for info in traffic_info_list %} - - + {% if info.user %} + + {% elif info.org_id > 0 %} + + {% else%} + + {% endif %} + + + + + + {% endfor %}
{% trans "User" %}{% trans "Total Usage" %}sync-file-uploadsync-file-downloadweb-file-uploadweb-file-downloadlink-file-uploadlink-file-download
{{ info.email }}{{ info.total |filesizeformat }}{{ info.user }}{{ info.org_id }}--{{ info.sync_file_upload|filesizeformat }}{{ info.sync_file_download|filesizeformat }}{{ info.web_file_upload|filesizeformat }}{{ info.web_file_download|filesizeformat }}{{ info.link_file_upload|filesizeformat }}{{ info.link_file_download|filesizeformat }}
diff --git a/seahub/urls.py b/seahub/urls.py index 5029857372..833a842ff1 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -593,12 +593,6 @@ if HAS_OFFICE_CONVERTER: office_convert_get_page, {'cluster_internal': True}), ] -if TRAFFIC_STATS_ENABLED: - from seahub.views.sysadmin import sys_traffic_admin - urlpatterns += [ - url(r'^sys/trafficadmin/$', sys_traffic_admin, name='sys_trafficadmin'), - ] - if getattr(settings, 'ENABLE_ADFS_LOGIN', False): from seahub_extra.adfs_auth.views import assertion_consumer_service, \ auth_complete diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index d9ad667b5c..8694754ab5 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -1181,30 +1181,12 @@ if EVENTS_CONFIG_FILE: HAS_FILE_SEARCH = check_search_enabled() -TRAFFIC_STATS_ENABLED = False -if EVENTS_CONFIG_FILE and hasattr(seafevents, 'get_user_traffic_stat'): - TRAFFIC_STATS_ENABLED = True - def get_user_traffic_stat(username): - session = SeafEventsSession() - try: - stat = seafevents.get_user_traffic_stat(session, username) - finally: - session.close() - return stat - - def get_user_traffic_list(month, start=0, limit=25): - session = SeafEventsSession() - try: - stat = seafevents.get_user_traffic_list(session, month, start, limit) - finally: - session.close() - return stat - +# init Seafevents API +if EVENTS_CONFIG_FILE: + from seafevents import seafevents_api + seafevents_api.init(EVENTS_CONFIG_FILE) else: - def get_user_traffic_stat(username): - pass - def get_user_traffic_list(): - pass + seafevents_api = None # TODO def user_traffic_over_limit(username): """Return ``True`` if user traffic over the limit, otherwise ``False``. diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py index b835209dd8..67fd9b9c8b 100644 --- a/seahub/views/ajax.py +++ b/seahub/views/ajax.py @@ -14,6 +14,7 @@ from django.http import HttpResponse, Http404 from django.template.loader import render_to_string from django.utils.http import urlquote from django.utils.html import escape +from django.utils.timezone import now from django.utils.translation import ugettext as _ from django.conf import settings as dj_settings from django.template.defaultfilters import filesizeformat @@ -39,7 +40,7 @@ import seahub.settings as settings from seahub.settings import ENABLE_THUMBNAIL, THUMBNAIL_ROOT, \ THUMBNAIL_DEFAULT_SIZE, SHOW_TRAFFIC, MEDIA_URL, ENABLE_VIDEO_THUMBNAIL from seahub.utils import check_filename_with_rename, EMPTY_SHA1, \ - gen_block_get_url, TRAFFIC_STATS_ENABLED, get_user_traffic_stat,\ + gen_block_get_url, \ new_merge_with_no_conflict, get_commit_before_new_merge, \ gen_file_upload_url, is_org_context, is_pro_version, normalize_dir_path, \ FILEEXT_TYPE_MAP @@ -1113,19 +1114,6 @@ def space_and_traffic(request): else: # no space quota set in config rates['space_usage'] = '0%' - # traffic calculation - traffic_stat = 0 - if TRAFFIC_STATS_ENABLED: - # User's network traffic stat in this month - try: - stat = get_user_traffic_stat(username) - except Exception as e: - logger.error(e) - stat = None - - if stat: - traffic_stat = stat['file_view'] + stat['file_download'] + stat['dir_download'] - # payment url, TODO: need to remove from here. payment_url = '' ENABLE_PAYMENT = getattr(settings, 'ENABLE_PAYMENT', False) @@ -1147,8 +1135,6 @@ def space_and_traffic(request): "space_usage": space_usage, "rates": rates, "SHOW_TRAFFIC": SHOW_TRAFFIC, - "TRAFFIC_STATS_ENABLED": TRAFFIC_STATS_ENABLED, - "traffic_stat": traffic_stat, "ENABLE_PAYMENT": ENABLE_PAYMENT, "payment_url": payment_url, "user": request.user diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index b376466528..daae13ac48 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -46,10 +46,10 @@ from seahub.role_permissions.utils import get_available_roles, \ from seahub.role_permissions.models import AdminRole from seahub.two_factor.models import default_device from seahub.utils import IS_EMAIL_CONFIGURED, string2list, is_valid_username, \ - is_pro_version, send_html_email, get_user_traffic_list, get_server_id, \ - handle_virus_record, get_virus_record_by_id, \ + is_pro_version, send_html_email, \ + get_server_id, handle_virus_record, get_virus_record_by_id, \ get_virus_record, FILE_AUDIT_ENABLED, get_max_upload_file_size, \ - get_site_name + get_site_name, seafevents_api from seahub.utils.ip import get_remote_ip from seahub.utils.file_size import get_file_size_unit from seahub.utils.ldap import get_ldap_info @@ -146,9 +146,58 @@ def sys_statistic_user(request): @login_required @sys_staff_required def sys_statistic_traffic(request): + req_type = request.GET.get('type', None) + if not req_type: + return render(request, 'sysadmin/sys_statistic_traffic.html', {}) - return render(request, 'sysadmin/sys_statistic_traffic.html', { - }) + try: + current_page = int(request.GET.get('page', '1')) + per_page = int(request.GET.get('per_page', '100')) + except ValueError: + current_page = 1 + per_page = 100 + + month = request.GET.get('month', timezone.now().strftime('%Y%m')) + try: + month_dt = datetime.datetime.strptime(month, '%Y%m') + except ValueError: + month_dt = timezone.now() + + start = per_page * (current_page - 1) + limit = per_page + 1 + + order_by = request.GET.get('order_by', '') + filters = [ + 'user', 'org_id', + 'sync_file_upload', 'sync_file_download', + 'web_file_upload', 'web_file_download', + 'link_file_upload', 'link_file_download', + ] + if order_by not in filters and \ + order_by not in map(lambda x: x + '_desc', filters): + order_by = 'link_file_download_desc' + + if req_type == 'user': + traffic_info_list = seafevents_api.get_all_users_traffic_by_month( + month_dt, start, limit, order_by) + else: + traffic_info_list = seafevents_api.get_all_orgs_traffic_by_month( + month_dt, start, limit, order_by) + for e in traffic_info_list: + e['org_name'] = ccnet_api.get_org_by_id(e['org_id']).org_name + + page_next = len(traffic_info_list) == limit + + return render(request, + 'sysadmin/sys_trafficadmin.html', { + 'traffic_info_list': traffic_info_list[:per_page], + 'month': month, + 'current_page': current_page, + 'prev_page': current_page-1, + 'next_page': current_page+1, + 'per_page': per_page, + 'page_next': page_next, + }) def can_view_sys_admin_repo(repo): default_repo_id = get_system_default_repo_id() @@ -1788,42 +1837,6 @@ def sys_repo_delete(request, repo_id): messages.success(request, _(u'Successfully deleted.')) return HttpResponseRedirect(next) -@login_required -@sys_staff_required -def sys_traffic_admin(request): - """List all users from database. - """ - try: - current_page = int(request.GET.get('page', '1')) - per_page = int(request.GET.get('per_page', '25')) - except ValueError: - current_page = 1 - per_page = 25 - - month = request.GET.get('month', '') - if not re.match(r'[\d]{6}', month): - month = datetime.datetime.now().strftime('%Y%m') - - start = per_page * (current_page -1) - limit = per_page + 1 - traffic_info_list = get_user_traffic_list(month, start, limit) - - page_next = len(traffic_info_list) == limit - - for info in traffic_info_list: - info['total'] = info['file_view'] + info['file_download'] + info['dir_download'] - - return render(request, - 'sysadmin/sys_trafficadmin.html', { - 'traffic_info_list': traffic_info_list, - 'month': month, - 'current_page': current_page, - 'prev_page': current_page-1, - 'next_page': current_page+1, - 'per_page': per_page, - 'page_next': page_next, - }) - @login_required @sys_staff_required def sys_virus_scan_records(request): From 0620273992edf41c9e069b529ead70b3a444370d Mon Sep 17 00:00:00 2001 From: llj Date: Thu, 20 Sep 2018 15:20:40 +0800 Subject: [PATCH 02/14] [system admin] user/org monthly traffic: modification Conflicts: seahub/templates/sysadmin/sys_trafficadmin.html --- .../sysadmin/sys_statistic_traffic.html | 7 +- .../templates/sysadmin/sys_trafficadmin.html | 136 +++++++++++++----- seahub/views/sysadmin.py | 2 + 3 files changed, 110 insertions(+), 35 deletions(-) diff --git a/seahub/templates/sysadmin/sys_statistic_traffic.html b/seahub/templates/sysadmin/sys_statistic_traffic.html index 9f59979146..c05dda0af2 100644 --- a/seahub/templates/sysadmin/sys_statistic_traffic.html +++ b/seahub/templates/sysadmin/sys_statistic_traffic.html @@ -19,10 +19,13 @@ diff --git a/seahub/templates/sysadmin/sys_trafficadmin.html b/seahub/templates/sysadmin/sys_trafficadmin.html index 7eddb7e8d8..7fc4ba31f3 100644 --- a/seahub/templates/sysadmin/sys_trafficadmin.html +++ b/seahub/templates/sysadmin/sys_trafficadmin.html @@ -16,47 +16,90 @@ -

{% trans "Tip: the traffic only includes the traffic used by sharing links." %}

- -
+ +
- - - - - - - - - - {% for info in traffic_info_list %} - - {% if info.user %} - - {% elif info.org_id > 0 %} - - {% else%} - - {% endif %} - - - - - - - - {% endfor %} + + + + + + + + + + + + + + {% for info in traffic_info_list %} + + + + + + + + + + {% endfor %} +
{% trans "User" %}sync-file-uploadsync-file-downloadweb-file-uploadweb-file-downloadlink-file-uploadlink-file-download
{{ info.user }}{{ info.org_id }}--{{ info.sync_file_upload|filesizeformat }}{{ info.sync_file_download|filesizeformat }}{{ info.web_file_upload|filesizeformat }}{{ info.web_file_download|filesizeformat }}{{ info.link_file_upload|filesizeformat }}{{ info.link_file_download|filesizeformat }}
+ {% if type == 'user' %} + {% trans "User" %} + {% else %} + {% trans "Organization" %} + {% endif %} + + + {% trans "Sync Upload" %} + + + + + {% trans "Sync Download" %} + + + + + {% trans "Web Upload" %} + + + + + {% trans "Web Download" %} + + + + + {% trans "Share link upload" %} + + + + + {% trans "Share link download" %} + + +
+ {% if info.user %} + {{ info.user }} + {% else%} + {{ info.org_name }} + {% endif %} + {{ info.sync_file_upload|filesizeformat }}{{ info.sync_file_download|filesizeformat }}{{ info.web_file_upload|filesizeformat }}{{ info.web_file_download|filesizeformat }}{{ info.link_file_upload|filesizeformat }}{{ info.link_file_download|filesizeformat }}
@@ -91,8 +134,35 @@ {% block extra_script %} {% endblock %} diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index daae13ac48..6dc23bf3d8 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -190,6 +190,8 @@ def sys_statistic_traffic(request): return render(request, 'sysadmin/sys_trafficadmin.html', { + 'type': req_type, + 'order_by': order_by, 'traffic_info_list': traffic_info_list[:per_page], 'month': month, 'current_page': current_page, From b6abdd61322b4906469d4b2065c25f3fd4ac2823 Mon Sep 17 00:00:00 2001 From: zhengxie Date: Thu, 27 Sep 2018 15:23:55 +0800 Subject: [PATCH 03/14] [sys] Update traffic admin and user_traffic_over_limit func --- .../templates/sysadmin/sys_statistic_traffic.html | 6 +++--- seahub/templates/sysadmin/sys_trafficadmin.html | 14 ++++++++------ seahub/utils/__init__.py | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/seahub/templates/sysadmin/sys_statistic_traffic.html b/seahub/templates/sysadmin/sys_statistic_traffic.html index c05dda0af2..cdc318d105 100644 --- a/seahub/templates/sysadmin/sys_statistic_traffic.html +++ b/seahub/templates/sysadmin/sys_statistic_traffic.html @@ -19,13 +19,13 @@ diff --git a/seahub/templates/sysadmin/sys_trafficadmin.html b/seahub/templates/sysadmin/sys_trafficadmin.html index 7fc4ba31f3..dcb3bf3701 100644 --- a/seahub/templates/sysadmin/sys_trafficadmin.html +++ b/seahub/templates/sysadmin/sys_trafficadmin.html @@ -16,13 +16,13 @@ @@ -85,10 +85,12 @@ {% for info in traffic_info_list %} - {% if info.user %} - {{ info.user }} - {% else%} + {% if info.org_id > 0 %} {{ info.org_name }} + {% elif info.user %} + {{ info.user|email2nickname }} + {% else %} + -- {% endif %} {{ info.sync_file_upload|filesizeformat }} diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 8694754ab5..7045f6a953 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -1201,7 +1201,7 @@ def user_traffic_over_limit(username): traffic_limit = int(PLAN[plan]['share_link_traffic']) * 1024 * 1024 * 1024 try: - stat = get_user_traffic_stat(username) + stat = seafevents_api.get_user_traffic_by_month(username, datetime.now()) except Exception as e: logger = logging.getLogger(__name__) logger.error('Failed to get user traffic stat: %s' % username, @@ -1211,7 +1211,7 @@ def user_traffic_over_limit(username): if stat is None: # No traffic record yet return False - month_traffic = stat['file_view'] + stat['file_download'] + stat['dir_download'] + month_traffic = stat['link_file_upload'] + stat['link_file_download'] return True if month_traffic >= traffic_limit else False def is_user_password_strong(password): From ddcd19a4a65233daaf7c2af175a01615f4e06ff9 Mon Sep 17 00:00:00 2001 From: zhengxie Date: Mon, 8 Oct 2018 10:58:50 +0800 Subject: [PATCH 04/14] Upgrade rest_framework to 3.3.3 to fix html render error in web api ref: https://forum.seafile.com/t/6-3-6-pro-api-broken-user-feedback-as-i-go/7356/5 --- requirements.txt | 2 +- tests/api/test_ping.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/api/test_ping.py diff --git a/requirements.txt b/requirements.txt index 551b33d70a..a178fbbf0c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ Django==1.11.15 django-compressor==2.2 django-post-office==3.0.4 django-statici18n==1.7.0 -djangorestframework==3.3.1 +djangorestframework==3.3.3 git+git://github.com/haiwen/django-constance.git@8508ff29141732190faff51d5c2b5474da297732#egg=django-constance[database] openpyxl==2.3.0 pytz==2015.7 diff --git a/tests/api/test_ping.py b/tests/api/test_ping.py new file mode 100644 index 0000000000..da46c58647 --- /dev/null +++ b/tests/api/test_ping.py @@ -0,0 +1,11 @@ +from seahub.test_utils import BaseTestCase + +class PingTest(BaseTestCase): + def test_can_ping(self): + resp = self.client.get('/api2/ping/') + self.assertEqual(200, resp.status_code) + + def test_html_ping(self): + headers = {'HTTP_ACCEPT': 'text/html'} + resp = self.client.get('/api2/ping/', **headers) + self.assertEqual(200, resp.status_code) From 2569768471091a01f118a2a3ad56bed613ca6f47 Mon Sep 17 00:00:00 2001 From: lian Date: Mon, 8 Oct 2018 13:49:53 +0800 Subject: [PATCH 05/14] update shared repos api (#2424) add 'encrypted' field --- seahub/api2/endpoints/shared_repos.py | 1 + 1 file changed, 1 insertion(+) diff --git a/seahub/api2/endpoints/shared_repos.py b/seahub/api2/endpoints/shared_repos.py index ba49337629..bd6917597d 100644 --- a/seahub/api2/endpoints/shared_repos.py +++ b/seahub/api2/endpoints/shared_repos.py @@ -65,6 +65,7 @@ class SharedRepos(APIView): result = {} result['repo_id'] = repo.repo_id result['repo_name'] = repo.repo_name + result['encrypted'] = repo.encrypted result['share_type'] = repo.share_type result['share_permission'] = repo.permission result['modifier_email'] = repo.last_modifier From a0e62bfacb154da416581670c4dc3b9ae8ab6b79 Mon Sep 17 00:00:00 2001 From: llj Date: Mon, 8 Oct 2018 17:01:10 +0800 Subject: [PATCH 06/14] [system admin] statistic: modified text for 'Storage' (#2426) --- seahub/templates/sysadmin/sys_statistic_storage.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seahub/templates/sysadmin/sys_statistic_storage.html b/seahub/templates/sysadmin/sys_statistic_storage.html index b9a389295b..8411b39ff5 100644 --- a/seahub/templates/sysadmin/sys_statistic_storage.html +++ b/seahub/templates/sysadmin/sys_statistic_storage.html @@ -169,7 +169,7 @@ function renderChart(data, group_by) { labels: labels, datasets: [ { - label: "{% trans "Total storage" %}", + label: "{% trans "Total Storage" %}", data: storage, borderColor: '#fd913a', backgroundColor: '#fd913a' @@ -181,7 +181,7 @@ function renderChart(data, group_by) { display: true, fontSize: 14, padding: 20, - text: "{% trans "Total storage" %}" + text: "{% trans "Total Storage" %}" }, elements: { line: { From d424848be716483ee4609207cd361a6c9200e305 Mon Sep 17 00:00:00 2001 From: lian Date: Tue, 9 Oct 2018 14:03:58 +0800 Subject: [PATCH 07/14] add more log when set cache value for OOS --- seahub/wopi/utils.py | 12 +++++++++--- seahub/wopi/views.py | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/seahub/wopi/utils.py b/seahub/wopi/utils.py index 0e49aab51f..d302c1c36c 100644 --- a/seahub/wopi/utils.py +++ b/seahub/wopi/utils.py @@ -30,7 +30,6 @@ from seahub.settings import ENABLE_WATERMARK logger = logging.getLogger(__name__) - def generate_access_token_cache_key(token): """ Generate cache key for WOPI access token """ @@ -44,7 +43,12 @@ def get_file_info_by_token(token): """ key = generate_access_token_cache_key(token) - return cache.get(key) if cache.get(key) else {} + value = cache.get(key) + if not value: + logger.error('No wopi cache value when first get %s' % key) + value = cache.get(key) + + return value if value else None def generate_discovery_cache_key(name, ext): """ Generate cache key for office web app hosting discovery @@ -200,7 +204,9 @@ def get_wopi_dict(request_user, repo_id, file_path, uid = uuid.uuid4() access_token = uid.hex key = generate_access_token_cache_key(access_token) - cache.set(key, user_repo_path_info, WOPI_ACCESS_TOKEN_EXPIRATION) + if not cache.set(key, user_repo_path_info, WOPI_ACCESS_TOKEN_EXPIRATION): + logger.error('Set wopi cache failed, key: %s' % key) + return None # access_token_ttl property tells office web app # when access token expires diff --git a/seahub/wopi/views.py b/seahub/wopi/views.py index 282537e521..463b36385b 100644 --- a/seahub/wopi/views.py +++ b/seahub/wopi/views.py @@ -85,6 +85,11 @@ def access_token_check(func): content_type=json_content_type) info_dict = get_file_info_by_token(token) + if not info_dict: + logger.error('Get wopi cache value failed: wopi_access_token_%s.' % token) + return HttpResponse(json.dumps({}), status=404, + content_type=json_content_type) + request_user = info_dict['request_user'] repo_id = info_dict['repo_id'] file_path= info_dict['file_path'] From 11a0f4fd2ac899abbb83ba8e17a91d17d920f48c Mon Sep 17 00:00:00 2001 From: llj Date: Wed, 10 Oct 2018 13:51:09 +0800 Subject: [PATCH 08/14] [file view] removed 'share' (#2435) --- .../templates/snippets/file_share_popup.html | 68 ----- seahub/templates/snippets/shared_link_js.html | 249 ------------------ seahub/templates/view_file_base.html | 42 --- 3 files changed, 359 deletions(-) delete mode 100644 seahub/templates/snippets/file_share_popup.html delete mode 100644 seahub/templates/snippets/shared_link_js.html diff --git a/seahub/templates/snippets/file_share_popup.html b/seahub/templates/snippets/file_share_popup.html deleted file mode 100644 index b4e831796e..0000000000 --- a/seahub/templates/snippets/file_share_popup.html +++ /dev/null @@ -1,68 +0,0 @@ -{% load i18n %} -
-

{% trans 'Share %(name)s' %}

- -
- diff --git a/seahub/templates/snippets/shared_link_js.html b/seahub/templates/snippets/shared_link_js.html deleted file mode 100644 index 1b6c6e2263..0000000000 --- a/seahub/templates/snippets/shared_link_js.html +++ /dev/null @@ -1,249 +0,0 @@ -{% load i18n %} - - -function showSharePopup(op, name, aj_data, type, cur_path) { - var path = cur_path + name; - - var form = $('#file-share'); - var modal = form.modal({appendTo: "#main", focus:false}); - - var hd = $('#file-share .hd'); - hd.html(hd.html().replace('%(name)s', '' + HTMLescape(trimFilename(name, 30)) + '')); - - $("#file-share-tabs").tabs(); - - // share link - if (op.attr('data-link')) { - $('#gen-link-btn, #link-options').addClass('hide'); - $('#share-link-body').removeClass('hide'); - var link = op.attr('data-link'); - $('#shared-link-text, #link-send-form input[name="file_shared_link"]').val(link); - $('#main').append('

' + link + '

'); - $('#shared-link-text').css({'width':$('#linkwidth').width() + 25}); - $('#linkwidth').remove(); - } else { - $('#gen-link-btn, #link-options').removeClass('hide'); - $('#share-link-body').addClass('hide'); - } - $('#gen-link-btn').data('aj_data', aj_data).data('obj', op); - $('#rm-shared-link').data('obj', op); - $('input[name="file_shared_name"]').val(name); - $('input[name="file_shared_type"]').val(type); - - $('#simplemodal-container').css({'height':'auto', 'width':'auto'}); - modal.setPosition(); -} - -$('#send-link').on('click', function() { - $(this).addClass('hide'); - $('#rm-shared-link').addClass('hide'); - var input = $('#link-send-input'); - input.css({'width': $('#link-share').width() - parseInt(input.css('padding-left')) - parseInt(input.css('padding-right')) - parseInt(input.css('border-left-width')) - parseInt(input.css('border-right-width'))}); - var text = $('#download-extra-msg-text'); - text.css({'width': $('#link-share').width() - parseInt(text.css('padding-left')) - parseInt(text.css('padding-right')) - parseInt(text.css('border-left-width')) - parseInt(text.css('border-right-width'))}); - $('#link-send-form').removeClass('hide'); - //addAutocomplete('#link-send-input', '#link-send-form', share_list); -}); - -$("#link-send-form .cancel").on('click', function() { - $('#link-send-form, #send-link, #rm-shared-link').toggleClass('hide'); -}); - -$("#link-send-form").on('submit', function(event) { - var form = $(this), - file_shared_link = form.children('input[name="file_shared_link"]').val(), - email = $.trim(form.children('input[name="email"]').val()), - submit_btn = form.children('input[type="submit"]'), - extra_msg = form.children('textarea[name="extra_msg"]').val(), - file_shared_name = form.children('input[name="file_shared_name"]').val(), - file_shared_type = form.children('input[name="file_shared_type"]').val(); - - if (!email) { - apply_form_error('link-send-form', "{% trans "Please input at least an email." %}"); - return false; - } - - disable(submit_btn); - $('#link-send-form .error').addClass('hide'); - $('#sending').removeClass('hide'); - - $.ajax({ - type: "POST", - url: "{% url 'send_shared_link' %}", - dataType: 'json', - cache: false, - beforeSend: prepareCSRFToken, - data: { - file_shared_link: file_shared_link, - email: email, - extra_msg: extra_msg, - file_shared_name: file_shared_name, - file_shared_type: file_shared_type - }, - success: function(data) { - $.modal.close(); - var msg = "{% trans "Successfully sent to {placeholder}" %}" - .replace('{placeholder}', data['send_success'].join(', ')); - feedback(msg, "success"); - if (data['send_failed'].length > 0) { - msg += '
' + "{% trans "Failed to send to {placeholder}" %}" - .replace('{placeholder}', data['send_failed'].join(', ')); - feedback(msg, 'info'); - } - }, - error: function(xhr, textStatus, errorThrown) { - $('#sending').addClass('hide'); - enable(submit_btn); - var err_str = ''; - if (xhr.responseText) { - var err = JSON.parse(xhr.responseText); - if (err.error) { - err_str = err.error; - } else { - for (var i in err) { - err_str += err[i]; - } - } - } else { - err_str = "{% trans "Failed. Please check the network." %}"; - } - apply_form_error('link-send-form', err_str); - } - }); - return false; -}); - -$('#shared-link-text').on('click', function() { - $(this).trigger('select'); -}); - -$('#gen-link-btn').on('click', function() { - var gen_link_btn = $(this), - obj = gen_link_btn.data('obj'), - form = $('#link-options'), - form_id = form.attr('id'), - use_passwd = $('#link-passwd-switch').prop('checked'), - set_expiration = $('#link-expire-switch').prop('checked'), - preview_only = $('[name="preview_only"]', form).prop('checked'), - password, password_again, expire_days, - post_data = {}; - - if (use_passwd) { - password = $('input[name="password"]', form).val(); - password_again = $('input[name="password_again"]', form).val(); - - if (!$.trim(password)) { - apply_form_error(form_id, "{% trans "Please enter password" %}"); - return false; - } - if ($.trim(password).length < {{share_link_password_min_length}}) { - apply_form_error(form_id, "{% trans "Password is too short" %}"); - return false; - } - if (!$.trim(password_again)) { - apply_form_error(form_id, "{% trans "Please enter the password again" %}"); - return false; - } - if ($.trim(password) != $.trim(password_again)) { - apply_form_error(form_id, "{% trans "Passwords don't match" %}"); - return false; - } - post_data['password'] = password; - } - - if (set_expiration) { - expire_days = $('input[name="expire-days"]', form).val(); - if (!$.trim(expire_days)) { - apply_form_error(form_id, "{% trans "Please enter days" %}"); - return false; - } - if (Math.floor(expire_days) == expire_days && $.isNumeric(expire_days)) { - post_data["expire_days"] = expire_days; - } else { - apply_form_error(form_id, "{% trans "Please enter valid days" %}"); - return false; - } - } - - if (preview_only) { - post_data["permissions"] = JSON.stringify({ - "can_preview": true, - "can_download": false - }); - } - - $.ajax({ - url: '{% url 'api-v2.1-share-links' %}', - type: 'POST', - dataType: 'json', - beforeSend: prepareCSRFToken, - data: $.extend(post_data, $(this).data('aj_data')), - success: function(data) { - var link = data['link']; - // hide gen-link button, and show link - gen_link_btn.addClass('hide'); - - $('#link-options, #link-options .error').addClass('hide'); - $('#link-passwd, #link-expire').hide(); // slideDown use 'show()' - $('#link-passwd-switch, #link-expire-switch').prop('checked', false); - $('[type="password"], [name="expire-days"]', form).val('').attr('disabled', false).removeClass('input-disabled'); - $('[name="preview_only"]', form).prop('checked', false); - - $('#shared-link-text, #link-send-form input[name="file_shared_link"]').val(link); - $('#main').append('

' + link + '

'); - $('#shared-link-text').css({'width':$('#linkwidth').width() + 25}); - $('#linkwidth').remove(); - $('#share-link-body').removeClass('hide'); - obj.attr({'data-link': link, 'data-token':data['token']}); - }, - error:ajaxErrorHandler - }); - return false; -}); - -$('#rm-shared-link').on('click', function() { - var obj = $(this).data('obj'), - token = obj.attr('data-token'); - - $.ajax({ - url: '{{ SITE_ROOT }}api/v2.1/share-links/' + token + '/', - type: 'DELETE', - dataType: 'json', - cache: false, - beforeSend: prepareCSRFToken, - success: function(data) { - $('#share-link-body').addClass('hide'); - $('#link-options, #gen-link-btn').removeClass('hide'); - obj.attr({'data-link':'', 'data-token':''}); - }, - error: ajaxErrorHandler - }); -}); - -$('#link-passwd-switch').on('click', function () { - var form = $('#link-options'), - pwd_input = $('input[type="password"]', form); - var link_passwd = $('#link-passwd'); - - if ($(this).prop('checked')) { - pwd_input.attr('disabled', false).removeClass('input-disabled'); - link_passwd.slideDown(100); - } else { - link_passwd.slideUp(100); - pwd_input.attr('disabled', true).addClass('input-disabled'); - } -}); - -$('#link-expire-switch').on('click', function () { - var form = $('#link-options'), - days_input = $('input[name="expire-days"]', form); - var link_expire = $('#link-expire'); - - if ($(this).prop('checked')) { - link_expire.slideDown(100); - days_input.attr('disabled', false).removeClass('input-disabled'); - } else { - link_expire.slideUp(100); - days_input.attr('disabled', true).addClass('input-disabled'); - } -}); diff --git a/seahub/templates/view_file_base.html b/seahub/templates/view_file_base.html index 1fd220373c..4fb0b1018c 100644 --- a/seahub/templates/view_file_base.html +++ b/seahub/templates/view_file_base.html @@ -87,8 +87,6 @@
- {% include "snippets/file_share_popup.html" %} -
  • {% trans
  • @@ -155,12 +153,6 @@ {% endif %} {% endif %} - {% if not repo.encrypted %} - {% if request.user.permissions.can_generate_share_link %} - - {% endif %} - {% endif %} - {% if file_perm == 'rw' %} {% endif %} @@ -205,14 +197,6 @@ {% endif %} {% endif %} - {% if not repo.encrypted %} - {% if request.user.permissions.can_generate_share_link %} -
  • - -
  • - {% endif %} - {% endif %} - {% if file_perm == 'rw' %}
  • {% trans "History" %} @@ -230,7 +214,6 @@ {% endblock %} {% block extra_script %} - {# for 'tabs' used in share popup #} @@ -238,9 +221,6 @@ {% endif %}