Updated with a latest changes.

This commit is contained in:
Serhii Ilin 2024-03-11 20:12:31 +02:00
commit 5f36eb1b22
28 changed files with 63 additions and 172 deletions

View file

@ -261,8 +261,8 @@ auth_ret_code_detection = false
; codes don't break the transactions while 4XX codes do
lock_ret_code = 423
; allows to change the repository location in settings page
allow_repo_location_change = true
; Filesystem location were repositories should be stored
repo_store.path = /var/opt/rhodecode_repo_store
; allows to setup custom hooks in settings page
allow_custom_hooks_settings = true

View file

@ -212,8 +212,8 @@ auth_ret_code_detection = false
; codes don't break the transactions while 4XX codes do
lock_ret_code = 423
; allows to change the repository location in settings page
allow_repo_location_change = true
; Filesystem location were repositories should be stored
repo_store.path = /var/opt/rhodecode_repo_store
; allows to setup custom hooks in settings page
allow_custom_hooks_settings = true

View file

@ -25,7 +25,7 @@ from rhodecode.api import (
from rhodecode.api.utils import (
Optional, OAttr, has_superadmin_permission, get_user_or_error)
from rhodecode.lib.utils import repo2db_mapper
from rhodecode.lib.utils import repo2db_mapper, get_rhodecode_repo_store_path
from rhodecode.lib import system_info
from rhodecode.lib import user_sessions
from rhodecode.lib import exc_tracking
@ -33,7 +33,6 @@ from rhodecode.lib.ext_json import json
from rhodecode.lib.utils2 import safe_int
from rhodecode.model.db import UserIpMap
from rhodecode.model.scm import ScmModel
from rhodecode.model.settings import VcsSettingsModel
from rhodecode.apps.file_store import utils
from rhodecode.apps.file_store.exceptions import FileNotAllowedException, \
FileOverSizeException
@ -103,7 +102,7 @@ def get_repo_store(request, apiuser):
if not has_superadmin_permission(apiuser):
raise JSONRPCForbidden()
path = VcsSettingsModel().get_repos_location()
path = get_rhodecode_repo_store_path()
return {"path": path}

View file

@ -38,7 +38,7 @@ from rhodecode.lib.auth import (
LoginRequired, HasPermissionAllDecorator, CSRFRequired)
from rhodecode.lib.celerylib import tasks, run_task
from rhodecode.lib.str_utils import safe_str
from rhodecode.lib.utils import repo2db_mapper
from rhodecode.lib.utils import repo2db_mapper, get_rhodecode_repo_store_path
from rhodecode.lib.utils2 import str2bool, AttributeDict
from rhodecode.lib.index import searcher_from_config
@ -167,9 +167,6 @@ class AdminSettingsView(BaseAppView):
return Response(html)
try:
if c.visual.allow_repo_location_change:
model.update_global_path_setting(form_result['paths_root_path'])
model.update_global_ssl_setting(form_result['web_push_ssl'])
model.update_global_hook_settings(form_result)
@ -217,7 +214,7 @@ class AdminSettingsView(BaseAppView):
def settings_mapping(self):
c = self.load_default_context()
c.active = 'mapping'
c.storage_path = VcsSettingsModel().get_repos_location()
c.storage_path = get_rhodecode_repo_store_path()
data = render('rhodecode:templates/admin/settings/settings.mako',
self._get_template_context(c), self.request)
html = formencode.htmlfill.render(

View file

@ -22,7 +22,7 @@ import os
from pyramid.renderers import render
from rhodecode.events import trigger
from rhodecode.lib.utils import get_rhodecode_realm, get_rhodecode_base_path
from rhodecode.lib.utils import get_rhodecode_realm, get_rhodecode_repo_store_path
from rhodecode.lib.utils2 import str2bool
from rhodecode.model.db import RepoGroup
@ -38,7 +38,7 @@ def write_mod_dav_svn_config(settings):
file_path = settings[config_keys.config_file_path]
config = _render_mod_dav_svn_config(
use_ssl=use_ssl,
parent_path_root=get_rhodecode_base_path(),
parent_path_root=get_rhodecode_repo_store_path(),
list_parent_path=settings[config_keys.list_parent_path],
location_root=settings[config_keys.location_root],
repo_groups=RepoGroup.get_all_repo_groups(),

View file

@ -118,6 +118,8 @@ def sanitize_settings_and_apply_defaults(global_config, settings):
settings_maker.make_setting('vcs.methods.cache', True, parser='bool')
# repo_store path
settings_maker.make_setting('repo_store.path', '/var/opt/rhodecode_repo_store')
# Support legacy values of vcs.scm_app_implementation. Legacy
# configurations may use 'rhodecode.lib.middleware.utils.scm_app_http', or
# disabled since 4.13 'vcsserver.scm_app' which is now mapped to 'http'.

View file

@ -80,7 +80,6 @@ def load_pyramid_environment(global_config, settings):
rhodecode.PYRAMID_SETTINGS = settings_merged
rhodecode.CONFIG = settings_merged
rhodecode.CONFIG['default_user_id'] = utils.get_default_user_id()
rhodecode.CONFIG['default_base_path'] = utils.get_default_base_path()
if vcs_server_enabled:
connect_vcs(vcs_server_uri, utils.get_vcs_server_protocol(settings))

View file

@ -102,15 +102,3 @@ def get_default_user_id():
user_id = result.first()[0]
return user_id
def get_default_base_path():
from sqlalchemy import text
from rhodecode.model import meta
engine = meta.get_engine()
with meta.SA_Session(engine) as session:
result = session.execute(text("SELECT ui_value from rhodecode_ui where ui_key = '/'"))
base_path = result.first()[0]
return base_path

View file

@ -347,8 +347,6 @@ def attach_context_attributes(context, request, user_id=None, is_api=None):
context.ssh_key_generator_enabled = str2bool(
config.get('ssh.enable_ui_key_generator', 'true'))
context.visual.allow_repo_location_change = str2bool(
config.get('allow_repo_location_change', True))
context.visual.allow_custom_hooks_settings = str2bool(
config.get('allow_custom_hooks_settings', True))
context.debug_style = str2bool(config.get('debug_style', False))

View file

@ -156,17 +156,10 @@ class SimpleVCS(object):
@property
def base_path(self):
settings_path = self.repo_vcs_config.get(*VcsSettingsModel.PATH_SETTING)
settings_path = self.config.get('repo_store.path')
if not settings_path:
settings_path = self.global_vcs_config.get(*VcsSettingsModel.PATH_SETTING)
if not settings_path:
# try, maybe we passed in explicitly as config option
settings_path = self.config.get('base_path')
if not settings_path:
raise ValueError('FATAL: base_path is empty')
raise ValueError('FATAL: repo_store.path is empty')
return settings_path
def set_repo_names(self, environ):

View file

@ -331,8 +331,8 @@ def cpu():
@register_sysinfo
def storage():
from rhodecode.lib.helpers import format_byte_size_binary
from rhodecode.model.settings import VcsSettingsModel
path = VcsSettingsModel().get_repos_location()
from rhodecode.lib.utils import get_rhodecode_repo_store_path
path = get_rhodecode_repo_store_path()
value = dict(percent=0, used=0, total=0, path=path, text='')
state = STATE_OK_DEFAULT
@ -364,8 +364,8 @@ def storage():
@register_sysinfo
def storage_inodes():
from rhodecode.model.settings import VcsSettingsModel
path = VcsSettingsModel().get_repos_location()
from rhodecode.lib.utils import get_rhodecode_repo_store_path
path = get_rhodecode_repo_store_path()
value = dict(percent=0.0, free=0, used=0, total=0, path=path, text='')
state = STATE_OK_DEFAULT
@ -442,11 +442,10 @@ def storage_archives():
@register_sysinfo
def storage_gist():
from rhodecode.model.gist import GIST_STORE_LOC
from rhodecode.model.settings import VcsSettingsModel
from rhodecode.lib.utils import safe_str
from rhodecode.lib.utils import safe_str, get_rhodecode_repo_store_path
from rhodecode.lib.helpers import format_byte_size_binary
path = safe_str(os.path.join(
VcsSettingsModel().get_repos_location(), GIST_STORE_LOC))
get_rhodecode_repo_store_path(), GIST_STORE_LOC))
# gist storage
value = dict(percent=0, used=0, total=0, items=0, path=path, text='')

View file

@ -472,14 +472,14 @@ def get_rhodecode_realm():
return safe_str(realm.app_settings_value)
def get_rhodecode_base_path():
def get_rhodecode_repo_store_path():
"""
Returns the base path. The base path is the filesystem path which points
to the repository store.
"""
import rhodecode
return rhodecode.CONFIG['default_base_path']
return rhodecode.CONFIG['repo_store.path']
def map_groups(path):

View file

@ -21,6 +21,7 @@ import logging
import rhodecode
from rhodecode.model import meta, db
from rhodecode.lib.utils import get_rhodecode_repo_store_path
from rhodecode.lib.utils2 import obfuscate_url_pw, get_encryption_key
log = logging.getLogger(__name__)
@ -138,3 +139,11 @@ class BaseModel(object):
Returns all instances of what is defined in `cls` class variable
"""
return cls.cls.getAll()
@property
def repos_path(self):
"""
Gets the repositories root path from *ini file
"""
return get_rhodecode_repo_store_path()

View file

@ -1942,8 +1942,8 @@ class Repository(Base, BaseModel):
:param cls:
"""
from rhodecode.lib.utils import get_rhodecode_base_path
return get_rhodecode_base_path()
from rhodecode.lib.utils import get_rhodecode_repo_store_path
return get_rhodecode_repo_store_path()
@classmethod
def get_all_repos(cls, user_id=Optional(None), group_id=Optional(None),
@ -2009,16 +2009,13 @@ class Repository(Base, BaseModel):
def groups_and_repo(self):
return self.groups_with_parents, self
@LazyProperty
@property
def repo_path(self):
"""
Returns base full path for that repository means where it actually
exists on a filesystem
"""
q = Session().query(RhodeCodeUi).filter(
RhodeCodeUi.ui_key == self.NAME_SEP)
q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
return q.one().ui_value
return self.base_path()
@property
def repo_full_path(self):

View file

@ -430,10 +430,6 @@ def ApplicationUiSettingsForm(localizer):
class _ApplicationUiSettingsForm(_BaseVcsSettingsForm):
web_push_ssl = v.StringBoolean(if_missing=False)
paths_root_path = All(
v.ValidPath(localizer),
v.UnicodeString(strip=True, min=1, not_empty=True)
)
largefiles_usercache = All(
v.ValidPath(localizer),
v.UnicodeString(strip=True, min=2, not_empty=True))

View file

@ -83,14 +83,6 @@ class RepoModel(BaseModel):
return repo_to_perm
@LazyProperty
def repos_path(self):
"""
Gets the repositories root path from database
"""
settings_model = VcsSettingsModel(sa=self.sa)
return settings_model.get_repos_location()
def get(self, repo_id):
repo = self.sa.query(Repository) \
.filter(Repository.repo_id == repo_id)

View file

@ -62,15 +62,6 @@ class RepoGroupModel(BaseModel):
def get_repo_group(self, repo_group):
return self._get_repo_group(repo_group)
@LazyProperty
def repos_path(self):
"""
Gets the repositories root path from database
"""
settings_model = VcsSettingsModel(sa=self.sa)
return settings_model.get_repos_location()
def get_by_group_name(self, repo_group_name, cache=None):
repo = self.sa.query(RepoGroup) \
.filter(RepoGroup.group_name == repo_group_name)

View file

@ -189,15 +189,6 @@ class ScmModel(BaseModel):
Generic Scm Model
"""
@LazyProperty
def repos_path(self):
"""
Gets the repositories root path from database
"""
settings_model = VcsSettingsModel(sa=self.sa)
return settings_model.get_repos_location()
def repo_scan(self, repos_path=None):
"""
Listing of repositories in given path. This path should not be a

View file

@ -717,10 +717,6 @@ class VcsSettingsModel(object):
self._create_or_update_ui(
self.global_settings, *self.SSL_SETTING, value=value)
def update_global_path_setting(self, value):
self._create_or_update_ui(
self.global_settings, *self.PATH_SETTING, value=value)
@assert_repo_settings
def delete_repo_svn_pattern(self, id_):
ui = self.repo_settings.UiDbModel.get(id_)
@ -795,9 +791,6 @@ class VcsSettingsModel(object):
else:
return self.get_repo_general_settings()
def get_repos_location(self):
return self.global_settings.get_ui_by_key('/').ui_value
def _filter_ui_settings(self, settings):
filtered_settings = [
s for s in settings if self._should_keep_setting(s)]

View file

@ -116,8 +116,9 @@ def scan_repositories_if_enabled(event):
import_on_startup = settings['startup.import_repos']
if vcs_server_enabled and import_on_startup:
from rhodecode.model.scm import ScmModel
from rhodecode.lib.utils import repo2db_mapper, get_rhodecode_base_path
repositories = ScmModel().repo_scan(get_rhodecode_base_path())
from rhodecode.lib.utils import repo2db_mapper
scm = ScmModel()
repositories = scm.repo_scan(scm.repos_path)
repo2db_mapper(repositories, remove_obsolete=False)

View file

@ -6,8 +6,7 @@ ${h.secure_form(h.route_path('admin_settings_vcs_update'), request=request)}
suffix='',
svn_tag_patterns=c.svn_tag_patterns,
svn_branch_patterns=c.svn_branch_patterns,
display_globals=True,
allow_repo_location_change=c.visual.allow_repo_location_change
display_globals=True
)}
<div class="buttons">
${h.submit('save',_('Save settings'),class_="btn")}

