1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 07:27:04 +00:00

share link duplicate generate, return error msg and 400 (#3789)

* share link duplicate generate, return error msg and 400

* add test case
This commit is contained in:
Leo
2019-07-04 16:22:50 +08:00
committed by lian
parent 3e28f5da62
commit b0d05f615f
3 changed files with 48 additions and 8 deletions

View File

@@ -128,6 +128,8 @@ class GenerateShareLink extends React.Component {
seafileAPI.createShareLink(repoID, itemPath, password, expireDays, permissions).then((res) => { seafileAPI.createShareLink(repoID, itemPath, password, expireDays, permissions).then((res) => {
let sharedLinkInfo = new SharedLinkInfo(res.data); let sharedLinkInfo = new SharedLinkInfo(res.data);
this.setState({sharedLinkInfo: sharedLinkInfo}); this.setState({sharedLinkInfo: sharedLinkInfo});
}).catch((error) => {
toaster.danger(error.response.data.error_msg);
}); });
} }
} }

View File

@@ -296,17 +296,21 @@ class ShareLinks(APIView):
org_id = request.user.org.org_id if is_org_context(request) else None org_id = request.user.org.org_id if is_org_context(request) else None
if s_type == 'f': if s_type == 'f':
fs = FileShare.objects.get_file_link_by_path(username, repo_id, path) fs = FileShare.objects.get_file_link_by_path(username, repo_id, path)
if not fs: if fs:
fs = FileShare.objects.create_file_link(username, repo_id, path, error_msg = _(u'Share link %s already exists.' % fs.token)
password, expire_date, return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
permission=perm, org_id=org_id) fs = FileShare.objects.create_file_link(username, repo_id, path,
password, expire_date,
permission=perm, org_id=org_id)
elif s_type == 'd': elif s_type == 'd':
fs = FileShare.objects.get_dir_link_by_path(username, repo_id, path) fs = FileShare.objects.get_dir_link_by_path(username, repo_id, path)
if not fs: if fs:
fs = FileShare.objects.create_dir_link(username, repo_id, path, error_msg = _(u'Share link %s already exists.' % fs.token)
password, expire_date, return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
permission=perm, org_id=org_id) fs = FileShare.objects.create_dir_link(username, repo_id, path,
password, expire_date,
permission=perm, org_id=org_id)
link_info = get_share_link_info(fs) link_info = get_share_link_info(fs)
return Response(link_info) return Response(link_info)

View File

@@ -105,6 +105,23 @@ class ShareLinksTest(BaseTestCase):
self._remove_share_link(json_resp['token']) self._remove_share_link(json_resp['token'])
def test_create_duplicate_file_share_link(self):
self.login_as(self.user)
resp = self.client.post(self.url, {'path': self.file_path, 'repo_id': self.repo_id})
self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content)
assert json_resp['token'] is not None
token = json_resp['token']
resp = self.client.post(self.url, {'path': self.file_path, 'repo_id': self.repo_id})
self.assertEqual(400, resp.status_code)
json_resp = json.loads(resp.content)
assert json_resp['error_msg'] is not None
assert token in json_resp['error_msg']
self._remove_share_link(token)
def test_create_file_share_link_in_enc_repo(self): def test_create_file_share_link_in_enc_repo(self):
self.login_as(self.user) self.login_as(self.user)
@@ -208,6 +225,23 @@ class ShareLinksTest(BaseTestCase):
self._remove_share_link(json_resp['token']) self._remove_share_link(json_resp['token'])
def test_create_duplicate_dir_share_link(self):
self.login_as(self.user)
resp = self.client.post(self.url, {'path': self.folder_path, 'repo_id': self.repo_id})
self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content)
assert json_resp['token'] is not None
token = json_resp['token']
resp = self.client.post(self.url, {'path': self.folder_path, 'repo_id': self.repo_id})
self.assertEqual(400, resp.status_code)
json_resp = json.loads(resp.content)
assert json_resp['error_msg'] is not None
assert token in json_resp['error_msg']
self._remove_share_link(token)
def test_create_link_with_invalid_repo_permission(self): def test_create_link_with_invalid_repo_permission(self):
# login with admin to create share link in user repo # login with admin to create share link in user repo
self.login_as(self.admin) self.login_as(self.admin)