1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 17:33:18 +00:00

update cancel_cp

This commit is contained in:
lian
2016-08-23 17:02:32 +08:00
committed by lian
parent 4a120b5aa5
commit 734263b76e
6 changed files with 60 additions and 28 deletions

View File

@@ -0,0 +1,49 @@
# Copyright (c) 2012-2016 Seafile Ltd.
import logging
from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from django.utils.translation import ugettext as _
from seahub.api2.throttling import UserRateThrottle
from seahub.api2.authentication import TokenAuthentication
from seahub.api2.utils import api_error
from seaserv import seafile_api
logger = logging.getLogger(__name__)
class CopyMoveTaskView(APIView):
authentication_classes = (TokenAuthentication, SessionAuthentication)
permission_classes = (IsAuthenticated,)
throttle_classes = (UserRateThrottle,)
def delete(self, request):
""" Cancel file/dir mv/cp.
Permission checking:
1. user login;
"""
# argument check
task_id = request.data.get('task_id')
if not task_id:
error_msg = 'task_id invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
try:
res = seafile_api.cancel_copy_task(task_id) # returns 0 or -1
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
if res == 0:
return Response({'success': True})
else:
error_msg = _('Cancel failed')
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

View File

@@ -31,6 +31,7 @@ from seahub.api2.endpoints.dirents_download_link import DirentsDownloadLinkView
from seahub.api2.endpoints.zip_task import ZipTaskView from seahub.api2.endpoints.zip_task import ZipTaskView
from seahub.api2.endpoints.share_link_zip_task import ShareLinkZipTaskView from seahub.api2.endpoints.share_link_zip_task import ShareLinkZipTaskView
from seahub.api2.endpoints.query_zip_progress import QueryZipProgressView from seahub.api2.endpoints.query_zip_progress import QueryZipProgressView
from seahub.api2.endpoints.copy_move_task import CopyMoveTaskView
from seahub.api2.endpoints.query_copy_move_progress import QueryCopyMoveProgressView from seahub.api2.endpoints.query_copy_move_progress import QueryCopyMoveProgressView
from seahub.api2.endpoints.invitations import InvitationsView from seahub.api2.endpoints.invitations import InvitationsView
from seahub.api2.endpoints.invitation import InvitationView from seahub.api2.endpoints.invitation import InvitationView
@@ -140,7 +141,6 @@ urlpatterns = patterns(
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/delete/$', delete_dirent, name='delete_dir'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/delete/$', delete_dirent, name='delete_dir'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/mv/$', mv_dir, name='mv_dir'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/mv/$', mv_dir, name='mv_dir'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/cp/$', cp_dir, name='cp_dir'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dir/cp/$', cp_dir, name='cp_dir'),
url(r'^ajax/cancel_cp/$', cancel_cp, name='cancel_cp'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/rename/$', rename_dirent, name='rename_file'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/rename/$', rename_dirent, name='rename_file'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/delete/$', delete_dirent, name='delete_file'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/delete/$', delete_dirent, name='delete_file'),
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/mv/$', mv_file, name='mv_file'), url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/file/mv/$', mv_file, name='mv_file'),
@@ -191,6 +191,7 @@ urlpatterns = patterns(
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/zip-task/$', ZipTaskView.as_view(), name='api-v2.1-zip-task'), url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/zip-task/$', ZipTaskView.as_view(), name='api-v2.1-zip-task'),
url(r'^api/v2.1/share-link-zip-task/$', ShareLinkZipTaskView.as_view(), name='api-v2.1-share-link-zip-task'), url(r'^api/v2.1/share-link-zip-task/$', ShareLinkZipTaskView.as_view(), name='api-v2.1-share-link-zip-task'),
url(r'^api/v2.1/query-zip-progress/$', QueryZipProgressView.as_view(), name='api-v2.1-query-zip-progress'), url(r'^api/v2.1/query-zip-progress/$', QueryZipProgressView.as_view(), name='api-v2.1-query-zip-progress'),
url(r'^api/v2.1/copy-move-task/$', CopyMoveTaskView.as_view(), name='api-v2.1-copy-move-task'),
url(r'^api/v2.1/query-copy-move-progress/$', QueryCopyMoveProgressView.as_view(), name='api-v2.1-query-copy-move-progress'), url(r'^api/v2.1/query-copy-move-progress/$', QueryCopyMoveProgressView.as_view(), name='api-v2.1-query-copy-move-progress'),
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/dir/$', DirView.as_view(), name='api-v2.1-dir-view'), url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/dir/$', DirView.as_view(), name='api-v2.1-dir-view'),
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/set-password/$', RepoSetPassword.as_view(), name="api-v2.1-repo-set-password"), url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/set-password/$', RepoSetPassword.as_view(), name="api-v2.1-repo-set-password"),

View File