View file

@ -3,7 +3,7 @@
## <%namespace name="vcss" file="/base/vcssettings.mako"/>
## ${vcss.vcs_settings_fields()}
<%def name="vcs_settings_fields(suffix='', svn_branch_patterns=None, svn_tag_patterns=None, repo_type=None, display_globals=False, allow_repo_location_change=False, **kwargs)">
<%def name="vcs_settings_fields(suffix='', svn_branch_patterns=None, svn_tag_patterns=None, repo_type=None, display_globals=False, **kwargs)">
% if display_globals:
<div class="panel panel-default">
<div class="panel-heading" id="general">
@ -23,34 +23,6 @@
</div>
% endif
% if display_globals:
<div class="panel panel-default">
<div class="panel-heading" id="vcs-storage-options">
<h3 class="panel-title">${_('Main Storage Location')}<a class="permalink" href="#vcs-storage-options"> ¶</a></h3>
</div>
<div class="panel-body">
<div class="field">
<div class="inputx locked_input">
%if allow_repo_location_change:
${h.text('paths_root_path',size=59,readonly="readonly", class_="disabled")}
<span id="path_unlock" class="tooltip"
title="${h.tooltip(_('Click to unlock. You must restart RhodeCode in order to make this setting take effect.'))}">
<div class="btn btn-default lock_input_button"><i id="path_unlock_icon" class="icon-lock"></i></div>
</span>
%else:
${_('Repository location change is disabled. You can enable this by changing the `allow_repo_location_change` inside .ini file.')}
## form still requires this but we cannot internally change it anyway
${h.hidden('paths_root_path',size=30,readonly="readonly", class_="disabled")}
%endif
</div>
</div>
<div class="label">
<span class="help-block">${_('Filesystem location where repositories should be stored. After changing this value a restart and rescan of the repository folder are required.')}</span>
</div>
</div>
</div>
% endif
% if display_globals or repo_type in ['git', 'hg']:
<div class="panel panel-default">
<div class="panel-heading" id="vcs-hooks-options">

