1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 00:43:53 +00:00

Merge pull request #5039 from haiwen/web-setting

remove ENABLE_USER_CREATE_ORG_REPO
This commit is contained in:
Daniel Pan
2021-11-26 10:56:21 +08:00
committed by GitHub
8 changed files with 23 additions and 70 deletions

View File

@@ -320,13 +320,6 @@ class WebSettings extends Component {
value={config_dict['SHARE_LINK_PASSWORD_STRENGTH_LEVEL']} 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')} 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')}
/> />
<CheckboxItem
saveSetting={this.saveSetting}
displayName='ENABLE_USER_CREATE_ORG_REPO'
keyText='ENABLE_USER_CREATE_ORG_REPO'
value={config_dict['ENABLE_USER_CREATE_ORG_REPO']}
helpTip={gettext('Allow user to add organization libraries. Otherwise, only system admin can add organization libraries.')}
/>
<CheckboxItem <CheckboxItem
saveSetting={this.saveSetting} saveSetting={this.saveSetting}
displayName='ENABLE_USER_CLEAN_TRASH' displayName='ENABLE_USER_CLEAN_TRASH'

View File

@@ -25,7 +25,7 @@ DIGIT_WEB_SETTINGS = [
'ENABLE_ENCRYPTED_LIBRARY', 'USER_PASSWORD_MIN_LENGTH', 'ENABLE_ENCRYPTED_LIBRARY', 'USER_PASSWORD_MIN_LENGTH',
'USER_PASSWORD_STRENGTH_LEVEL', 'SHARE_LINK_PASSWORD_MIN_LENGTH', 'USER_PASSWORD_STRENGTH_LEVEL', 'SHARE_LINK_PASSWORD_MIN_LENGTH',
'SHARE_LINK_FORCE_USE_PASSWORD', 'SHARE_LINK_PASSWORD_STRENGTH_LEVEL', 'SHARE_LINK_FORCE_USE_PASSWORD', 'SHARE_LINK_PASSWORD_STRENGTH_LEVEL',
'ENABLE_USER_CREATE_ORG_REPO', 'FORCE_PASSWORD_CHANGE', 'FORCE_PASSWORD_CHANGE',
'LOGIN_ATTEMPT_LIMIT', 'FREEZE_USER_ON_LOGIN_FAILED', 'LOGIN_ATTEMPT_LIMIT', 'FREEZE_USER_ON_LOGIN_FAILED',
'ENABLE_SHARE_TO_ALL_GROUPS', 'ENABLE_TWO_FACTOR_AUTH', 'ENABLE_SHARE_TO_ALL_GROUPS', 'ENABLE_TWO_FACTOR_AUTH',
'ENABLE_BRANDING_CSS', 'ENABLE_TERMS_AND_CONDITIONS', 'ENABLE_BRANDING_CSS', 'ENABLE_TERMS_AND_CONDITIONS',

View File

@@ -181,8 +181,7 @@ class UserPermissions(object):
return False return False
elif self.user.is_staff: elif self.user.is_staff:
return True return True
elif self._get_perm_by_roles('can_add_public_repo') and \ elif self._get_perm_by_roles('can_add_public_repo'):
bool(config.ENABLE_USER_CREATE_ORG_REPO):
return True return True
else: else:
return False return False

View File

@@ -435,9 +435,6 @@ ENABLE_UPDATE_USER_INFO = True
# Enable or disable repo history setting # Enable or disable repo history setting
ENABLE_REPO_HISTORY_SETTING = True ENABLE_REPO_HISTORY_SETTING = True
# Enable or disable org repo creation by user
ENABLE_USER_CREATE_ORG_REPO = True
DISABLE_SYNC_WITH_ANY_FOLDER = False DISABLE_SYNC_WITH_ANY_FOLDER = False
ENABLE_TERMS_AND_CONDITIONS = False ENABLE_TERMS_AND_CONDITIONS = False
@@ -907,8 +904,6 @@ CONSTANCE_CONFIG = {
'LOGIN_ATTEMPT_LIMIT': (LOGIN_ATTEMPT_LIMIT, ''), 'LOGIN_ATTEMPT_LIMIT': (LOGIN_ATTEMPT_LIMIT, ''),
'FREEZE_USER_ON_LOGIN_FAILED': (FREEZE_USER_ON_LOGIN_FAILED, ''), 'FREEZE_USER_ON_LOGIN_FAILED': (FREEZE_USER_ON_LOGIN_FAILED, ''),
'ENABLE_USER_CREATE_ORG_REPO': (ENABLE_USER_CREATE_ORG_REPO, ''),
'ENABLE_ENCRYPTED_LIBRARY': (ENABLE_ENCRYPTED_LIBRARY, ''), 'ENABLE_ENCRYPTED_LIBRARY': (ENABLE_ENCRYPTED_LIBRARY, ''),
'REPO_PASSWORD_MIN_LENGTH': (REPO_PASSWORD_MIN_LENGTH, ''), 'REPO_PASSWORD_MIN_LENGTH': (REPO_PASSWORD_MIN_LENGTH, ''),
'ENABLE_REPO_HISTORY_SETTING': (ENABLE_REPO_HISTORY_SETTING, ''), 'ENABLE_REPO_HISTORY_SETTING': (ENABLE_REPO_HISTORY_SETTING, ''),

View File

@@ -6,6 +6,7 @@ from seahub.test_utils import BaseTestCase
class AdminWebSettingsTest(BaseTestCase): class AdminWebSettingsTest(BaseTestCase):
def setUp(self): def setUp(self):
self.url = reverse('api-v2.1-web-settings') self.url = reverse('api-v2.1-web-settings')
self.login_as(self.admin) self.login_as(self.admin)
@@ -27,7 +28,7 @@ class AdminWebSettingsTest(BaseTestCase):
self.assertEqual(200, resp.status_code) self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content) 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): def test_get_with_enable_settings(self):
@@ -37,7 +38,6 @@ class AdminWebSettingsTest(BaseTestCase):
def test_update_web_settings_info(self): def test_update_web_settings_info(self):
data = { data = {
"DISABLE_SYNC_WITH_ANY_FOLDER": False, "DISABLE_SYNC_WITH_ANY_FOLDER": False,
"ENABLE_USER_CREATE_ORG_REPO": True,
"SHARE_LINK_TOKEN_LENGTH": 20, "SHARE_LINK_TOKEN_LENGTH": 20,
"REPO_PASSWORD_MIN_LENGTH": 10, "REPO_PASSWORD_MIN_LENGTH": 10,
"REGISTRATION_SEND_MAIL": False, "REGISTRATION_SEND_MAIL": False,

View File

@@ -1,15 +1,14 @@
import json import json
import pytest 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 mock import patch, MagicMock
from seaserv import seafile_api
from seahub.test_utils import BaseTestCase
pytestmark = pytest.mark.django_db
class RepoPublicTest(BaseTestCase): class RepoPublicTest(BaseTestCase):
def setUp(self): def setUp(self):
from constance import config from constance import config
self.config = config self.config = config
@@ -20,8 +19,6 @@ class RepoPublicTest(BaseTestCase):
self.url = '/api2/shared-repos/%s/' % self.repo_id self.url = '/api2/shared-repos/%s/' % self.repo_id
self.user_repo_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): def tearDown(self):
self.remove_repo(self.repo_id) self.remove_repo(self.repo_id)
# clear cache between every test case to avoid config option cache issue # 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) self.assertEqual(403, resp.status_code)
def test_admin_can_set_pub_repo_when_setting_disalbed(self): 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) self.login_as(self.admin)
@@ -75,9 +69,6 @@ class RepoPublicTest(BaseTestCase):
assert 'success' in json_resp assert 'success' in json_resp
def test_user_can_not_set_pub_repo_when_setting_disalbed(self): 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) self.login_as(self.user)

