diff --git a/seahub/api2/urls.py b/seahub/api2/urls.py index df758d9332..182289fc0c 100644 --- a/seahub/api2/urls.py +++ b/seahub/api2/urls.py @@ -18,6 +18,7 @@ urlpatterns = patterns('', url(r'^repos/(?P[-0-9a-f]{36})/$', Repo.as_view(), name="api2-repo"), url(r'^repos/(?P[-0-9a-f]{36})/history/$', RepoHistory.as_view()), url(r'^repos/(?P[-0-9a-f]{36})/download-info/$', DownloadRepo.as_view()), + url(r'^repos/(?P[-0-9a-f]{36})/public/$', RepoPublic.as_view()), url(r'^repos/(?P[-0-9a-f]{36})/upload-link/$', UploadLinkView.as_view()), url(r'^repos/(?P[-0-9a-f]{36})/update-link/$', UpdateLinkView.as_view()), url(r'^repos/(?P[-0-9a-f]{36})/upload-blks-link/$', UploadBlksLinkView.as_view()), diff --git a/seahub/api2/views.py b/seahub/api2/views.py index 6527c1f792..c620b1c811 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -682,6 +682,41 @@ class DownloadRepo(APIView): return repo_download_info(request, repo_id) +class RepoPublic(APIView): + authentication_classes = (TokenAuthentication, ) + permission_classes = (IsAuthenticated,) + throttle_classes = (UserRateThrottle, ) + + def post(self, request, repo_id, format=None): + repo = get_repo(repo_id) + if not repo: + return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.') + + if check_permission(repo_id, request.user.username) != 'rw': + return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this repo.') + + try: + seafile_api.add_inner_pub_repo(repo_id, "r") + except: + return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Unable to make repo public') + + return HttpResponse(json.dumps({'success': True}), status=200, content_type=json_content_type) + + def delete(self, request, repo_id, format=None): + repo = get_repo(repo_id) + if not repo: + return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.') + + if check_permission(repo_id, request.user.username) != 'rw': + return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this repo.') + + try: + seafile_api.remove_inner_pub_repo(repo_id) + except: + return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Unable to make repo private') + + return HttpResponse(json.dumps({'success': True}), status=200, content_type=json_content_type) + class UploadLinkView(APIView): authentication_classes = (TokenAuthentication, ) permission_classes = (IsAuthenticated, )