diff --git a/frontend/src/seafile-editor b/frontend/src/seafile-editor deleted file mode 160000 index 121a55fe85..0000000000 --- a/frontend/src/seafile-editor +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 121a55fe85dec8de3b36d54cfb505406803321e4 diff --git a/frontend/src/seafile-js b/frontend/src/seafile-js deleted file mode 160000 index d1fee8bca8..0000000000 --- a/frontend/src/seafile-js +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d1fee8bca82141ee2d929bb29187d9fd88f2365a diff --git a/seahub/api2/endpoints/drafts.py b/seahub/api2/endpoints/drafts.py index f43e0bc414..6714af0766 100644 --- a/seahub/api2/endpoints/drafts.py +++ b/seahub/api2/endpoints/drafts.py @@ -77,8 +77,12 @@ class DraftsView(APIView): d = Draft.objects.add(username, repo, file_path, file_id) return Response(d.to_dict()) - except (DraftFileExist, IntegrityError): + except DraftFileExist: return api_error(status.HTTP_409_CONFLICT, 'Draft already exists.') + except Exception as e: + logger.error(e) + error_msg = 'Internal Server Error' + return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) class DraftView(APIView): @@ -115,9 +119,13 @@ class DraftView(APIView): d.publish(operator=username) d.delete(operator=username) return Response(status.HTTP_200_OK) - except (DraftFileConflict, IntegrityError): + except DraftFileConflict: return api_error(status.HTTP_409_CONFLICT, 'There is a conflict between the draft and the original file') + except Exception as e: + logger.error(e) + error_msg = 'Internal Server Error' + return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) def delete(self, request, pk, format=None): """Delete a draft if user is draft owner diff --git a/seahub/api2/endpoints/file.py b/seahub/api2/endpoints/file.py index 3b2656dcc1..c2ffe2d962 100644 --- a/seahub/api2/endpoints/file.py +++ b/seahub/api2/endpoints/file.py @@ -31,7 +31,7 @@ from seahub.settings import MAX_UPLOAD_FILE_NAME_LEN, \ FILE_LOCK_EXPIRATION_DAYS, OFFICE_TEMPLATE_ROOT from seahub.drafts.models import Draft, DraftReview -from seahub.drafts.utils import is_draft_file, get_file_review +from seahub.drafts.utils import is_draft_file, get_file_draft_and_related_review from seaserv import seafile_api from pysearpc import SearpcError @@ -292,7 +292,7 @@ class FileView(APIView): filetype, fileext = get_file_type_and_ext(new_file_name) if filetype == MARKDOWN or filetype == TEXT: is_draft = is_draft_file(repo.id, path) - review = get_file_review(repo.id, path, is_draft) + review = get_file_draft_and_related_review(repo.id, path, is_draft) review_id = review['review_id'] draft_id = review['draft_id'] if is_draft: diff --git a/seahub/api2/views.py b/seahub/api2/views.py index 678786dde7..af3f8d039f 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -58,7 +58,8 @@ from seahub.notifications.models import UserNotification from seahub.options.models import UserOptions from seahub.profile.models import Profile, DetailedProfile from seahub.drafts.models import Draft -from seahub.drafts.utils import is_draft_file, has_draft_file, get_file_review +from seahub.drafts.utils import get_file_draft_and_related_review, \ + is_draft_file, has_draft_file from seahub.signals import (repo_created, repo_deleted) from seahub.share.models import FileShare, OrgFileShare, UploadLinkShare from seahub.utils import gen_file_get_url, gen_token, gen_file_upload_url, \ @@ -3046,7 +3047,7 @@ class FileDetailView(APIView): if not is_draft: has_draft = has_draft_file(repo_id, path) - review = get_file_review(repo_id, path, is_draft, has_draft) + review = get_file_draft_and_related_review(repo_id, path, is_draft, has_draft) entry['is_draft'] = is_draft entry['has_draft'] = has_draft diff --git a/seahub/drafts/models.py b/seahub/drafts/models.py index 2488ea633f..fee97f1be5 100644 --- a/seahub/drafts/models.py +++ b/seahub/drafts/models.py @@ -25,7 +25,7 @@ class DraftFileConflict(Exception): class DraftManager(models.Manager): def create_exist_file_draft(self, repo, username, file_uuid, file_path): - # create drafts dir if any + # create drafts dir if does not exist draft_dir_id = seafile_api.get_dir_id_by_path(repo.id, '/Drafts') if draft_dir_id is None: seafile_api.post_dir(repo.id, '/', 'Drafts', username) @@ -35,20 +35,23 @@ class DraftManager(models.Manager): draft_file_name = get_draft_file_name(repo.id, file_path) draft_file_path = '/Drafts/' + draft_file_name - if seafile_api.get_file_id_by_path(repo.id, draft_file_path): + try: + d = self.get(origin_file_uuid=file_uuid) + except Draft.DoesNotExist: + # copy file to draft dir + seafile_api.copy_file(repo.id, file_uuid.parent_path, file_uuid.filename, + repo.id, '/Drafts', draft_file_name, + username=username, need_progress=0, synchronous=1) + return draft_file_path + + if d: raise DraftFileExist - # copy file to draft dir - seafile_api.copy_file(repo.id, file_uuid.parent_path, file_uuid.filename, - repo.id, '/Drafts', draft_file_name, - username=username, need_progress=0, synchronous=1) - - return draft_file_path - def add(self, username, repo, file_path, file_exist=True, file_id=None, org_id=-1): file_path = normalize_file_path(file_path) parent_path = os.path.dirname(file_path) filename = os.path.basename(file_path) + # origin file uuid file_uuid = FileUUIDMap.objects.get_or_create_fileuuidmap( repo.id, parent_path, filename, is_dir=False) diff --git a/seahub/drafts/utils.py b/seahub/drafts/utils.py index c3828aabb3..6f4046a4ca 100644 --- a/seahub/drafts/utils.py +++ b/seahub/drafts/utils.py @@ -23,6 +23,7 @@ def get_draft_file_name(repo_id, file_path): file_name, file_ext = os.path.splitext(os.path.basename(file_path)) draft_file_name = "%s%s%s" % (file_name, '(draft)', file_ext) + draft_file_name = check_filename_with_rename(repo_id, '/Drafts', draft_file_name) return draft_file_name @@ -61,7 +62,7 @@ def has_draft_file(repo_id, file_path): return has_draft -def get_file_review(repo_id, file_path, is_draft=False, has_draft=False): +def get_file_draft_and_related_review(repo_id, file_path, is_draft=False, has_draft=False): review = {} review['review_id'] = None review['review_status'] = None @@ -73,12 +74,13 @@ def get_file_review(repo_id, file_path, is_draft=False, has_draft=False): if is_draft: d = Draft.objects.get(origin_repo_id=repo_id, draft_file_path=file_path) review['draft_id'] = d.id + review['draft_file_path'] = d.draft_file_path + # return review (closed / open) try: - d_r = DraftReview.objects.get(origin_repo_id=repo_id, draft_file_path=file_path) + d_r = DraftReview.objects.get(origin_repo_id=repo_id, draft_file_path=file_path, draft_id=d) review['review_id'] = d_r.id review['review_status'] = d_r.status - review['draft_file_path'] = file_path except DraftReview.DoesNotExist: pass @@ -90,14 +92,17 @@ def get_file_review(repo_id, file_path, is_draft=False, has_draft=False): file_uuid = FileUUIDMap.objects.get_fileuuidmap_by_path( repo_id, parent_path, filename, is_dir=False) + d = Draft.objects.get(origin_file_uuid=file_uuid) + # return review (closed / open) if file_uuid: try: - d_r = DraftReview.objects.get(origin_file_uuid=file_uuid) + d_r = DraftReview.objects.get(origin_file_uuid=file_uuid, draft_id=d) review['review_id'] = d_r.id review['review_status'] = d_r.status - review['draft_id'] = d_r.draft_id_id - review['draft_file_path'] = d_r.draft_file_path except DraftReview.DoesNotExist: pass + review['draft_id'] = d.id + review['draft_file_path'] = d.draft_file_path + return review diff --git a/seahub/views/file.py b/seahub/views/file.py index aad1f85a2c..77d36c045d 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -72,7 +72,8 @@ from seahub.utils.repo import is_repo_owner, parse_repo_perm from seahub.group.utils import is_group_member from seahub.thumbnail.utils import extract_xmind_image, get_thumbnail_src, \ XMIND_IMAGE_SIZE, THUMBNAIL_ROOT -from seahub.drafts.utils import is_draft_file, has_draft_file, get_file_review +from seahub.drafts.utils import get_file_draft_and_related_review, \ + is_draft_file, has_draft_file from seahub.constants import HASH_URLS @@ -631,7 +632,7 @@ def view_lib_file(request, repo_id, path): if not is_draft: has_draft = has_draft_file(repo.id, path) - review = get_file_review(repo.id, path, is_draft, has_draft) + review = get_file_draft_and_related_review(repo.id, path, is_draft, has_draft) if filetype == MARKDOWN: return_dict['protocol'] = request.is_secure() and 'https' or 'http'