@@ -999,30 +999,6 @@ def cp_dirents(request, src_repo_id, src_path, dst_repo_id, dst_path, obj_file_n
result = {'success': success, 'failed': failed, 'url': url} result = {'success': success, 'failed': failed, 'url': url}
return HttpResponse(json.dumps(result), content_type=content_type) return HttpResponse(json.dumps(result), content_type=content_type)
@login_required_ajax
def cancel_cp(request):
'''
cancel file/dir mv/cp.
'''
content_type = 'application/json; charset=utf-8'
result = {}
task_id = request.GET.get('task_id')
if not task_id:
result['error'] = _('Argument missing')
return HttpResponse(json.dumps(result), status=400,
content_type=content_type)
res = seafile_api.cancel_copy_task(task_id) # returns 0 or -1
if res == 0:
result['success'] = True
return HttpResponse(json.dumps(result), content_type=content_type)
else:
result['error'] = _('Cancel failed')
return HttpResponse(json.dumps(result), status=400,
content_type=content_type)
########## contacts related ########## contacts related
@login_required_ajax @login_required_ajax
def get_current_commit(request, repo_id): def get_current_commit(request, repo_id):

View File

@@ -140,8 +140,11 @@ define([
cancel_btn.click(function() { cancel_btn.click(function() {
Common.disableButton(cancel_btn); Common.disableButton(cancel_btn);
$.ajax({ $.ajax({
url: Common.getUrl({name: 'cancel_cp'}) + '?task_id=' + encodeURIComponent(task_id), url: Common.getUrl({name: 'copy_move_task'}),
type: 'DELETE',
dataType: 'json', dataType: 'json',
beforeSend: Common.prepareCSRFToken,
data: {'task_id': encodeURIComponent(task_id)},
success: function(data) { success: function(data) {
details.addClass('vh') details.addClass('vh')
other_info.html(gettext("Canceled.")).removeClass('hide'); other_info.html(gettext("Canceled.")).removeClass('hide');

View File

@@ -1272,8 +1272,11 @@ define([
Common.disableButton(cancel_btn); Common.disableButton(cancel_btn);
var task_id = $(this).data('task_id'); var task_id = $(this).data('task_id');
$.ajax({ $.ajax({
url: Common.getUrl({name:'cancel_cp'}) + '?task_id=' + encodeURIComponent(task_id), url: Common.getUrl({name: 'copy_move_task'}),
type: 'DELETE',
dataType: 'json', dataType: 'json',
beforeSend: Common.prepareCSRFToken,
data: {'task_id': encodeURIComponent(task_id)},
success: function(data) { success: function(data) {
other_info.html(gettext("Canceled.")).removeClass('hide'); other_info.html(gettext("Canceled.")).removeClass('hide');
cancel_btn.addClass('hide'); cancel_btn.addClass('hide');

View File

@@ -84,6 +84,7 @@ define([
case 'download_dir_zip_url': return fileServerRoot + 'zip/' + options.zip_token; case 'download_dir_zip_url': return fileServerRoot + 'zip/' + options.zip_token;
case 'zip_task': return siteRoot + 'api/v2.1/repos/' + options.repo_id + '/zip-task/'; case 'zip_task': return siteRoot + 'api/v2.1/repos/' + options.repo_id + '/zip-task/';
case 'query_zip_progress': return siteRoot + 'api/v2.1/query-zip-progress/'; case 'query_zip_progress': return siteRoot + 'api/v2.1/query-zip-progress/';
case 'copy_move_task': return siteRoot + 'api/v2.1/copy-move-task/';
case 'query_copy_move_progress': return siteRoot + 'api/v2.1/query-copy-move-progress/'; case 'query_copy_move_progress': return siteRoot + 'api/v2.1/query-copy-move-progress/';
case 'rename_dir': return siteRoot + 'api/v2.1/repos/' + options.repo_id + '/dir/'; case 'rename_dir': return siteRoot + 'api/v2.1/repos/' + options.repo_id + '/dir/';
case 'rename_file': return siteRoot + 'api/v2.1/repos/' + options.repo_id + '/file/'; case 'rename_file': return siteRoot + 'api/v2.1/repos/' + options.repo_id + '/file/';
@@ -97,7 +98,6 @@ define([
case 'del_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/delete/'; case 'del_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/delete/';
case 'mv_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/move/'; case 'mv_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/move/';
case 'cp_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/copy/'; case 'cp_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/copy/';
case 'cancel_cp': return siteRoot + 'ajax/cancel_cp/';
case 'get_file_op_url': return siteRoot + 'ajax/repo/' + options.repo_id + '/file_op_url/'; case 'get_file_op_url': return siteRoot + 'ajax/repo/' + options.repo_id + '/file_op_url/';
case 'get_file_uploaded_bytes': return siteRoot + 'ajax/repo/' + options.repo_id + '/get-file-uploaded-bytes/'; case 'get_file_uploaded_bytes': return siteRoot + 'ajax/repo/' + options.repo_id + '/get-file-uploaded-bytes/';
case 'get_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/'; case 'get_dirents': return siteRoot + 'ajax/repo/' + options.repo_id + '/dirents/';