1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 17:02:47 +00:00

freeze document

This commit is contained in:
lian
2023-11-14 16:06:45 +08:00
committed by 杨顺强
parent eefbc643c6
commit 9d52a45474
7 changed files with 35 additions and 8 deletions

View File

@@ -271,6 +271,9 @@ class DirentListItem extends React.Component {
case 'Lock': case 'Lock':
this.onLockItem(); this.onLockItem();
break; break;
case 'Freeze Document':
this.onFreezeDocument();
break;
case 'Convert to Markdown': case 'Convert to Markdown':
this.onItemConvert(event, 'markdown'); this.onItemConvert(event, 'markdown');
break; 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 = () => { onUnlockItem = () => {
let repoID = this.props.repoID; let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent); let filePath = this.getDirentPath(this.props.dirent);

View File

@@ -21,6 +21,7 @@ const TextTranslation = {
'DETAILS' : {key : 'Details', value : gettext('Details')}, 'DETAILS' : {key : 'Details', value : gettext('Details')},
'OPEN_VIA_CLIENT' : {key : 'Open via Client', value : gettext('Open via Client')}, 'OPEN_VIA_CLIENT' : {key : 'Open via Client', value : gettext('Open via Client')},
'LOCK' : {key : 'Lock', value : gettext('Lock')}, 'LOCK' : {key : 'Lock', value : gettext('Lock')},
'FREEZE_DOCUMENT' : {key : 'Freeze Document', value : gettext('Freeze Document')},
'UNLOCK' : {key : 'Unlock', value : gettext('Unlock')}, 'UNLOCK' : {key : 'Unlock', value : gettext('Unlock')},
'CONVERT_TO_MARKDOWN' : {key : 'Convert to Markdown', value : gettext('Convert to Markdown')}, 'CONVERT_TO_MARKDOWN' : {key : 'Convert to Markdown', value : gettext('Convert to Markdown')},
'CONVERT_TO_SDOC' : {key : 'Convert to sdoc', value : gettext('Convert to sdoc')}, 'CONVERT_TO_SDOC' : {key : 'Convert to sdoc', value : gettext('Convert to sdoc')},

View File

@@ -527,7 +527,7 @@ export const Utils = {
getFileOperationList: function(isRepoOwner, currentRepoInfo, dirent, isContextmenu) { getFileOperationList: function(isRepoOwner, currentRepoInfo, dirent, isContextmenu) {
let list = []; 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; HISTORY, ACCESS_LOG, PROPERTIES, OPEN_VIA_CLIENT, ONLYOFFICE_CONVERT, CONVERT_TO_MARKDOWN, CONVERT_TO_SDOC } = TextTranslation;
const permission = dirent.permission; const permission = dirent.permission;
const { isCustomPermission, customPermission } = Utils.getUserPermission(permission); const { isCustomPermission, customPermission } = Utils.getUserPermission(permission);
@@ -589,10 +589,14 @@ export const Utils = {
if (dirent.locked_by_me || dirent.lock_owner == 'OnlineOffice' || isRepoOwner || currentRepoInfo.is_admin) { if (dirent.locked_by_me || dirent.lock_owner == 'OnlineOffice' || isRepoOwner || currentRepoInfo.is_admin) {
list.push(UNLOCK); list.push(UNLOCK);
} }
} else {
if (dirent.name.endsWith('.sdoc')) {
list.push(FREEZE_DOCUMENT);
} else { } else {
list.push(LOCK); list.push(LOCK);
} }
} }
}
list.push('Divider'); list.push('Divider');
} }

View File

@@ -142,6 +142,7 @@ def get_dir_file_info_list(username, request_type, repo_obj, parent_dir,
if is_pro_version(): if is_pro_version():
file_info["is_locked"] = dirent.is_locked file_info["is_locked"] = dirent.is_locked
file_info["lock_time"] = dirent.lock_time 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 '' lock_owner_email = dirent.lock_owner or ''
file_info["lock_owner"] = lock_owner_email file_info["lock_owner"] = lock_owner_email

View File

@@ -662,6 +662,9 @@ class FileView(APIView):
error_msg = _("File is locked") error_msg = _("File is locked")
return api_error(status.HTTP_400_BAD_REQUEST, error_msg) 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) expire = request.data.get('expire', 0)
try: try:
expire = int(expire) expire = int(expire)
@@ -669,17 +672,13 @@ class FileView(APIView):
error_msg = 'expire invalid.' error_msg = 'expire invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg) 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 # lock file
try: try:
if expire > 0: if expire > 0:
seafile_api.lock_file(repo_id, path, username, seafile_api.lock_file(repo_id, path, username,
int(time.time()) + expire) int(time.time()) + expire)
else: else:
seafile_api.lock_file(repo_id, path, username, 0) seafile_api.lock_file(repo_id, path, username, expire)
except SearpcError as e: except SearpcError as e:
logger.error(e) logger.error(e)
error_msg = 'Internal Server Error' error_msg = 'Internal Server Error'

View File

@@ -27,7 +27,8 @@ publisherNickname: '{{ publisher_nickname }}',
isPublished: {% if is_published %}true{% else %}false{% endif %}, isPublished: {% if is_published %}true{% else %}false{% endif %},
revisionCreatedAt: '{{ revision_created_at }}', revisionCreatedAt: '{{ revision_created_at }}',
revisionUpdatedAt: '{{ revision_updated_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 %} {% endblock %}
{% block render_bundle %} {% block render_bundle %}

View File

@@ -662,8 +662,12 @@ def view_lib_file(request, repo_id, path):
can_edit_file = False can_edit_file = False
elif is_locked and not locked_by_me: elif is_locked and not locked_by_me:
can_edit_file = False can_edit_file = False
return_dict['can_edit_file'] = can_edit_file 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: if is_pro_version() and can_edit_file:
try: try:
if not is_locked: if not is_locked: