mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 10:50:24 +00:00
SeadocDrafts (#5519)
This commit is contained in:
@@ -506,6 +506,44 @@ class SeadocHistory(APIView):
|
||||
})
|
||||
|
||||
|
||||
class SeadocDrafts(APIView):
|
||||
|
||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||
permission_classes = (IsAuthenticated,)
|
||||
throttle_classes = (UserRateThrottle, )
|
||||
|
||||
def get(self, request, repo_id):
|
||||
"""list drafts
|
||||
"""
|
||||
username = request.user.username
|
||||
# argument check
|
||||
owned = request.GET.get('owned')
|
||||
|
||||
# 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)
|
||||
|
||||
#
|
||||
if owned:
|
||||
draft_queryset = SeadocDraft.objects.filter(
|
||||
repo_id=repo_id, username=username)
|
||||
# all
|
||||
else:
|
||||
draft_queryset = SeadocDraft.objects.list_by_repo_id(repo_id)
|
||||
|
||||
drafts = [draft.to_dict() for draft in draft_queryset]
|
||||
|
||||
return Response({'drafts': drafts})
|
||||
|
||||
|
||||
class SeadocMaskAsDraft(APIView):
|
||||
|
||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||
@@ -550,7 +588,8 @@ class SeadocMaskAsDraft(APIView):
|
||||
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, username)
|
||||
draft = SeadocDraft.objects.mask_as_draft(
|
||||
file_uuid, repo_id, username)
|
||||
|
||||
return Response(draft.to_dict())
|
||||
|
||||
|
@@ -40,8 +40,9 @@ class SeadocDraftManager(models.Manager):
|
||||
def get_by_doc_uuid(self, doc_uuid):
|
||||
return self.filter(doc_uuid=doc_uuid).first()
|
||||
|
||||
def mask_as_draft(self, doc_uuid, username):
|
||||
return self.create(doc_uuid=doc_uuid, username=username)
|
||||
def mask_as_draft(self, doc_uuid, repo_id, username):
|
||||
return self.create(
|
||||
doc_uuid=doc_uuid, repo_id=repo_id, username=username)
|
||||
|
||||
def unmask_as_draft(self, doc_uuid):
|
||||
return self.filter(doc_uuid=doc_uuid).delete()
|
||||
@@ -52,9 +53,13 @@ class SeadocDraftManager(models.Manager):
|
||||
def list_by_username(self, username):
|
||||
return self.filter(username=username)
|
||||
|
||||
def list_by_repo_id(self, repo_id):
|
||||
return self.filter(repo_id=repo_id)
|
||||
|
||||
|
||||
class SeadocDraft(models.Model):
|
||||
doc_uuid = models.CharField(max_length=36, unique=True)
|
||||
repo_id = models.CharField(max_length=36, db_index=True)
|
||||
username = models.CharField(max_length=255, db_index=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
@@ -65,8 +70,8 @@ class SeadocDraft(models.Model):
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.pk,
|
||||
'doc_uuid': self.doc_uuid,
|
||||
'repo_id': self.repo_id,
|
||||
'username': self.username,
|
||||
'created_at': datetime_to_isoformat_timestr(self.created_at),
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from django.urls import re_path
|
||||
from .apis import SeadocAccessToken, SeadocUploadLink, SeadocDownloadLink, SeadocUploadFile, \
|
||||
SeadocUploadImage, SeadocDownloadImage, SeadocCopyHistoryFile, SeadocHistory, SeadocMaskAsDraft
|
||||
SeadocUploadImage, SeadocDownloadImage, SeadocCopyHistoryFile, SeadocHistory, SeadocDrafts, SeadocMaskAsDraft
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^access-token/(?P<repo_id>[-0-9a-f]{36})/$', SeadocAccessToken.as_view(), name='seadoc_access_token'),
|
||||
@@ -11,5 +11,6 @@ urlpatterns = [
|
||||
re_path(r'^download-image/(?P<file_uuid>[-0-9a-f]{36})/(?P<filename>.*)$', SeadocDownloadImage.as_view(), name='seadoc_download_image'),
|
||||
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'^drafts/(?P<repo_id>[-0-9a-f]{36})/$', SeadocDrafts.as_view(), name='seadoc_drafts'),
|
||||
re_path(r'^mask-as-draft/(?P<repo_id>[-0-9a-f]{36})/$', SeadocMaskAsDraft.as_view(), name='seadoc_mask_as_draft'),
|
||||
]
|
||||
|
@@ -1388,10 +1388,12 @@ CREATE TABLE `history_name` (
|
||||
|
||||
CREATE TABLE `sdoc_draft` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`doc_uuid` char(36) NOT NULL,
|
||||
`doc_uuid` varchar(36) NOT NULL,
|
||||
`repo_id` varchar(36) NOT NULL,
|
||||
`username` varchar(255) NOT NULL,
|
||||
`created_at` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `sdoc_draft_doc_uuid` (`doc_uuid`),
|
||||
KEY `sdoc_draft_repo_id` (`repo_id`),
|
||||
KEY `sdoc_draft_username` (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
Reference in New Issue
Block a user