Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #6778

Merged
merged 2 commits into from
Sep 14, 2024
Merged

update #6778

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions seahub/api2/endpoints/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +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 SeadocDraft, 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:
logger.error(e)

for dirent in file_list:

file_name = dirent.obj_name
Expand Down Expand Up @@ -186,30 +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_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:
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())
Expand Down
3 changes: 1 addition & 2 deletions seahub/api2/endpoints/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions seahub/api2/endpoints/via_repo_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions seahub/api2/endpoints/wiki2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions seahub/api2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
136 changes: 1 addition & 135 deletions seahub/seadoc/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,)
Expand Down
4 changes: 1 addition & 3 deletions seahub/seadoc/urls.py
Original file line number Diff line number Diff line change
@@ -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, \
Expand All @@ -21,8 +21,6 @@
re_path(r'^copy-history-file/(?P<repo_id>[-0-9a-f]{36})/$', SeadocCopyHistoryFile.as_view(), name='seadoc_copy_history_file'),
re_path(r'^history/(?P<file_uuid>[-0-9a-f]{36})/$', SeadocHistory.as_view(), name='seadoc_history'),
re_path(r'^daily-history-detail/(?P<file_uuid>[-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<repo_id>[-0-9a-f]{36})/$', SeadocMaskAsDraft.as_view(), name='seadoc_mark_as_draft'),
re_path(r'^comments/(?P<file_uuid>[-0-9a-f]{36})/$', SeadocCommentsView.as_view(), name='seadoc_comments'),
re_path(r'^comment/(?P<file_uuid>[-0-9a-f]{36})/(?P<comment_id>\d+)/$', SeadocCommentView.as_view(), name='seadoc_comment'),
re_path(r'^comment/(?P<file_uuid>[-0-9a-f]{36})/(?P<comment_id>\d+)/replies/$', SeadocCommentRepliesView.as_view(), name='seadoc_comment_replies'),
Expand Down
1 change: 0 additions & 1 deletion seahub/templates/sdoc_file_view_react.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down
1 change: 0 additions & 1 deletion seahub/templates/sdoc_published_revision_file_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
8 changes: 2 additions & 6 deletions seahub/views/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
Loading