From d0c8235f13bc015ce1e4c9788ce6ab4ab0e187da Mon Sep 17 00:00:00 2001 From: lian Date: Thu, 22 Oct 2015 16:08:45 +0800 Subject: [PATCH] [api2] update ENABLE_ENCRYPTED_LIBRARY --- seahub/api2/views.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/seahub/api2/views.py b/seahub/api2/views.py index 0ed7bfc139..5ec34024e6 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -701,6 +701,12 @@ class Repos(APIView): def _create_repo(self, request, repo_name, repo_desc, username, org_id): passwd = request.DATA.get("passwd", None) + + # to avoid 'Bad magic' error when create repo, passwd should be 'None' + # not an empty string when create unencrypted repo + if not passwd: + passwd = None + if (passwd is not None) and (not config.ENABLE_ENCRYPTED_LIBRARY): return api_error(status.HTTP_403_FORBIDDEN, 'NOT allow to create encrypted library.') @@ -786,8 +792,16 @@ class PubRepos(APIView): 'Library name is required.') repo_desc = request.DATA.get("desc", '') passwd = request.DATA.get("passwd", None) + + # to avoid 'Bad magic' error when create repo, passwd should be 'None' + # not an empty string when create unencrypted repo if not passwd: passwd = None + + if (passwd is not None) and (not config.ENABLE_ENCRYPTED_LIBRARY): + return api_error(status.HTTP_403_FORBIDDEN, + 'NOT allow to create encrypted library.') + permission = request.DATA.get("permission", 'r') if permission != 'r' and permission != 'rw': return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid permission') @@ -3533,8 +3547,16 @@ class GroupRepos(APIView): repo_name = request.DATA.get("name", None) repo_desc = request.DATA.get("desc", '') passwd = request.DATA.get("passwd", None) + + # to avoid 'Bad magic' error when create repo, passwd should be 'None' + # not an empty string when create unencrypted repo if not passwd: passwd = None + + if (passwd is not None) and (not config.ENABLE_ENCRYPTED_LIBRARY): + return api_error(status.HTTP_403_FORBIDDEN, + 'NOT allow to create encrypted library.') + permission = request.DATA.get("permission", 'r') if permission != 'r' and permission != 'rw': return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid permission')