View file

@ -27,6 +27,7 @@ import urllib.parse
import pytest
import rhodecode
from rhodecode.model.db import User
from rhodecode.lib import auth
from rhodecode.lib import helpers as h
@ -54,7 +55,6 @@ __all__ = [
# SOME GLOBALS FOR TESTS
TEST_DIR = tempfile.gettempdir()
TESTS_TMP_PATH = jn(TEST_DIR, 'rc_test_{}'.format(next(tempfile._RandomNameSequence())))
TEST_USER_ADMIN_LOGIN = 'test_admin'
TEST_USER_ADMIN_PASS = 'test12'
TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com'
@ -81,6 +81,8 @@ GIT_FORK = 'vcs_test_git_fork'
SCM_TESTS = ['hg', 'git']
uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple())))
TESTS_TMP_PATH = tempfile.mkdtemp(prefix='rc_test_', dir=TEST_DIR)
TEST_GIT_REPO = jn(TESTS_TMP_PATH, GIT_REPO)
TEST_GIT_REPO_CLONE = jn(TESTS_TMP_PATH, f'vcsgitclone{uniq_suffix}')
TEST_GIT_REPO_PULL = jn(TESTS_TMP_PATH, f'vcsgitpull{uniq_suffix}')
@ -111,7 +113,7 @@ def get_new_dir(title):
hex_str = sha1_safe(f'{os.getpid()} {time.time()}')
name_parts.append(hex_str)
name = '-'.join(name_parts)
path = os.path.join(TEST_DIR, name)
path = jn(TEST_DIR, name)
return get_normalized_path(path)

