From 9d52a4547460eccc3ef16da51a0c146aaea6435e Mon Sep 17 00:00:00 2001 From: lian Date: Tue, 14 Nov 2023 16:06:45 +0800 Subject: [PATCH] freeze document --- .../dirent-list-view/dirent-list-item.js | 17 +++++++++++++++++ frontend/src/utils/text-translation.js | 1 + frontend/src/utils/utils.js | 8 ++++++-- seahub/api2/endpoints/dir.py | 1 + seahub/api2/endpoints/file.py | 9 ++++----- seahub/templates/sdoc_file_view_react.html | 3 ++- seahub/views/file.py | 4 ++++ 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/dirent-list-view/dirent-list-item.js b/frontend/src/components/dirent-list-view/dirent-list-item.js index a59cfac4f9..2ceba7ac99 100644 --- a/frontend/src/components/dirent-list-view/dirent-list-item.js +++ b/frontend/src/components/dirent-list-view/dirent-list-item.js @@ -271,6 +271,9 @@ class DirentListItem extends React.Component { case 'Lock': this.onLockItem(); break; + case 'Freeze Document': + this.onFreezeDocument(); + break; case 'Convert to Markdown': this.onItemConvert(event, 'markdown'); break; @@ -369,6 +372,20 @@ class DirentListItem extends React.Component { }); }; + onFreezeDocument = () => { + let repoID = this.props.repoID; + let filePath = this.getDirentPath(this.props.dirent); + seafileAPI.lockfile(repoID, filePath, -1).then(() => { + this.props.updateDirent(this.props.dirent, 'is_locked', true); + this.props.updateDirent(this.props.dirent, 'locked_by_me', true); + let lockName = username.split('@'); + this.props.updateDirent(this.props.dirent, 'lock_owner_name', lockName[0]); + }).catch(error => { + let errMessage = Utils.getErrorMsg(error); + toaster.danger(errMessage); + }); + }; + onUnlockItem = () => { let repoID = this.props.repoID; let filePath = this.getDirentPath(this.props.dirent); diff --git a/frontend/src/utils/text-translation.js b/frontend/src/utils/text-translation.js index e85cdae7f3..fd7962383a 100644 --- a/frontend/src/utils/text-translation.js +++ b/frontend/src/utils/text-translation.js @@ -21,6 +21,7 @@ const TextTranslation = { 'DETAILS' : {key : 'Details', value : gettext('Details')}, 'OPEN_VIA_CLIENT' : {key : 'Open via Client', value : gettext('Open via Client')}, 'LOCK' : {key : 'Lock', value : gettext('Lock')}, + 'FREEZE_DOCUMENT' : {key : 'Freeze Document', value : gettext('Freeze Document')}, 'UNLOCK' : {key : 'Unlock', value : gettext('Unlock')}, 'CONVERT_TO_MARKDOWN' : {key : 'Convert to Markdown', value : gettext('Convert to Markdown')}, 'CONVERT_TO_SDOC' : {key : 'Convert to sdoc', value : gettext('Convert to sdoc')}, diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index fff38b959e..822405ac57 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -527,7 +527,7 @@ export const Utils = { getFileOperationList: function(isRepoOwner, currentRepoInfo, dirent, isContextmenu) { let list = []; - const { SHARE, DOWNLOAD, DELETE, RENAME, MOVE, COPY, TAGS, UNLOCK, LOCK, + const { SHARE, DOWNLOAD, DELETE, RENAME, MOVE, COPY, TAGS, UNLOCK, LOCK, FREEZE_DOCUMENT, HISTORY, ACCESS_LOG, PROPERTIES, OPEN_VIA_CLIENT, ONLYOFFICE_CONVERT, CONVERT_TO_MARKDOWN, CONVERT_TO_SDOC } = TextTranslation; const permission = dirent.permission; const { isCustomPermission, customPermission } = Utils.getUserPermission(permission); @@ -590,7 +590,11 @@ export const Utils = { list.push(UNLOCK); } } else { - list.push(LOCK); + if (dirent.name.endsWith('.sdoc')) { + list.push(FREEZE_DOCUMENT); + } else { + list.push(LOCK); + } } } diff --git a/seahub/api2/endpoints/dir.py b/seahub/api2/endpoints/dir.py index ef45028201..cbd3c8c845 100644 --- a/seahub/api2/endpoints/dir.py +++ b/seahub/api2/endpoints/dir.py @@ -142,6 +142,7 @@ def get_dir_file_info_list(username, request_type, repo_obj, parent_dir, if is_pro_version(): file_info["is_locked"] = dirent.is_locked file_info["lock_time"] = dirent.lock_time + file_info["is_freezed"] = dirent.expire is not None and dirent.expire < 0 lock_owner_email = dirent.lock_owner or '' file_info["lock_owner"] = lock_owner_email diff --git a/seahub/api2/endpoints/file.py b/seahub/api2/endpoints/file.py index a40ac31f26..813fe54eaf 100644 --- a/seahub/api2/endpoints/file.py +++ b/seahub/api2/endpoints/file.py @@ -662,6 +662,9 @@ class FileView(APIView): error_msg = _("File is locked") return api_error(status.HTTP_400_BAD_REQUEST, error_msg) + # expire < 0, freeze document + # expire = 0, use default lock duration + # expire > 0, specify lock duration expire = request.data.get('expire', 0) try: expire = int(expire) @@ -669,17 +672,13 @@ class FileView(APIView): error_msg = 'expire invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - if expire < 0: - error_msg = 'expire invalid.' - return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - # lock file try: if expire > 0: seafile_api.lock_file(repo_id, path, username, int(time.time()) + expire) else: - seafile_api.lock_file(repo_id, path, username, 0) + seafile_api.lock_file(repo_id, path, username, expire) except SearpcError as e: logger.error(e) error_msg = 'Internal Server Error' diff --git a/seahub/templates/sdoc_file_view_react.html b/seahub/templates/sdoc_file_view_react.html index 86d7dcef2b..38dbc10aa4 100644 --- a/seahub/templates/sdoc_file_view_react.html +++ b/seahub/templates/sdoc_file_view_react.html @@ -27,7 +27,8 @@ publisherNickname: '{{ publisher_nickname }}', isPublished: {% if is_published %}true{% else %}false{% endif %}, revisionCreatedAt: '{{ revision_created_at }}', revisionUpdatedAt: '{{ revision_updated_at }}', -isSdocDraft: {% if is_sdoc_draft %}true{% else %}false{% endif %} +isSdocDraft: {% if is_sdoc_draft %}true{% else %}false{% endif %}, +isFreezed: {% if is_freezed %}true{% else %}false{% endif %} {% endblock %} {% block render_bundle %} diff --git a/seahub/views/file.py b/seahub/views/file.py index fc556479a4..6c086fb5b3 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -662,8 +662,12 @@ def view_lib_file(request, repo_id, path): can_edit_file = False elif is_locked and not locked_by_me: can_edit_file = False + return_dict['can_edit_file'] = can_edit_file + lock_info = seafile_api.get_lock_info(repo_id, path) + return_dict['is_freezed'] = lock_info is not None and lock_info.expire < 0 + if is_pro_version() and can_edit_file: try: if not is_locked: