1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-23 12:27:48 +00:00

update file lock error check

This commit is contained in:
lian
2015-07-20 13:53:07 +08:00
parent 2aa15a7d19
commit 3ec770e7d8
4 changed files with 59 additions and 10 deletions

View File

@@ -89,7 +89,6 @@ if HAS_OFFICE_CONVERTER:
from seahub.utils import query_office_convert_status, prepare_converted_html
import seahub.settings as settings
from seahub.settings import THUMBNAIL_EXTENSION, THUMBNAIL_ROOT, \
ENABLE_THUMBNAIL, THUMBNAIL_IMAGE_SIZE_LIMIT, \
ENABLE_GLOBAL_ADDRESSBOOK, FILE_LOCK_EXPIRATION_DAYS
try:
from seahub.settings import CLOUD_MODE
@@ -1667,6 +1666,9 @@ class FileView(APIView):
'You do not have permission to rename file.')
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
if (is_locked, locked_by_me) == (None, None):
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Check file lock error')
if is_locked and not locked_by_me:
return api_error(status.HTTP_403_FORBIDDEN, 'File is locked')
@@ -1708,6 +1710,9 @@ class FileView(APIView):
'You do not have permission to move file.')
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
if (is_locked, locked_by_me) == (None, None):
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Check file lock error')
if is_locked and not locked_by_me:
return api_error(status.HTTP_403_FORBIDDEN, 'File is locked')
@@ -1846,6 +1851,9 @@ class FileView(APIView):
return api_error(status.HTTP_400_BAD_REQUEST, 'Path is missing.')
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
if (is_locked, locked_by_me) == (None, None):
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Check file lock error')
if is_locked and not locked_by_me:
return api_error(status.HTTP_403_FORBIDDEN, 'File is locked')
@@ -1941,6 +1949,9 @@ class FileRevert(APIView):
username = request.uset.username
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
if (is_locked, locked_by_me) == (None, None):
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Check file lock error')
if is_locked and not locked_by_me:
return api_error(status.HTTP_403_FORBIDDEN, 'File is locked')

View File

@@ -142,8 +142,12 @@ def check_file_lock(repo_id, file_path, username):
return (is_locked, locked_by_me)
"""
try:
return_value = seafile_api.check_file_lock(repo_id,
file_path.lstrip('/'), username)
except SearpcError as e:
logger.error(e)
return (None, None)
if return_value == 0:
return (False, False)
@@ -152,7 +156,7 @@ def check_file_lock(repo_id, file_path, username):
elif return_value == 2:
return (True, True)
else:
return None
return (None, None)
def check_repo_access_permission(repo_id, user):
"""Check repo access permission of a user, always return 'rw' when repo is
@@ -1488,7 +1492,12 @@ def render_file_revisions (request, repo_id):
can_revert_file = True
username = request.user.username
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
if (is_locked, locked_by_me) == (None, None):
# check file lock error
can_revert_file = False
if seafile_api.check_permission_by_path(repo_id, path, username) != 'rw' or \
(is_locked and not locked_by_me):
can_revert_file = False
@@ -1522,12 +1531,19 @@ def repo_revert_file(request, repo_id):
username = request.user.username
# perm check
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
if check_folder_permission(request, repo.id, path) != 'rw' or \
(is_locked and not locked_by_me):
if check_folder_permission(request, repo.id, path) != 'rw':
messages.error(request, _("Permission denied"))
return HttpResponseRedirect(next)
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
if (is_locked, locked_by_me) == (None, None):
messages.error(request, _("Check file lock error"))
return HttpResponseRedirect(next)
if is_locked and not locked_by_me:
messages.error(request, _("File is locked"))
return HttpResponseRedirect(next)
try:
ret = seafile_api.revert_file(repo_id, commit_id, path, username)
except Exception as e:

View File

@@ -656,6 +656,12 @@ def rename_dirent(request, repo_id):
content_type=content_type)
is_locked, locked_by_me = check_file_lock(repo_id, full_path, username)
if (is_locked, locked_by_me) == (None, None):
# check file lock error
err_msg = _('Check file lock error')
return HttpResponse(json.dumps({'error': err_msg}), status=500,
content_type=content_type)
if is_locked and not locked_by_me:
err_msg = _('File is locked')
return HttpResponse(json.dumps({'error': err_msg}), status=403,
@@ -718,6 +724,12 @@ def delete_dirent(request, repo_id):
content_type=content_type)
is_locked, locked_by_me = check_file_lock(repo_id, full_path, username)
if (is_locked, locked_by_me) == (None, None):
# check file lock error
err_msg = _('Check file lock error')
return HttpResponse(json.dumps({'error': err_msg}), status=500,
content_type=content_type)
if is_locked and not locked_by_me:
err_msg = _('File is locked')
return HttpResponse(json.dumps({'error': err_msg}), status=403,
@@ -846,12 +858,17 @@ def mv_file(request, src_repo_id, src_path, dst_repo_id, dst_path, obj_name):
file_path = posixpath.join(src_path, obj_name)
is_locked, locked_by_me = check_file_lock(src_repo_id, file_path, username)
if (is_locked, locked_by_me) == (None, None):
# check file lock error
err_msg = _('Check file lock error')
return HttpResponse(json.dumps({'error': err_msg}), status=500,
content_type=content_type)
if is_locked and not locked_by_me:
err_msg = _('File is locked')
return HttpResponse(json.dumps({'error': err_msg}), status=403,
content_type=content_type)
new_obj_name = check_filename_with_rename(dst_repo_id, dst_path, obj_name)
try:
res = seafile_api.move_file(src_repo_id, src_path, obj_name,

View File

@@ -986,11 +986,16 @@ def file_edit_submit(request, repo_id):
parent_dir = os.path.dirname(path)
# edit file, so check parent_dir's permission
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
if check_folder_permission(request, repo_id, parent_dir) != 'rw' or \
(is_locked and not locked_by_me):
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
return error_json(_(u'Permission denied'))
is_locked, locked_by_me = check_file_lock(repo_id, path, username)
if (is_locked, locked_by_me) == (None, None):
return error_json(_(u'Check file lock errror'))
if is_locked and not locked_by_me:
return error_json(_(u'File is locked'))
repo = get_repo(repo_id)
if not repo:
return error_json(_(u'The library does not exist.'))