mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-27 11:10:10 +00:00
commit
fdf8793f0e
@ -6,8 +6,7 @@ import stat
|
||||
import logging
|
||||
import requests
|
||||
import posixpath
|
||||
from datetime import datetime
|
||||
from urllib.parse import quote, unquote
|
||||
from urllib.parse import unquote
|
||||
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
@ -32,17 +31,19 @@ from seahub.seadoc.utils import is_valid_seadoc_access_token, get_seadoc_upload_
|
||||
gen_seadoc_image_parent_path, get_seadoc_asset_upload_link, get_seadoc_asset_download_link, \
|
||||
can_access_seadoc_asset, is_seadoc_revision
|
||||
from seahub.utils.file_types import SEADOC, IMAGE
|
||||
from seahub.utils import get_file_type_and_ext, normalize_file_path, normalize_dir_path, PREVIEW_FILEEXT, get_file_history, \
|
||||
gen_inner_file_get_url, gen_inner_file_upload_url, get_service_url, is_valid_username
|
||||
from seahub.utils.file_op import if_locked_by_online_office
|
||||
from seahub.utils import get_file_type_and_ext, normalize_file_path, \
|
||||
normalize_dir_path, PREVIEW_FILEEXT, get_file_history, \
|
||||
gen_inner_file_get_url, gen_inner_file_upload_url, \
|
||||
get_service_url, is_valid_username, is_pro_version
|
||||
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.utils.file_revisions import get_file_revisions_within_limit
|
||||
from seahub.seadoc.models import SeadocHistoryName, SeadocDraft, SeadocRevision, SeadocCommentReply
|
||||
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname, \
|
||||
email2contact_email
|
||||
from seahub.utils.timeutils import utc_datetime_to_isoformat_timestr, timestamp_to_isoformat_timestr
|
||||
from seahub.utils.timeutils import utc_datetime_to_isoformat_timestr
|
||||
from seahub.base.models import FileComment
|
||||
from seahub.constants import PERMISSION_READ_WRITE, PERMISSION_INVISIBLE
|
||||
from seahub.seadoc.sdoc_server_api import SdocServerAPI
|
||||
@ -2195,3 +2196,46 @@ class SdocRelatedUsers(APIView):
|
||||
related_users.append(user_info)
|
||||
|
||||
return Response({'related_users': related_users})
|
||||
|
||||
class SeadocEditorCallBack(APIView):
|
||||
|
||||
authentication_classes = ()
|
||||
throttle_classes = (UserRateThrottle,)
|
||||
|
||||
def post(self, request, file_uuid):
|
||||
|
||||
# jwt permission check
|
||||
auth = request.headers.get('authorization', '').split()
|
||||
if not is_valid_seadoc_access_token(auth, file_uuid):
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
# file info check
|
||||
uuid_map = FileUUIDMap.objects.get_fileuuidmap_by_uuid(file_uuid)
|
||||
if not uuid_map:
|
||||
error_msg = 'seadoc uuid %s not found.' % file_uuid
|
||||
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
||||
|
||||
filetype, fileext = get_file_type_and_ext(uuid_map.filename)
|
||||
if filetype != SEADOC:
|
||||
error_msg = 'seadoc file type %s invalid.' % filetype
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
# currently only implement unlock file
|
||||
sdoc_status = request.POST.get('status', '')
|
||||
if sdoc_status != 'no_write':
|
||||
error_msg = 'status invalid.'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
# unlock file
|
||||
repo_id = uuid_map.repo_id
|
||||
file_path = posixpath.join(uuid_map.parent_path, uuid_map.filename)
|
||||
try:
|
||||
if is_pro_version() and if_locked_by_online_office(repo_id, file_path):
|
||||
seafile_api.unlock_file(repo_id, file_path)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
error_msg = 'Internal Server Error'
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||
|
||||
return Response({'success': True})
|
||||
|
@ -3,8 +3,7 @@ from .apis import SeadocAccessToken, SeadocUploadLink, SeadocDownloadLink, Seado
|
||||
SeadocUploadImage, SeadocDownloadImage, SeadocAsyncCopyImages, SeadocQueryCopyMoveProgressView, SeadocCopyHistoryFile, SeadocHistory, SeadocDrafts, SeadocMaskAsDraft, \
|
||||
SeadocCommentsView, SeadocCommentView, SeadocStartRevise, SeadocPublishRevision, SeadocRevisionsCount, SeadocRevisions, \
|
||||
SeadocCommentRepliesView, SeadocCommentReplyView, SeadocFileView, SeadocFileUUIDView, SeadocDirView, SdocRevisionBaseVersionContent, SeadocRevisionView, \
|
||||
SeadocFilesInfoView, DeleteSeadocOtherRevision, SeadocPublishedRevisionContent, SdocParticipantsView, SdocParticipantView, SdocRelatedUsers
|
||||
|
||||
SeadocFilesInfoView, DeleteSeadocOtherRevision, SeadocPublishedRevisionContent, SdocParticipantsView, SdocParticipantView, SdocRelatedUsers,SeadocEditorCallBack
|
||||
|
||||
# api/v2.1/seadoc/
|
||||
urlpatterns = [
|
||||
@ -40,4 +39,5 @@ urlpatterns = [
|
||||
re_path(r'^participants/(?P<file_uuid>[-0-9a-f]{36})/$', SdocParticipantsView.as_view(), name='seadoc_participants_view'),
|
||||
re_path(r'^participant/(?P<file_uuid>[-0-9a-f]{36})/$', SdocParticipantView.as_view(), name='seadoc_participant_view'),
|
||||
re_path(r'^related-users/(?P<file_uuid>[-0-9a-f]{36})/$', SdocRelatedUsers.as_view(), name='seadoc_related_users_view'),
|
||||
re_path(r'^editor-status-callback/(?P<file_uuid>[-0-9a-f]{36})/$', SeadocEditorCallBack.as_view(), name='seadoc_editor_callback'),
|
||||
]
|
||||
|
@ -1,6 +1,6 @@
|
||||
{% extends 'file_view_react.html' %}
|
||||
{% load render_bundle from webpack_loader %}
|
||||
{% load seahub_tags %}
|
||||
{% load seahub_tags i18n static %}
|
||||
|
||||
{% block extra_style %}
|
||||
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}sdoc-editor/sdoc-editor-font.css" />
|
||||
@ -31,6 +31,66 @@ isSdocDraft: {% if is_sdoc_draft %}true{% else %}false{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block render_bundle %}
|
||||
<script type="text/javascript" src="{% static "scripts/lib/jquery.min.js" %}"></script>
|
||||
<script type="text/javascript" src="{{ MEDIA_URL }}js/jq.min.js"></script>
|
||||
<script type="text/javascript" src="{{ MEDIA_URL }}js/base.js?t=1536127546642"></script>
|
||||
<script src="{{ MEDIA_URL }}js/init-scroll-bar.js" ></script>
|
||||
<script type="text/javascript">
|
||||
var SEAFILE_GLOBAL = {
|
||||
csrfCookieName: '{{ CSRF_COOKIE_NAME }}'
|
||||
};
|
||||
{% if can_edit_file %}
|
||||
var interval;
|
||||
{% if not share_link_token %}
|
||||
var refreshLock = function() {
|
||||
$.ajax({
|
||||
url: '{% url "api-v2.1-file-view" repo.id %}' + '?p={{path|urlencode}}',
|
||||
type: 'PUT',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
'operation': 'refresh-lock',
|
||||
'expire': 2400
|
||||
},
|
||||
cache: false,
|
||||
beforeSend: prepareCSRFToken,
|
||||
success: function(data) {
|
||||
},
|
||||
error: function(xhr) {
|
||||
if (xhr.responseText) {
|
||||
feedback(JSON.parse(xhr.responseText).error_msg, 'error');
|
||||
} else {
|
||||
feedback("{% trans "Failed. Please check the network." %}", 'error');
|
||||
}
|
||||
clearInterval(interval);
|
||||
}
|
||||
});
|
||||
};
|
||||
{% else %}
|
||||
var refreshLock = function() {
|
||||
$.ajax({
|
||||
url: '{% url "api-v2.1-share-link-online-office-lock" share_link_token %}',
|
||||
type: 'PUT',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
'expire': 2400
|
||||
},
|
||||
cache: false,
|
||||
beforeSend: prepareCSRFToken,
|
||||
success: function(data) {
|
||||
},
|
||||
error: function(xhr) {
|
||||
if (xhr.responseText) {
|
||||
feedback(JSON.parse(xhr.responseText).error_msg, 'error');
|
||||
} else {
|
||||
feedback("{% trans "Failed. Please check the network." %}", 'error');
|
||||
}
|
||||
clearInterval(interval);
|
||||
}
|
||||
});
|
||||
};
|
||||
{% endif %}
|
||||
interval = setInterval(refreshLock, 30 * 60 * 1000);
|
||||
{% endif %}
|
||||
</script>
|
||||
{% render_bundle 'viewFileSdoc' 'js' %}
|
||||
{% endblock %}
|
||||
|
@ -664,6 +664,17 @@ def view_lib_file(request, repo_id, path):
|
||||
can_edit_file = False
|
||||
return_dict['can_edit_file'] = can_edit_file
|
||||
|
||||
if is_pro_version() and can_edit_file:
|
||||
try:
|
||||
if not is_locked:
|
||||
seafile_api.lock_file(repo_id, path, ONLINE_OFFICE_LOCK_OWNER,
|
||||
int(time.time()) + 40 * 60)
|
||||
elif locked_by_online_office:
|
||||
seafile_api.refresh_file_lock(repo_id, path,
|
||||
int(time.time()) + 40 * 60)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
||||
seadoc_perm = 'rw' if can_edit_file else 'r'
|
||||
return_dict['seadoc_access_token'] = gen_seadoc_access_token(file_uuid, filename, username, permission=seadoc_perm)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user