View file

@ -21,6 +21,7 @@ import pytest
from rhodecode.lib.config_utils import get_app_config
from rhodecode.tests.fixture import TestINI
from rhodecode.tests import TESTS_TMP_PATH
from rhodecode.tests.server_utils import RcVCSServer
@ -111,6 +112,7 @@ def ini_config(request, tmpdir_factory, rcserver_port, vcsserver_port):
'vcs.svn.proxy.enabled': 'true',
'vcs.hooks.protocol': 'http',
'vcs.hooks.host': '*',
'repo_store.path': TESTS_TMP_PATH,
'app.service_api.token': 'service_secret_token',
}},

View file

@ -23,16 +23,16 @@ import pytest
from unittest.mock import patch, Mock, MagicMock
from rhodecode.lib.middleware.simplesvn import SimpleSvn, SimpleSvnApp
from rhodecode.lib.utils import get_rhodecode_base_path
from rhodecode.lib.utils import get_rhodecode_repo_store_path
from rhodecode.tests import SVN_REPO, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS
class TestSimpleSvn(object):
@pytest.fixture(autouse=True)
def simple_svn(self, baseapp, request_stub):
base_path = get_rhodecode_base_path()
base_path = get_rhodecode_repo_store_path()
self.app = SimpleSvn(
config={'auth_ret_code': '', 'base_path': base_path},
config={'auth_ret_code': '', 'repo_store.path': base_path},
registry=request_stub.registry)
def test_get_config(self):
@ -126,7 +126,7 @@ class TestSimpleSvnApp(object):
def setup_method(self, method):
# note(marcink): this is hostname from docker compose used for testing...
self.host = 'http://svn:8090'
base_path = get_rhodecode_base_path()
base_path = get_rhodecode_repo_store_path()
self.app = SimpleSvnApp(
config={'subversion_http_server_url': self.host,
'base_path': base_path})

