From 8f1c13e68b94e1490901883c38698b3ecf792b28 Mon Sep 17 00:00:00 2001 From: lian Date: Thu, 25 Nov 2021 15:08:50 +0800 Subject: [PATCH 1/2] remove ENABLE_USER_CREATE_ORG_REPO --- frontend/src/pages/sys-admin/web-settings/web-settings.js | 7 ------- seahub/api2/endpoints/admin/web_settings.py | 2 +- seahub/base/accounts.py | 3 +-- seahub/settings.py | 5 ----- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/frontend/src/pages/sys-admin/web-settings/web-settings.js b/frontend/src/pages/sys-admin/web-settings/web-settings.js index 053f5102f4..c170ee0090 100644 --- a/frontend/src/pages/sys-admin/web-settings/web-settings.js +++ b/frontend/src/pages/sys-admin/web-settings/web-settings.js @@ -320,13 +320,6 @@ class WebSettings extends Component { value={config_dict['SHARE_LINK_PASSWORD_STRENGTH_LEVEL']} helpTip={gettext('The level(1-4) of a share/upload link password\'s strength. For example, \'3\' means password must have at least 3 of the following: num, upper letter, lower letter and other symbols')} /> - Date: Thu, 25 Nov 2021 17:32:41 +0800 Subject: [PATCH 2/2] update test --- .../api/endpoints/admin/test_web_settings.py | 6 +-- tests/api/test_public_repo.py | 19 +++------- tests/api/test_shared_repo.py | 14 ++----- tests/seahub/base/test_accounts.py | 37 +++++-------------- 4 files changed, 21 insertions(+), 55 deletions(-) diff --git a/tests/api/endpoints/admin/test_web_settings.py b/tests/api/endpoints/admin/test_web_settings.py index 81477ceee7..94a7988f0b 100644 --- a/tests/api/endpoints/admin/test_web_settings.py +++ b/tests/api/endpoints/admin/test_web_settings.py @@ -6,6 +6,7 @@ from seahub.test_utils import BaseTestCase class AdminWebSettingsTest(BaseTestCase): + def setUp(self): self.url = reverse('api-v2.1-web-settings') self.login_as(self.admin) @@ -27,9 +28,9 @@ class AdminWebSettingsTest(BaseTestCase): self.assertEqual(200, resp.status_code) json_resp = json.loads(resp.content) - assert len(json_resp) == 30 + assert len(json_resp) == 29 - @override_settings(ENABLE_SETTINGS_VIA_WEB = False) + @override_settings(ENABLE_SETTINGS_VIA_WEB=False) def test_get_with_enable_settings(self): resp = self.client.get(self.url) self.assertEqual(404, resp.status_code) @@ -37,7 +38,6 @@ class AdminWebSettingsTest(BaseTestCase): def test_update_web_settings_info(self): data = { "DISABLE_SYNC_WITH_ANY_FOLDER": False, - "ENABLE_USER_CREATE_ORG_REPO": True, "SHARE_LINK_TOKEN_LENGTH": 20, "REPO_PASSWORD_MIN_LENGTH": 10, "REGISTRATION_SEND_MAIL": False, diff --git a/tests/api/test_public_repo.py b/tests/api/test_public_repo.py index 12d84d9337..eff0ab560a 100644 --- a/tests/api/test_public_repo.py +++ b/tests/api/test_public_repo.py @@ -1,15 +1,14 @@ import json - import pytest -pytestmark = pytest.mark.django_db - -from seaserv import seafile_api, ccnet_threaded_rpc - -from seahub.test_utils import BaseTestCase from mock import patch, MagicMock +from seaserv import seafile_api +from seahub.test_utils import BaseTestCase + +pytestmark = pytest.mark.django_db class RepoPublicTest(BaseTestCase): + def setUp(self): from constance import config self.config = config @@ -20,8 +19,6 @@ class RepoPublicTest(BaseTestCase): self.url = '/api2/shared-repos/%s/' % self.repo_id self.user_repo_url = '/api2/shared-repos/%s/' % self.repo.id - self.config.ENABLE_USER_CREATE_ORG_REPO = 1 - def tearDown(self): self.remove_repo(self.repo_id) # clear cache between every test case to avoid config option cache issue @@ -63,9 +60,6 @@ class RepoPublicTest(BaseTestCase): self.assertEqual(403, resp.status_code) def test_admin_can_set_pub_repo_when_setting_disalbed(self): - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True - self.config.ENABLE_USER_CREATE_ORG_REPO = False - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False self.login_as(self.admin) @@ -75,9 +69,6 @@ class RepoPublicTest(BaseTestCase): assert 'success' in json_resp def test_user_can_not_set_pub_repo_when_setting_disalbed(self): - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True - self.config.ENABLE_USER_CREATE_ORG_REPO = False - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False self.login_as(self.user) diff --git a/tests/api/test_shared_repo.py b/tests/api/test_shared_repo.py index c7a75f691a..7dbd84bcaf 100644 --- a/tests/api/test_shared_repo.py +++ b/tests/api/test_shared_repo.py @@ -1,12 +1,13 @@ import pytest -pytestmark = pytest.mark.django_db - +from mock import patch, MagicMock from seahub.test_utils import BaseTestCase from seaserv import seafile_api -from mock import patch, MagicMock + +pytestmark = pytest.mark.django_db class SharedRepoTest(BaseTestCase): + def setUp(self): from constance import config self.config = config @@ -15,7 +16,6 @@ class SharedRepoTest(BaseTestCase): username=self.admin.username, passwd=None) self.shared_repo_url = '/api2/shared-repos/%s/?share_type=public&permission=rw' - self.config.ENABLE_USER_CREATE_ORG_REPO = 1 def tearDown(self): self.remove_repo(self.repo_id) @@ -48,9 +48,6 @@ class SharedRepoTest(BaseTestCase): self.assertEqual(403, resp.status_code) def test_admin_can_set_pub_repo_when_setting_disalbed(self): - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True - self.config.ENABLE_USER_CREATE_ORG_REPO = False - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False self.login_as(self.admin) @@ -59,9 +56,6 @@ class SharedRepoTest(BaseTestCase): assert b"success" in resp.content def test_user_can_not_set_pub_repo_when_setting_disalbed(self): - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True - self.config.ENABLE_USER_CREATE_ORG_REPO = False - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False self.login_as(self.user) diff --git a/tests/seahub/base/test_accounts.py b/tests/seahub/base/test_accounts.py index 367cf00fff..aad7558efc 100644 --- a/tests/seahub/base/test_accounts.py +++ b/tests/seahub/base/test_accounts.py @@ -1,12 +1,11 @@ import copy +from mock import patch +from django.test import override_settings + from seahub.test_utils import BaseTestCase from seahub.base.accounts import User, RegistrationForm - from seahub.options.models import UserOptions from seahub.role_permissions.settings import ENABLED_ROLE_PERMISSIONS -from django.urls import reverse -from django.test import override_settings -from mock import patch TEST_CAN_ADD_PUBLICK_REPO_TRUE = copy.deepcopy(ENABLED_ROLE_PERMISSIONS) @@ -19,7 +18,9 @@ CLOUD_MODE_TRUE = True MULTI_TENANCY_TRUE = True MULTI_TENANCY_FALSE = False + class UserTest(BaseTestCase): + def test_freeze_user(self): u = User.objects.get(self.user.username) @@ -39,11 +40,13 @@ class UserTest(BaseTestCase): user = User.objects.get(email=test_email) user.delete() - + assert len(UserOptions.objects.filter(email=test_email)) == 0 + @override_settings(ENABLE_WIKI=True) class UserPermissionsTest(BaseTestCase): + def setUp(self): from constance import config self.config = config @@ -76,31 +79,10 @@ class UserPermissionsTest(BaseTestCase): def test_user_permissions_can_add_public_repo(self): # both have - self.config.ENABLE_USER_CREATE_ORG_REPO = 1 - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True with patch('seahub.role_permissions.utils.ENABLED_ROLE_PERMISSIONS', TEST_CAN_ADD_PUBLICK_REPO_TRUE): assert self.user.permissions._get_perm_by_roles('can_add_public_repo') is True assert self.user.permissions.can_add_public_repo() is True - # only have can_add_public_repo - self.config.ENABLE_USER_CREATE_ORG_REPO = 0 - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False - with patch('seahub.role_permissions.utils.ENABLED_ROLE_PERMISSIONS', TEST_CAN_ADD_PUBLICK_REPO_TRUE): - assert self.user.permissions._get_perm_by_roles('can_add_public_repo') is True - assert self.user.permissions.can_add_public_repo() is False - - # only have ENABLE_USER_CREATE_ORG_REPO - self.config.ENABLE_USER_CREATE_ORG_REPO = 1 - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True - assert self.user.permissions._get_perm_by_roles('can_add_public_repo') is False - assert self.user.permissions.can_add_public_repo() is False - - # neither have - self.config.ENABLE_USER_CREATE_ORG_REPO = 0 - assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False - assert self.user.permissions._get_perm_by_roles('can_add_public_repo') is False - assert self.user.permissions.can_add_public_repo() is False - def test_can_publish_repo_permission(self): # enableWIKI = True, and can_publish_repo = True assert self.user.permissions._get_perm_by_roles('can_publish_repo') is True @@ -148,7 +130,6 @@ class RegistrationFormTest(BaseTestCase): def test_clean_email(self): form = self.form_class({'email': 'some_random_user@1.com', 'password1': '123', - 'password2': '123', - }) + 'password2': '123'}) assert form.is_valid() is True assert form.clean_email() == 'some_random_user@1.com'