mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-19 18:29:23 +00:00
Merge branch 'add-repo-api'
This commit is contained in:
@@ -10,8 +10,8 @@ urlpatterns = patterns('',
|
||||
|
||||
# RESTful API
|
||||
url(r'^account/info/$', Account.as_view()),
|
||||
url(r'^repos/$', Repos.as_view()),
|
||||
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/$', Repo.as_view()),
|
||||
url(r'^repos/$', Repos.as_view(), name="api2-repos"),
|
||||
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})/upload-link/$', UploadLinkView.as_view()),
|
||||
url(r'^repos/(?P<repo_id>[-0-9a-f]{36})/update-link/$', UpdateLinkView.as_view()),
|
||||
|
@@ -206,6 +206,31 @@ class Repos(APIView):
|
||||
|
||||
return Response(repos_json)
|
||||
|
||||
def post(self, request, format=None):
|
||||
username = request.user.username
|
||||
repo_name = request.POST.get("name", None)
|
||||
repo_desc= request.POST.get("desc", 'new repo')
|
||||
passwd = request.POST.get("passwd")
|
||||
if not repo_name:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, \
|
||||
'Library name is required.')
|
||||
|
||||
# create a repo
|
||||
try:
|
||||
repo_id = seafserv_threaded_rpc.create_repo(repo_name, repo_desc,
|
||||
username, passwd)
|
||||
except:
|
||||
return api_error(status.HTTP_520_OPERATION_FAILED, \
|
||||
'Failed to create library.')
|
||||
if not repo_id:
|
||||
return api_error(status.HTTP_520_OPERATION_FAILED, \
|
||||
'Failed to create library.')
|
||||
else:
|
||||
resp = Response('success', status=status.HTTP_201_CREATED)
|
||||
resp['Location'] = reverse('api2-repo', args=[repo_id])
|
||||
return resp
|
||||
|
||||
|
||||
def can_access_repo(request, repo_id):
|
||||
if not check_permission(repo_id, request.user.username):
|
||||
return False
|
||||
@@ -302,6 +327,20 @@ class Repo(APIView):
|
||||
|
||||
return Response("unsupported operation")
|
||||
|
||||
def delete(self, request, repo_id, format=None):
|
||||
username = request.user.username
|
||||
repo = seafile_api.get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, \
|
||||
'Library does not exist.')
|
||||
|
||||
if not seafile_api.is_repo_owner(username, repo_id):
|
||||
return api_error(status.HTTP_403_FORBIDDEN, \
|
||||
'Only library owner can perform this operation.')
|
||||
|
||||
seafile_api.remove_repo(repo_id)
|
||||
return Response('success', status=status.HTTP_200_OK)
|
||||
|
||||
class DownloadRepo(APIView):
|
||||
authentication_classes = (TokenAuthentication, )
|
||||
permission_classes = (IsAuthenticated, IsRepoAccessible, )
|
||||
|
Reference in New Issue
Block a user