1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 06:34:40 +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']}
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
saveSetting={this.saveSetting}
displayName='ENABLE_USER_CLEAN_TRASH'

View File

@@ -25,7 +25,7 @@ DIGIT_WEB_SETTINGS = [
'ENABLE_ENCRYPTED_LIBRARY', 'USER_PASSWORD_MIN_LENGTH',
'USER_PASSWORD_STRENGTH_LEVEL', 'SHARE_LINK_PASSWORD_MIN_LENGTH',
'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',
'ENABLE_SHARE_TO_ALL_GROUPS', 'ENABLE_TWO_FACTOR_AUTH',
'ENABLE_BRANDING_CSS', 'ENABLE_TERMS_AND_CONDITIONS',

View File

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

View File

@@ -435,9 +435,6 @@ ENABLE_UPDATE_USER_INFO = True
# Enable or disable repo history setting
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
ENABLE_TERMS_AND_CONDITIONS = False
@@ -907,8 +904,6 @@ CONSTANCE_CONFIG = {
'LOGIN_ATTEMPT_LIMIT': (LOGIN_ATTEMPT_LIMIT, ''),
'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, ''),
'REPO_PASSWORD_MIN_LENGTH': (REPO_PASSWORD_MIN_LENGTH, ''),
'ENABLE_REPO_HISTORY_SETTING': (ENABLE_REPO_HISTORY_SETTING, ''),

View File

@@ -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,

View File

@@ -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)

View File

@@ -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)

View File

@@ -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'