From a0fac4ab81ce8322b4e07d944ffc3b4df859f347 Mon Sep 17 00:00:00 2001 From: r350178982 <32759763+r350178982@users.noreply.github.com> Date: Sat, 14 Sep 2024 14:51:40 +0800 Subject: [PATCH 1/2] update --- seahub/api2/endpoints/dir.py | 10 +- seahub/api2/endpoints/file.py | 3 +- seahub/api2/endpoints/via_repo_token.py | 3 +- seahub/api2/endpoints/wiki2.py | 3 +- seahub/api2/views.py | 3 +- seahub/seadoc/apis.py | 136 +----------------- seahub/seadoc/urls.py | 4 +- seahub/templates/sdoc_file_view_react.html | 1 - .../sdoc_published_revision_file_view.html | 1 - seahub/views/file.py | 8 +- 10 files changed, 9 insertions(+), 163 deletions(-) diff --git a/seahub/api2/endpoints/dir.py b/seahub/api2/endpoints/dir.py index 787fe32d167..0384970e870 100644 --- a/seahub/api2/endpoints/dir.py +++ b/seahub/api2/endpoints/dir.py @@ -107,12 +107,10 @@ def get_dir_file_info_list(username, request_type, repo_obj, parent_dir, try: from seahub.tags.models import FileUUIDMap - from seahub.seadoc.models import SeadocDraft, SeadocRevision + from seahub.seadoc.models import SeadocRevision file_uuid_queryset = FileUUIDMap.objects.get_fileuuidmaps_by_parent_path( repo_id, parent_dir) file_uuid_list = [item.uuid for item in file_uuid_queryset] - seadoc_draft_queryset = SeadocDraft.objects.list_by_doc_uuids( - file_uuid_list) seadoc_revision_queryset = SeadocRevision.objects.list_by_doc_uuids( file_uuid_list) except Exception as e: @@ -194,12 +192,6 @@ def get_dir_file_info_list(username, request_type, repo_obj, parent_dir, file_uuid_map = file_uuid_queryset.filter( filename=file_name).first() if file_uuid_map: - sdoc_draft = seadoc_draft_queryset.filter( - doc_uuid=file_uuid_map.uuid).first() - if sdoc_draft: - file_info['is_sdoc_draft'] = True - else: - file_info['is_sdoc_draft'] = False sdoc_revision = seadoc_revision_queryset.filter( doc_uuid=file_uuid_map.uuid).first() if sdoc_revision: diff --git a/seahub/api2/endpoints/file.py b/seahub/api2/endpoints/file.py index 1c0fbdfacf4..740189688eb 100644 --- a/seahub/api2/endpoints/file.py +++ b/seahub/api2/endpoints/file.py @@ -32,7 +32,7 @@ MARKDOWN_SUPPORT_CONVERT_TYPES, SDOC_SUPPORT_CONVERT_TYPES, \ DOCX_SUPPORT_CONVERT_TYPES from seahub.tags.models import FileUUIDMap -from seahub.seadoc.models import SeadocHistoryName, SeadocDraft, SeadocCommentReply +from seahub.seadoc.models import SeadocHistoryName, SeadocCommentReply from seahub.base.models import FileComment from seahub.settings import MAX_UPLOAD_FILE_NAME_LEN, OFFICE_TEMPLATE_ROOT from seahub.api2.endpoints.utils import convert_file, sdoc_convert_to_docx @@ -882,7 +882,6 @@ def delete(self, request, repo_id, format=None): FileUUIDMap.objects.delete_fileuuidmap_by_path( repo_id, parent_dir, file_name, is_dir=False) SeadocHistoryName.objects.filter(doc_uuid=file_uuid).delete() - SeadocDraft.objects.filter(doc_uuid=file_uuid).delete() SeadocCommentReply.objects.filter(doc_uuid=file_uuid).delete() except Exception as e: logger.error(e) diff --git a/seahub/api2/endpoints/via_repo_token.py b/seahub/api2/endpoints/via_repo_token.py index 0ac41ea1bf1..31c4f34b1e5 100644 --- a/seahub/api2/endpoints/via_repo_token.py +++ b/seahub/api2/endpoints/via_repo_token.py @@ -24,7 +24,7 @@ from seahub.repo_api_tokens.utils import get_dir_file_info_list from seahub.api2.throttling import UserRateThrottle from seahub.api2.utils import api_error, to_python_boolean -from seahub.seadoc.models import SeadocHistoryName, SeadocDraft, SeadocCommentReply +from seahub.seadoc.models import SeadocHistoryName, SeadocCommentReply from seahub.utils.file_op import if_locked_by_online_office from seahub.seadoc.utils import get_seadoc_file_uuid from seahub.settings import MAX_PATH @@ -1246,7 +1246,6 @@ def delete(self, request, format=None): FileUUIDMap.objects.delete_fileuuidmap_by_path( repo_id, parent_dir, file_name, is_dir=False) SeadocHistoryName.objects.filter(doc_uuid=file_uuid).delete() - SeadocDraft.objects.filter(doc_uuid=file_uuid).delete() SeadocCommentReply.objects.filter(doc_uuid=file_uuid).delete() except Exception as e: logger.error(e) diff --git a/seahub/api2/endpoints/wiki2.py b/seahub/api2/endpoints/wiki2.py index 174e5951fae..baff9bae42f 100644 --- a/seahub/api2/endpoints/wiki2.py +++ b/seahub/api2/endpoints/wiki2.py @@ -47,7 +47,7 @@ from seahub.utils.timeutils import timestamp_to_isoformat_timestr from seahub.utils.ccnet_db import CcnetDB from seahub.tags.models import FileUUIDMap -from seahub.seadoc.models import SeadocHistoryName, SeadocDraft, SeadocCommentReply +from seahub.seadoc.models import SeadocHistoryName, SeadocCommentReply from seahub.base.models import FileComment from seahub.api2.views import HTTP_447_TOO_MANY_FILES_IN_LIBRARY from seahub.group.utils import group_id_to_name, is_group_admin @@ -1143,7 +1143,6 @@ def delete(self, request, wiki_id): FileComment.objects.filter(uuid__in=file_uuids).delete() FileUUIDMap.objects.filter(uuid__in=file_uuids).delete() SeadocHistoryName.objects.filter(doc_uuid__in=file_uuids).delete() - SeadocDraft.objects.filter(doc_uuid__in=file_uuids).delete() SeadocCommentReply.objects.filter(doc_uuid__in=file_uuids).delete() except Exception as e: logger.error(e) diff --git a/seahub/api2/views.py b/seahub/api2/views.py index 87dadd0f9a6..7f27ea2e191 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -78,7 +78,7 @@ normalize_cache_key, HAS_FILE_SEASEARCH from seahub.tags.models import FileUUIDMap -from seahub.seadoc.models import SeadocHistoryName, SeadocDraft, SeadocCommentReply +from seahub.seadoc.models import SeadocHistoryName, SeadocCommentReply from seahub.utils.file_types import IMAGE, SEADOC from seahub.utils.file_revisions import get_file_revisions_after_renamed from seahub.utils.devices import do_unlink_device @@ -3368,7 +3368,6 @@ def delete(self, request, repo_id, format=None): FileUUIDMap.objects.delete_fileuuidmap_by_path( repo_id, parent_dir, file_name, is_dir=False) SeadocHistoryName.objects.filter(doc_uuid=file_uuid).delete() - SeadocDraft.objects.filter(doc_uuid=file_uuid).delete() SeadocCommentReply.objects.filter(doc_uuid=file_uuid).delete() except Exception as e: logger.error(e) diff --git a/seahub/seadoc/apis.py b/seahub/seadoc/apis.py index bd0e2dbed38..9f1a6e27241 100644 --- a/seahub/seadoc/apis.py +++ b/seahub/seadoc/apis.py @@ -48,7 +48,7 @@ from seahub.tags.models import FileUUIDMap from seahub.utils.error_msg import file_type_error_msg from seahub.utils.repo import parse_repo_perm -from seahub.seadoc.models import SeadocHistoryName, SeadocDraft, SeadocRevision, SeadocCommentReply, SeadocNotification +from seahub.seadoc.models import SeadocHistoryName, SeadocRevision, SeadocCommentReply, SeadocNotification from seahub.avatar.templatetags.avatar_tags import api_avatar_url from seahub.base.templatetags.seahub_tags import email2nickname, \ email2contact_email @@ -821,140 +821,6 @@ def get(self, request, file_uuid): } return Response(result) - -class SeadocDrafts(APIView): - - authentication_classes = (TokenAuthentication, SessionAuthentication) - permission_classes = (IsAuthenticated,) - throttle_classes = (UserRateThrottle, ) - - def get(self, request): - """list drafts - """ - username = request.user.username - # argument check - repo_id = request.GET.get('repo_id') - try: - page = int(request.GET.get('page', '1')) - per_page = int(request.GET.get('per_page', '25')) - except ValueError: - page = 1 - per_page = 25 - start = (page - 1) * per_page - end = page * per_page - - if repo_id: - # resource check - repo = seafile_api.get_repo(repo_id) - if not repo: - error_msg = 'Library %s not found.' % repo_id - return api_error(status.HTTP_404_NOT_FOUND, error_msg) - - # permission check - permission = check_folder_permission(request, repo_id, '/') - if not permission: - error_msg = 'Permission denied.' - return api_error(status.HTTP_403_FORBIDDEN, error_msg) - - draft_queryset = SeadocDraft.objects.list_by_repo_id(repo_id, start, end) - count = SeadocDraft.objects.filter(repo_id=repo_id).count() - else: - # owned - draft_queryset = SeadocDraft.objects.list_by_username(username, start, end) - count = SeadocDraft.objects.filter(username=username).count() - - drafts = [draft.to_dict() for draft in draft_queryset] - - return Response({'drafts': drafts, 'count': count}) - - -class SeadocMaskAsDraft(APIView): - - authentication_classes = (TokenAuthentication, SessionAuthentication) - permission_classes = (IsAuthenticated,) - throttle_classes = (UserRateThrottle, ) - - def post(self, request, repo_id): - """ Mask as draft - """ - username = request.user.username - # argument check - path = request.data.get('p', None) - if not path: - error_msg = 'p invalid.' - return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - - path = normalize_file_path(path) - parent_dir = os.path.dirname(path) - filename = os.path.basename(path) - - filetype, fileext = get_file_type_and_ext(filename) - if filetype != SEADOC: - error_msg = 'seadoc file type %s invalid.' % filetype - return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - - # resource check - repo = seafile_api.get_repo(repo_id) - if not repo: - error_msg = 'Library %s not found.' % repo_id - return api_error(status.HTTP_404_NOT_FOUND, error_msg) - - # permission check - permission = check_folder_permission(request, repo_id, path) - if not permission: - error_msg = 'Permission denied.' - return api_error(status.HTTP_403_FORBIDDEN, error_msg) - - # - file_uuid = get_seadoc_file_uuid(repo, path) - exist_draft = SeadocDraft.objects.get_by_doc_uuid(file_uuid) - if exist_draft: - error_msg = '%s is already draft' % filename - return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - - draft = SeadocDraft.objects.mask_as_draft( - file_uuid, repo_id, username) - - return Response(draft.to_dict()) - - def delete(self, request, repo_id): - """ Unmask as draft - """ - username = request.user.username - # argument check - path = request.data.get('p', None) - if not path: - error_msg = 'p invalid.' - return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - - path = normalize_file_path(path) - parent_dir = os.path.dirname(path) - filename = os.path.basename(path) - - filetype, fileext = get_file_type_and_ext(filename) - if filetype != SEADOC: - error_msg = 'seadoc file type %s invalid.' % filetype - return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - - # resource check - repo = seafile_api.get_repo(repo_id) - if not repo: - error_msg = 'Library %s not found.' % repo_id - return api_error(status.HTTP_404_NOT_FOUND, error_msg) - - # permission check - permission = check_folder_permission(request, repo_id, path) - if not permission: - error_msg = 'Permission denied.' - return api_error(status.HTTP_403_FORBIDDEN, error_msg) - - # - file_uuid = get_seadoc_file_uuid(repo, path) - SeadocDraft.objects.unmask_as_draft(file_uuid) - - return Response({'success': True}) - - class SeadocNotificationsView(APIView): authentication_classes = (SdocJWTTokenAuthentication, TokenAuthentication, SessionAuthentication) permission_classes = (IsAuthenticated,) diff --git a/seahub/seadoc/urls.py b/seahub/seadoc/urls.py index e45a2a2f2a1..d7d709570a7 100644 --- a/seahub/seadoc/urls.py +++ b/seahub/seadoc/urls.py @@ -1,6 +1,6 @@ from django.urls import re_path from .apis import SeadocAccessToken, SeadocUploadLink, SeadocDownloadLink, SeadocImageDownloadLink, SeadocOriginFileContent, SeadocUploadFile, \ - SeadocUploadImage, SeadocDownloadImage, SeadocAsyncCopyImages, SeadocQueryCopyMoveProgressView, SeadocCopyHistoryFile, SeadocHistory, SeadocDrafts, SeadocMaskAsDraft, \ + SeadocUploadImage, SeadocDownloadImage, SeadocAsyncCopyImages, SeadocQueryCopyMoveProgressView, SeadocCopyHistoryFile, SeadocHistory, \ SeadocCommentsView, SeadocCommentView, SeadocStartRevise, SeadocPublishRevision, SeadocRevisionsCount, SeadocRevisions, \ SeadocCommentRepliesView, SeadocCommentReplyView, SeadocFileView, SeadocFileUUIDView, SeadocDirView, SdocRevisionBaseVersionContent, SeadocRevisionView, \ SdocRepoTagsView, SdocRepoTagView, SdocRepoFileTagsView, SdocRepoFileTagView, SeadocNotificationsView, SeadocNotificationView, \ @@ -21,8 +21,6 @@ re_path(r'^copy-history-file/(?P[-0-9a-f]{36})/$', SeadocCopyHistoryFile.as_view(), name='seadoc_copy_history_file'), re_path(r'^history/(?P[-0-9a-f]{36})/$', SeadocHistory.as_view(), name='seadoc_history'), re_path(r'^daily-history-detail/(?P[-0-9a-f]{36})/$', SeadocDailyHistoryDetail.as_view(), name='seadoc_daily_history_detail'), - re_path(r'^drafts/$', SeadocDrafts.as_view(), name='seadoc_drafts'), - re_path(r'^mark-as-draft/(?P[-0-9a-f]{36})/$', SeadocMaskAsDraft.as_view(), name='seadoc_mark_as_draft'), re_path(r'^comments/(?P[-0-9a-f]{36})/$', SeadocCommentsView.as_view(), name='seadoc_comments'), re_path(r'^comment/(?P[-0-9a-f]{36})/(?P\d+)/$', SeadocCommentView.as_view(), name='seadoc_comment'), re_path(r'^comment/(?P[-0-9a-f]{36})/(?P\d+)/replies/$', SeadocCommentRepliesView.as_view(), name='seadoc_comment_replies'), diff --git a/seahub/templates/sdoc_file_view_react.html b/seahub/templates/sdoc_file_view_react.html index a9e10724cac..08d83ac8983 100644 --- a/seahub/templates/sdoc_file_view_react.html +++ b/seahub/templates/sdoc_file_view_react.html @@ -29,7 +29,6 @@ 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 %}, isFreezed: {% if is_freezed %}true{% else %}false{% endif %} {% endblock %} diff --git a/seahub/templates/sdoc_published_revision_file_view.html b/seahub/templates/sdoc_published_revision_file_view.html index 3b41f89ffbe..04648cdfb57 100644 --- a/seahub/templates/sdoc_published_revision_file_view.html +++ b/seahub/templates/sdoc_published_revision_file_view.html @@ -27,7 +27,6 @@ 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 %} {% endblock %} {% block render_bundle %} diff --git a/seahub/views/file.py b/seahub/views/file.py index 68a33b9b43c..fe9c7a127ee 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -76,7 +76,7 @@ from seahub.drafts.utils import get_file_draft, \ is_draft_file, has_draft_file from seahub.seadoc.utils import get_seadoc_file_uuid, gen_seadoc_access_token, is_seadoc_revision -from seahub.seadoc.models import SeadocDraft, SeadocRevision +from seahub.seadoc.models import SeadocRevision if HAS_OFFICE_CONVERTER: from seahub.utils import ( @@ -677,11 +677,7 @@ def view_lib_file(request, repo_id, path): return_dict['seadoc_access_token'] = gen_seadoc_access_token(file_uuid, filename, username, permission=seadoc_perm) # draft - is_sdoc_draft = False - sdoc_draft = SeadocDraft.objects.get_by_doc_uuid(file_uuid) - if sdoc_draft: - is_sdoc_draft = True - return_dict['is_sdoc_draft'] = is_sdoc_draft + # revision revision_info = is_seadoc_revision(file_uuid) From 7e5511b2a9ef87420191bf80205991469352efff Mon Sep 17 00:00:00 2001 From: r350178982 <32759763+r350178982@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:24:01 +0800 Subject: [PATCH 2/2] remove-useless-codes --- seahub/api2/endpoints/dir.py | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/seahub/api2/endpoints/dir.py b/seahub/api2/endpoints/dir.py index 0384970e870..bd554745cd1 100644 --- a/seahub/api2/endpoints/dir.py +++ b/seahub/api2/endpoints/dir.py @@ -105,17 +105,6 @@ def get_dir_file_info_list(username, request_type, repo_obj, parent_dir, logger.error(e) files_tags_in_dir = {} - try: - from seahub.tags.models import FileUUIDMap - from seahub.seadoc.models import SeadocRevision - file_uuid_queryset = FileUUIDMap.objects.get_fileuuidmaps_by_parent_path( - repo_id, parent_dir) - file_uuid_list = [item.uuid for item in file_uuid_queryset] - seadoc_revision_queryset = SeadocRevision.objects.list_by_doc_uuids( - file_uuid_list) - except Exception as e: - logger.error(e) - for dirent in file_list: file_name = dirent.obj_name @@ -184,24 +173,6 @@ def get_dir_file_info_list(username, request_type, repo_obj, parent_dir, if os.path.exists(thumbnail_file_path): src = get_thumbnail_src(repo_id, thumbnail_size, file_path) file_info['encoded_thumbnail_src'] = quote(src) - - # sdoc - filetype, fileext = get_file_type_and_ext(file_info['name']) - if filetype == SEADOC: - try: - file_uuid_map = file_uuid_queryset.filter( - filename=file_name).first() - if file_uuid_map: - sdoc_revision = seadoc_revision_queryset.filter( - doc_uuid=file_uuid_map.uuid).first() - if sdoc_revision: - file_info['is_sdoc_revision'] = True - file_info['revision_id'] = sdoc_revision.revision_id - else: - file_info['is_sdoc_revision'] = False - except Exception as e: - logger.error(e) - file_info_list.append(file_info) dir_info_list.sort(key=lambda x: x['name'].lower())