View File

@@ -1,12 +1,13 @@
import pytest import pytest
pytestmark = pytest.mark.django_db from mock import patch, MagicMock
from seahub.test_utils import BaseTestCase from seahub.test_utils import BaseTestCase
from seaserv import seafile_api from seaserv import seafile_api
from mock import patch, MagicMock
pytestmark = pytest.mark.django_db
class SharedRepoTest(BaseTestCase): class SharedRepoTest(BaseTestCase):
def setUp(self): def setUp(self):
from constance import config from constance import config
self.config = config self.config = config
@@ -15,7 +16,6 @@ class SharedRepoTest(BaseTestCase):
username=self.admin.username, username=self.admin.username,
passwd=None) passwd=None)
self.shared_repo_url = '/api2/shared-repos/%s/?share_type=public&permission=rw' self.shared_repo_url = '/api2/shared-repos/%s/?share_type=public&permission=rw'
self.config.ENABLE_USER_CREATE_ORG_REPO = 1
def tearDown(self): def tearDown(self):
self.remove_repo(self.repo_id) self.remove_repo(self.repo_id)
@@ -48,9 +48,6 @@ class SharedRepoTest(BaseTestCase):
self.assertEqual(403, resp.status_code) self.assertEqual(403, resp.status_code)
def test_admin_can_set_pub_repo_when_setting_disalbed(self): 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) self.login_as(self.admin)
@@ -59,9 +56,6 @@ class SharedRepoTest(BaseTestCase):
assert b"success" in resp.content assert b"success" in resp.content
def test_user_can_not_set_pub_repo_when_setting_disalbed(self): 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) self.login_as(self.user)

