From 7bc56361b69e70e2904760d79cf986cb6e0c689b Mon Sep 17 00:00:00 2001 From: zhengxie Date: Mon, 10 Dec 2018 11:01:46 +0800 Subject: [PATCH 1/6] [thumbnail] Update psd_tools import --- seahub/thumbnail/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/seahub/thumbnail/utils.py b/seahub/thumbnail/utils.py index e9826f6a91..3cfb5e126d 100644 --- a/seahub/thumbnail/utils.py +++ b/seahub/thumbnail/utils.py @@ -145,6 +145,13 @@ def generate_thumbnail(request, repo_id, size, path): return (False, 500) def create_psd_thumbnails(repo, file_id, path, size, thumbnail_file, file_size): + try: + from psd_tools import PSDImage + except ImportError: + logger.error("Could not find psd_tools installed. " + "Please install by 'pip install psd_tools'") + return (False, 500) + token = seafile_api.get_fileserver_access_token( repo.id, file_id, 'view', '', use_onetime=False) if not token: @@ -153,8 +160,6 @@ def create_psd_thumbnails(repo, file_id, path, size, thumbnail_file, file_size): tmp_img_path = str(os.path.join(tempfile.gettempdir(), '%s.png' % file_id)) t1 = timeit.default_timer() - from psd_tools import PSDImage - inner_path = gen_inner_file_get_url(token, os.path.basename(path)) tmp_file = os.path.join(tempfile.gettempdir(), file_id) urlretrieve(inner_path, tmp_file) From 665671461c9b47c8b1affb50f789f821608574c5 Mon Sep 17 00:00:00 2001 From: lian Date: Fri, 14 Dec 2018 12:39:56 +0800 Subject: [PATCH 2/6] update get event typy --- seahub/utils/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 0e023fa369..9cb8722347 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -666,13 +666,20 @@ if EVENTS_CONFIG_FILE: return events if events else None def generate_file_audit_event_type(e): - return { + + event_type_dict = { 'file-download-web': ('web', ''), 'file-download-share-link': ('share-link',''), 'file-download-api': ('API', e.device), 'repo-download-sync': ('download-sync', e.device), 'repo-upload-sync': ('upload-sync', e.device), - }[e.etype] + 'seadrive-download-file': ('seadrive-download', e.device), + } + + if not event_type_dict.has_key(e.etype): + event_type_dict[e.etype] = (e.etype, '') + + return event_type_dict[e.etype] def get_file_audit_events_by_path(email, org_id, repo_id, file_path, start, limit): """Return file audit events list by file path. (If no file audit, return 'None') From 8497f075dbbbb7fbbb67bc05cc2e334ff322eb19 Mon Sep 17 00:00:00 2001 From: lian Date: Mon, 17 Dec 2018 16:29:34 +0800 Subject: [PATCH 3/6] add test for get file audit event type/device --- seahub/utils/__init__.py | 2 +- .../test_generate_file_audit_event_type.py | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/seahub/utils/test_generate_file_audit_event_type.py diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 9cb8722347..6cad04ac1c 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -677,7 +677,7 @@ if EVENTS_CONFIG_FILE: } if not event_type_dict.has_key(e.etype): - event_type_dict[e.etype] = (e.etype, '') + event_type_dict[e.etype] = (e.etype, e.device if e.device else '') return event_type_dict[e.etype] diff --git a/tests/seahub/utils/test_generate_file_audit_event_type.py b/tests/seahub/utils/test_generate_file_audit_event_type.py new file mode 100644 index 0000000000..9227cbebd0 --- /dev/null +++ b/tests/seahub/utils/test_generate_file_audit_event_type.py @@ -0,0 +1,36 @@ +from seahub.test_utils import BaseTestCase +from seahub.utils import generate_file_audit_event_type + +class Events(): + + def __init__(self, etype, device): + self.etype = etype + self.device = device + + +class GenerateFileAuditEventTypeTest(BaseTestCase): + + def test_generate_file_audit_event_type(self): + + event_type_device = { + 'file-download-web': '', + 'file-download-share-link': '', + 'file-download-api': 'file-download-api-device', + 'repo-download-sync': 'repo-download-sync-device', + 'repo-upload-sync': 'repo-upload-sync-device', + 'seadrive-download-file': 'seadrive-download-file-device', + 'unknow-type-has-device': 'has-device', + 'unknow-type-no-device': '', + } + + for key,value in event_type_device.items(): + + e = Events(key, value) + + assert generate_file_audit_event_type(e)[1] == value + + if e.etype == 'unknow-type-has-device': + assert generate_file_audit_event_type(e)[1] == 'has-device' + + if e.etype == 'unknow-type-no-device': + assert generate_file_audit_event_type(e)[1] == '' From f8d31dd0fe3a0136df2f7651ad11847f75dce653 Mon Sep 17 00:00:00 2001 From: lian Date: Tue, 18 Dec 2018 13:53:04 +0800 Subject: [PATCH 4/6] fix bug when org user create public repo --- seahub/base/accounts.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/seahub/base/accounts.py b/seahub/base/accounts.py index 3b4db56a6d..a9737c590f 100644 --- a/seahub/base/accounts.py +++ b/seahub/base/accounts.py @@ -156,7 +156,10 @@ class UserPermissions(object): """ if CLOUD_MODE: - return False + if MULTI_TENANCY: + return True + else: + return False elif self.user.is_staff: return True elif get_enabled_role_permissions_by_role(self.user.role)['can_add_public_repo']: From f22a6715a3b35a0272713141a3652f9213cbe212 Mon Sep 17 00:00:00 2001 From: llj Date: Wed, 19 Dec 2018 14:49:25 +0800 Subject: [PATCH 5/6] [dir view] show 'leaving page' confirm popup when a file is uploading (#2612) --- static/scripts/app/router.js | 65 ++++++++++++++++++++------ static/scripts/app/views/dir.js | 8 ++++ static/scripts/app/views/fileupload.js | 2 + 3 files changed, 61 insertions(+), 14 deletions(-) diff --git a/static/scripts/app/router.js b/static/scripts/app/router.js index b0b342098a..2baf222570 100644 --- a/static/scripts/app/router.js +++ b/static/scripts/app/router.js @@ -130,10 +130,19 @@ define([ this.currentView = newView; } else { if (this.currentView != newView) { + if (this.currentView == this.dirView) { + if ($('#upload-file-dialog').is(':visible') && + $('#upload-file-dialog .status').text() == window.fileuploading) { + if (!window.confirm('A file is being uploaded. Are you sure you want to leave this page?')) { + return false; + } + } + } this.currentView.hide(); this.currentView = newView; } } + return true; }, showRepos: function() { @@ -145,19 +154,25 @@ define([ }, showMyRepos: function() { - this.switchCurrentView(this.myReposView); + if (!this.switchCurrentView(this.myReposView)) { + return false; + }; this.myReposView.show(); this.sideNavView.setCurTab('mine'); }, showMyDeletedRepos: function() { - this.switchCurrentView(this.myDeletedReposView); + if (!this.switchCurrentView(this.myDeletedReposView)) { + return false; + }; this.myDeletedReposView.show(); this.sideNavView.setCurTab('mine'); }, showSharedRepos: function() { - this.switchCurrentView(this.sharedReposView); + if (!this.switchCurrentView(this.sharedReposView)) { + return false; + } this.sharedReposView.show(); this.sideNavView.setCurTab('shared'); }, @@ -196,7 +211,9 @@ define([ }, showGroups: function () { - this.switchCurrentView(this.groupsView); + if (!this.switchCurrentView(this.groupsView)) { + return false; + } this.groupsView.show(); this.sideNavView.setCurTab('group', { 'cur_group_tab': 'groups', @@ -205,7 +222,9 @@ define([ }, showGroup: function(group_id, options) { - this.switchCurrentView(this.groupView); + if (!this.switchCurrentView(this.groupView)) { + return false; + } this.groupView.show(group_id, options); this.sideNavView.setCurTab('group', { 'cur_group_tab': '', @@ -247,7 +266,9 @@ define([ }, showOrgRepos: function() { - this.switchCurrentView(this.orgView); + if (!this.switchCurrentView(this.orgView)) { + return false; + } this.orgView.show(); this.sideNavView.setCurTab('org'); }, @@ -264,49 +285,65 @@ define([ }, showStarredFile: function() { - this.switchCurrentView(this.starredFileView); + if (!this.switchCurrentView(this.starredFileView)) { + return false; + } this.starredFileView.show(); this.sideNavView.setCurTab('starred'); }, showActivities: function() { - this.switchCurrentView(this.activitiesView); + if (!this.switchCurrentView(this.activitiesView)) { + return false; + } this.activitiesView.show(); this.sideNavView.setCurTab('activities'); }, showDevices: function() { - this.switchCurrentView(this.devicesView); + if (!this.switchCurrentView(this.devicesView)) { + return false; + } this.devicesView.show(); this.sideNavView.setCurTab('devices'); }, showInvitations: function() { - this.switchCurrentView(this.invitationsView); + if (!this.switchCurrentView(this.invitationsView)) { + return false; + } this.invitationsView.show(); this.sideNavView.setCurTab('invitations'); }, showShareAdminRepos: function() { - this.switchCurrentView(this.shareAdminReposView); + if (!this.switchCurrentView(this.shareAdminReposView)) { + return false; + } this.shareAdminReposView.show(); this.sideNavView.setCurTab('share-admin-repos', {'show_share_admin': true}); }, showShareAdminFolders: function() { - this.switchCurrentView(this.shareAdminFoldersView); + if (!this.switchCurrentView(this.shareAdminFoldersView)) { + return false; + } this.shareAdminFoldersView.show(); this.sideNavView.setCurTab('share-admin-folders', {'show_share_admin': true}); }, showShareAdminShareLinks: function() { - this.switchCurrentView(this.shareAdminShareLinksView); + if (!this.switchCurrentView(this.shareAdminShareLinksView)) { + return false; + } this.shareAdminShareLinksView.show(); this.sideNavView.setCurTab('share-admin-links', {'show_share_admin': true}); }, showShareAdminUploadLinks: function() { - this.switchCurrentView(this.shareAdminUploadLinksView); + if (!this.switchCurrentView(this.shareAdminUploadLinksView)) { + return false; + } this.shareAdminUploadLinksView.show(); this.sideNavView.setCurTab('share-admin-links', {'show_share_admin': true}); } diff --git a/static/scripts/app/views/dir.js b/static/scripts/app/views/dir.js index e75dbd3146..b0ccc021c4 100644 --- a/static/scripts/app/views/dir.js +++ b/static/scripts/app/views/dir.js @@ -104,6 +104,14 @@ define([ } }); + // confirm leaving the page when file is uploading + window.onbeforeunload = function(e) { + if ($('#upload-file-dialog').is(':visible') && + $('#upload-file-dialog .status').text() == window.fileuploading) { + return ''; + } + }; + }, renderMainCon: function() { diff --git a/static/scripts/app/views/fileupload.js b/static/scripts/app/views/fileupload.js index 725ed7c3d5..9d55429ee6 100644 --- a/static/scripts/app/views/fileupload.js +++ b/static/scripts/app/views/fileupload.js @@ -49,6 +49,8 @@ define([ 'canceled': gettext("File Upload canceled"), 'failed': gettext("File Upload failed") }; + // for the leaving page confirm popup + window.fileuploading = fu_status.uploading; var uploaded_files = []; var updated_files = []; From f41596a611b00775b9152934c98c852da3e018fe Mon Sep 17 00:00:00 2001 From: lian Date: Thu, 20 Dec 2018 14:41:11 +0800 Subject: [PATCH 6/6] add LOCAL_PRO_DEV_ENV when test generet event type --- tests/seahub/utils/test_generate_file_audit_event_type.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/seahub/utils/test_generate_file_audit_event_type.py b/tests/seahub/utils/test_generate_file_audit_event_type.py index 9227cbebd0..77a20f2ba2 100644 --- a/tests/seahub/utils/test_generate_file_audit_event_type.py +++ b/tests/seahub/utils/test_generate_file_audit_event_type.py @@ -1,6 +1,11 @@ from seahub.test_utils import BaseTestCase from seahub.utils import generate_file_audit_event_type +try: + from seahub.settings import LOCAL_PRO_DEV_ENV +except ImportError: + LOCAL_PRO_DEV_ENV = False + class Events(): def __init__(self, etype, device): @@ -12,6 +17,9 @@ class GenerateFileAuditEventTypeTest(BaseTestCase): def test_generate_file_audit_event_type(self): + if not LOCAL_PRO_DEV_ENV: + return + event_type_device = { 'file-download-web': '', 'file-download-share-link': '',