View file

@ -589,17 +589,6 @@ class TestUpdateGlobalSslSetting(object):
model.global_settings, 'web', 'push_ssl', value='False')
class TestUpdateGlobalPathSetting(object):
def test_updates_global_path_settings(self):
model = VcsSettingsModel()
with mock.patch.object(model, '_create_or_update_ui') as create_mock:
model.update_global_path_setting('False')
Session().commit()
create_mock.assert_called_once_with(
model.global_settings, 'paths', '/', value='False')
class TestCreateOrUpdateGlobalHgSettings(object):
FORM_DATA = {
'extensions_largefiles': False,
@ -1004,21 +993,6 @@ class TestGetSvnPatterns(object):
settings_mock.assert_called_once_with(*args)
class TestGetReposLocation(object):
def test_returns_repos_location(self, repo_stub):
model = VcsSettingsModel()
result_mock = mock.Mock()
result_mock.ui_value = '/tmp'
with mock.patch.object(model, 'global_settings') as settings_mock:
settings_mock.get_ui_by_key.return_value = result_mock
result = model.get_repos_location()
settings_mock.get_ui_by_key.assert_called_once_with('/')
assert result == '/tmp'
class TestCreateOrUpdateRepoSettings(object):
FORM_DATA = {
'inherit_global_settings': False,

View file

@ -121,20 +121,20 @@ class TestRepoModel(object):
def test_create_filesystem_repo_installs_hooks(self, tmpdir, backend):
repo = backend.create_repo()
repo_name = repo.repo_name
model = RepoModel()
repo_location = tempfile.mkdtemp()
model.repos_path = repo_location
repo = model._create_filesystem_repo(
repo_name, backend.alias, repo_group='', clone_uri=None)
with mock.patch('rhodecode.model.repo.RepoModel.repos_path',
new_callable=mock.PropertyMock) as mocked_models_property:
mocked_models_property.return_value = tempfile.mkdtemp()
repo = RepoModel()._create_filesystem_repo(
repo_name, backend.alias, repo_group='', clone_uri=None)
hooks = {
'svn': ('pre-commit', 'post-commit'),
'git': ('pre-receive', 'post-receive'),
}
for hook in hooks[backend.alias]:
with open(os.path.join(repo.path, 'hooks', hook)) as f:
data = f.read()
assert 'RC_HOOK_VER' in data
hooks = {
'svn': ('pre-commit', 'post-commit'),
'git': ('pre-receive', 'post-receive'),
}
for hook in hooks[backend.alias]:
with open(os.path.join(repo.path, 'hooks', hook)) as f:
data = f.read()
assert 'RC_HOOK_VER' in data
@pytest.mark.parametrize("use_global_config, repo_name_passed", [
(True, False),

View file

@ -206,9 +206,6 @@ auth_ret_code_detection = false
; codes don't break the transactions while 4XX codes do
lock_ret_code = 423
; allows to change the repository location in settings page
allow_repo_location_change = true
; allows to setup custom hooks in settings page
allow_custom_hooks_settings = true