View File

@@ -1,12 +1,11 @@
import copy import copy
from mock import patch
from django.test import override_settings
from seahub.test_utils import BaseTestCase from seahub.test_utils import BaseTestCase
from seahub.base.accounts import User, RegistrationForm from seahub.base.accounts import User, RegistrationForm
from seahub.options.models import UserOptions from seahub.options.models import UserOptions
from seahub.role_permissions.settings import ENABLED_ROLE_PERMISSIONS 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) 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_TRUE = True
MULTI_TENANCY_FALSE = False MULTI_TENANCY_FALSE = False
class UserTest(BaseTestCase): class UserTest(BaseTestCase):
def test_freeze_user(self): def test_freeze_user(self):
u = User.objects.get(self.user.username) u = User.objects.get(self.user.username)
@@ -42,8 +43,10 @@ class UserTest(BaseTestCase):
assert len(UserOptions.objects.filter(email=test_email)) == 0 assert len(UserOptions.objects.filter(email=test_email)) == 0
@override_settings(ENABLE_WIKI=True) @override_settings(ENABLE_WIKI=True)
class UserPermissionsTest(BaseTestCase): class UserPermissionsTest(BaseTestCase):
def setUp(self): def setUp(self):
from constance import config from constance import config
self.config = config self.config = config
@@ -76,31 +79,10 @@ class UserPermissionsTest(BaseTestCase):
def test_user_permissions_can_add_public_repo(self): def test_user_permissions_can_add_public_repo(self):
# both have # 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): 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._get_perm_by_roles('can_add_public_repo') is True
assert self.user.permissions.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): def test_can_publish_repo_permission(self):
# enableWIKI = True, and can_publish_repo = True # enableWIKI = True, and can_publish_repo = True
assert self.user.permissions._get_perm_by_roles('can_publish_repo') is 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): def test_clean_email(self):
form = self.form_class({'email': 'some_random_user@1.com', form = self.form_class({'email': 'some_random_user@1.com',
'password1': '123', 'password1': '123',
'password2': '123', 'password2': '123'})
})
assert form.is_valid() is True assert form.is_valid() is True
assert form.clean_email() == 'some_random_user@1.com' assert form.clean_email() == 'some_random_user@1.com'