mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-03 07:55:36 +00:00
update return value when copy/move file via web api
This commit is contained in:
@@ -2007,6 +2007,7 @@ class FileView(APIView):
|
||||
parent_dir = os.path.dirname(path)
|
||||
operation = request.POST.get('operation', '')
|
||||
|
||||
file_info = {}
|
||||
if operation.lower() == 'rename':
|
||||
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
@@ -2090,7 +2091,10 @@ class FileView(APIView):
|
||||
if request.GET.get('reloaddir', '').lower() == 'true':
|
||||
return reloaddir(request, dst_repo, dst_dir)
|
||||
else:
|
||||
resp = Response('success', status=status.HTTP_301_MOVED_PERMANENTLY)
|
||||
file_info['repo_id'] = dst_repo_id
|
||||
file_info['parent_dir'] = dst_dir
|
||||
file_info['obj_name'] = new_filename_utf8
|
||||
resp = Response(file_info, status=status.HTTP_301_MOVED_PERMANENTLY)
|
||||
uri = reverse('FileView', args=[dst_repo_id], request=request)
|
||||
resp['Location'] = uri + '?p=' + quote(dst_dir_utf8) + quote(new_filename_utf8)
|
||||
return resp
|
||||
@@ -2140,7 +2144,10 @@ class FileView(APIView):
|
||||
if request.GET.get('reloaddir', '').lower() == 'true':
|
||||
return reloaddir(request, dst_repo, dst_dir)
|
||||
else:
|
||||
resp = Response('success', status=status.HTTP_200_OK)
|
||||
file_info['repo_id'] = dst_repo_id
|
||||
file_info['parent_dir'] = dst_dir
|
||||
file_info['obj_name'] = new_filename_utf8
|
||||
resp = Response(file_info, status=status.HTTP_200_OK)
|
||||
uri = reverse('FileView', args=[dst_repo_id], request=request)
|
||||
resp['Location'] = uri + '?p=' + quote(dst_dir_utf8) + quote(new_filename_utf8)
|
||||
return resp
|
||||
|
@@ -8,6 +8,7 @@ import pytest
|
||||
import urllib
|
||||
from urllib import urlencode, quote
|
||||
import urlparse
|
||||
from nose.tools import assert_in
|
||||
|
||||
from tests.common.utils import randstring, urljoin
|
||||
from tests.api.apitestbase import ApiTestBase
|
||||
@@ -32,15 +33,70 @@ class FilesApiTest(ApiTestBase):
|
||||
|
||||
def test_move_file(self):
|
||||
with self.get_tmp_repo() as repo:
|
||||
_, furl = self.create_file(repo)
|
||||
# TODO: create another repo here, and use it as dst_repo
|
||||
|
||||
# create sub folder(dpath)
|
||||
dpath, _ = self.create_dir(repo)
|
||||
|
||||
# create tmp file in sub folder(dpath)
|
||||
tmp_file = 'tmp_file.txt'
|
||||
file_path = dpath + '/' + tmp_file
|
||||
furl = repo.get_filepath_url(file_path)
|
||||
data = {'operation': 'create'}
|
||||
res = self.post(furl, data=data, expected=201)
|
||||
|
||||
# copy tmp file from sub folder(dpath) to dst dir('/')
|
||||
data = {
|
||||
'operation': 'move',
|
||||
'dst_repo': repo.repo_id,
|
||||
'dst_dir': '/',
|
||||
'operation': 'copy',
|
||||
}
|
||||
res = self.post(furl, data=data)
|
||||
self.assertEqual(res.text, '"success"')
|
||||
u = urlparse.urlparse(furl)
|
||||
parsed_furl = urlparse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in(tmp_file, res.text)
|
||||
|
||||
# get info of copied file in dst dir('/')
|
||||
fdurl = repo.file_url + u'detail/?p=/%s' % quote(tmp_file)
|
||||
detail = self.get(fdurl).json()
|
||||
self.assertIsNotNone(detail)
|
||||
self.assertIsNotNone(detail['id'])
|
||||
|
||||
# copy tmp file from sub folder(dpath) to dst dir('/') again
|
||||
# for test can rename file if a file with the same name is dst dir
|
||||
data = {
|
||||
'dst_repo': repo.repo_id,
|
||||
'dst_dir': '/',
|
||||
'operation': 'copy',
|
||||
}
|
||||
u = urlparse.urlparse(furl)
|
||||
parsed_furl = urlparse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file (1).txt', res.text)
|
||||
|
||||
# copy tmp file from sub folder(dpath) to dst dir('/') again
|
||||
# for test can rename file if a file with the same name is dst dir
|
||||
data = {
|
||||
'dst_repo': repo.repo_id,
|
||||
'dst_dir': '/',
|
||||
'operation': 'copy',
|
||||
}
|
||||
u = urlparse.urlparse(furl)
|
||||
parsed_furl = urlparse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file (2).txt', res.text)
|
||||
|
||||
# then move file to dst dir
|
||||
data = {
|
||||
'dst_repo': repo.repo_id,
|
||||
'dst_dir': '/',
|
||||
'operation': 'move',
|
||||
}
|
||||
u = urlparse.urlparse(furl)
|
||||
parsed_furl = urlparse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file%20%283%29.txt', res.text)
|
||||
|
||||
|
||||
def test_copy_file(self):
|
||||
with self.get_tmp_repo() as repo:
|
||||
@@ -65,7 +121,7 @@ class FilesApiTest(ApiTestBase):
|
||||
u = urlparse.urlparse(furl)
|
||||
parsed_furl = urlparse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
self.assertEqual(res.text, '"success"')
|
||||
assert_in(tmp_file, res.text)
|
||||
|
||||
# get info of copied file in dst dir('/')
|
||||
fdurl = repo.file_url + u'detail/?p=/%s' % quote(tmp_file)
|
||||
@@ -73,6 +129,30 @@ class FilesApiTest(ApiTestBase):
|
||||
self.assertIsNotNone(detail)
|
||||
self.assertIsNotNone(detail['id'])
|
||||
|
||||
# copy tmp file from sub folder(dpath) to dst dir('/') again
|
||||
# for test can rename file if a file with the same name is dst dir
|
||||
data = {
|
||||
'dst_repo': repo.repo_id,
|
||||
'dst_dir': '/',
|
||||
'operation': 'copy',
|
||||
}
|
||||
u = urlparse.urlparse(furl)
|
||||
parsed_furl = urlparse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file (1).txt', res.text)
|
||||
|
||||
# copy tmp file from sub folder(dpath) to dst dir('/') again
|
||||
# for test can rename file if a file with the same name is dst dir
|
||||
data = {
|
||||
'dst_repo': repo.repo_id,
|
||||
'dst_dir': '/',
|
||||
'operation': 'copy',
|
||||
}
|
||||
u = urlparse.urlparse(furl)
|
||||
parsed_furl = urlparse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file (2).txt', res.text)
|
||||
|
||||
def test_download_file(self):
|
||||
with self.get_tmp_repo() as repo:
|
||||
fname, furl = self.create_file(repo)
|
||||
|
Reference in New Issue
Block a user