1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-25 14:50:29 +00:00

[api2] Fixed add/delete repo bug

This commit is contained in:
zhengxie
2013-06-29 11:01:28 +08:00
parent a5f6120a5f
commit 85dcc522ce
2 changed files with 12 additions and 12 deletions

View File

@@ -10,8 +10,8 @@ urlpatterns = patterns('',
# RESTful API # RESTful API
url(r'^account/info/$', Account.as_view()), url(r'^account/info/$', Account.as_view()),
url(r'^repos/$', Repos.as_view(), name="Repos"), url(r'^repos/$', Repos.as_view(), name="api2-repos"),
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/$', Repo.as_view()), url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/$', Repo.as_view(), name="api2-repo"),
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/download-info/$', DownloadRepo.as_view()), url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/download-info/$', DownloadRepo.as_view()),
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/upload-link/$', UploadLinkView.as_view()), url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/upload-link/$', UploadLinkView.as_view()),
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/update-link/$', UpdateLinkView.as_view()), url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/update-link/$', UpdateLinkView.as_view()),

View File

@@ -213,7 +213,7 @@ class Repos(APIView):
passwd = request.POST.get("passwd") passwd = request.POST.get("passwd")
if not repo_name: if not repo_name:
return api_error(status.HTTP_400_BAD_REQUEST, \ return api_error(status.HTTP_400_BAD_REQUEST, \
'Please write repo name.') 'Library name is required.')
# create a repo # create a repo
try: try:
@@ -223,12 +223,11 @@ class Repos(APIView):
return api_error(status.HTTP_520_OPERATION_FAILED, \ return api_error(status.HTTP_520_OPERATION_FAILED, \
'Failed to create library.') 'Failed to create library.')
if not repo_id: if not repo_id:
return api_error(status.HTTP_520_BAD_REQUEST, \ return api_error(status.HTTP_520_OPERATION_FAILED, \
'Failed to create library.') 'Failed to create library.')
else: else:
resp = Response('success', status=status.HTTP_201_CREATED) resp = Response('success', status=status.HTTP_201_CREATED)
uri = reverse('Repos') resp['Location'] = reverse('api2-repo', args=[repo_id])
resp['Location'] = uri + repo_id + '/'
return resp return resp
@@ -330,14 +329,15 @@ class Repo(APIView):
def delete(self, request, repo_id, format=None): def delete(self, request, repo_id, format=None):
username = request.user.username username = request.user.username
repo = get_repo(repo_id) repo = seafile_api.get_repo(repo_id)
if not repo: if not repo:
return api_error(status.HTTP_400_BAD_REQUEST, \ return api_error(status.HTTP_400_BAD_REQUEST, \
'Library does not exist.') 'Library does not exist.')
if not can_access_repo(request, repo_id):
return api_error(status.HTTP_400_BAD_REQUEST, \ if not seafile_api.is_repo_owner(username, repo_id):
'You can not access this repo.') return api_error(status.HTTP_403_FORBIDDEN, \
print username, repo_id 'Only library owner can perform this operation.')
seafile_api.remove_repo(repo_id) seafile_api.remove_repo(repo_id)
return Response('success', status=status.HTTP_200_OK) return Response('success', status=status.HTTP_200_OK)