diff --git a/seahub/api2/views.py b/seahub/api2/views.py index daca9c93c3..c588651961 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -71,7 +71,7 @@ from seahub.utils import gen_file_get_url, gen_token, gen_file_upload_url, \ gen_block_get_url, get_file_type_and_ext, HAS_FILE_SEARCH, \ gen_file_share_link, gen_dir_share_link, is_org_context, gen_shared_link, \ get_org_user_events, calculate_repos_last_modify, send_perm_audit_msg, \ - gen_shared_upload_link, convert_cmmt_desc_link, enable_org_repo_creation + gen_shared_upload_link, convert_cmmt_desc_link, is_org_repo_creation_allowed from seahub.utils.repo import get_sub_repo_abbrev_origin_path from seahub.utils.star import star_file, unstar_file from seahub.utils.file_types import IMAGE, DOCUMENT @@ -1076,11 +1076,11 @@ class RepoPublic(APIView): """ repo = get_repo(repo_id) if not repo: - return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.') + return api_error(status.HTTP_404_NOT_FOUND, 'Library %s not found.' % repo_id) - if not enable_org_repo_creation(request): + if not is_org_repo_creation_allowed(request): return api_error(status.HTTP_403_FORBIDDEN, - 'Failed to share library to public: permission denied.') + 'Permission denied.') if check_permission(repo_id, request.user.username) != 'rw': return api_error(status.HTTP_403_FORBIDDEN, @@ -3214,7 +3214,7 @@ class SharedRepo(APIView): elif share_type == 'public': if not CLOUD_MODE: - if not enable_org_repo_creation(request): + if not is_org_repo_creation_allowed(request): return api_error(status.HTTP_403_FORBIDDEN, 'Failed to share library to public: permission denied.') diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 842fedf910..f110fbdf65 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -1312,8 +1312,8 @@ def within_time_range(d1, d2, maxdiff_seconds): diff = (delta.microseconds + (delta.seconds + delta.days*24*3600) * 1e6) / 1e6 return diff < maxdiff_seconds -def enable_org_repo_creation(request): - """Whether or not enable organization library. +def is_org_repo_creation_allowed(request): + """Whether or not allow a user create organization library. """ if request.user.is_staff: return True diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index 1c31db4b7b..901e6c0f16 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -54,7 +54,7 @@ from seahub.utils import render_permission_error, render_error, list_to_string, TRAFFIC_STATS_ENABLED, get_user_traffic_stat, new_merge_with_no_conflict, \ user_traffic_over_limit, send_perm_audit_msg, get_origin_repo_info, \ get_max_upload_file_size, is_pro_version, FILE_AUDIT_ENABLED, \ - enable_org_repo_creation + is_org_repo_creation_allowed from seahub.utils.paginator import get_page_range from seahub.utils.star import get_dir_starred_files from seahub.utils.timeutils import utc_to_local @@ -1268,7 +1268,7 @@ def libraries(request): UserOptions.objects.disable_user_guide(username) folder_perm_enabled = True if is_pro_version() and ENABLE_FOLDER_PERM else False - can_add_pub_repo = True if enable_org_repo_creation(request) else False + can_add_pub_repo = True if is_org_repo_creation_allowed(request) else False return render_to_response('libraries.html', { "allow_public_share": allow_public_share, diff --git a/tests/api/test_public_repo.py b/tests/api/test_public_repo.py index 699319b45d..9b73a32bf2 100644 --- a/tests/api/test_public_repo.py +++ b/tests/api/test_public_repo.py @@ -67,4 +67,4 @@ class RepoPublicTest(BaseTestCase): resp = self.client.post(self.user_repo_url) self.assertEqual(403, resp.status_code) json_resp = json.loads(resp.content) - assert json_resp['error_msg'] == 'Failed to share library to public: permission denied.' + assert json_resp['error_msg'] == 'Permission denied.'