# HG changeset patch # User RhodeCode Admin # Date 2023-08-23 11:42:39 # Node ID 02a0c91dd4dfb7059e1ad451579f5980394713ed # Parent 0b0fbfc9be63f0e920a70663d6a0201974500f14 settings: fixes for 5.0.0 release new license key storage diff --git a/rhodecode/model/settings.py b/rhodecode/model/settings.py --- a/rhodecode/model/settings.py +++ b/rhodecode/model/settings.py @@ -68,6 +68,9 @@ class SettingsModel(BaseModel): RepoRhodeCodeSetting if repo else RhodeCodeSetting) super().__init__(sa) + def get_keyname(self, key_name, prefix='rhodecode_'): + return f'{prefix}{key_name}' + def get_ui_by_key(self, key): q = self.UiDbModel.query() q = q.filter(self.UiDbModel.ui_key == key) @@ -169,9 +172,9 @@ class SettingsModel(BaseModel): return q.scalar() def create_or_update_setting( - self, name, val=Optional(''), type_=Optional('unicode')): + self, name, val: Optional | str = Optional(''), type_: Optional | str = Optional('unicode')): """ - Creates or updates RhodeCode setting. If updates is triggered it will + Creates or updates RhodeCode setting. If updates are triggered, it will only update parameters that are explicitly set Optional instance will be skipped @@ -233,7 +236,7 @@ class SettingsModel(BaseModel): raise Exception('Could not get application settings !') settings = { - f'rhodecode_{res.app_settings_name}': res.app_settings_value + self.get_keyname(res.app_settings_name): res.app_settings_value for res in q } return settings @@ -243,7 +246,7 @@ class SettingsModel(BaseModel): # defines if we use GLOBAL, or PER_REPO repo = self._get_repo(self.repo) if self.repo else None - # initially try the requests context, this is the fastest + # initially try the request context; this is the fastest # we only fetch global config, NOT for repo-specific if from_request and not repo: request = get_current_request() @@ -302,8 +305,7 @@ class SettingsModel(BaseModel): repo = self._get_repo(self.repo) if not repo: raise Exception( - 'Repository `{}` cannot be found inside the database'.format( - self.repo)) + f'Repository `{self.repo}` cannot be found inside the database') return repo def _filter_by_repo(self, model, query): @@ -360,12 +362,11 @@ class IssueTrackerSettingsModel(object): self.INHERIT_SETTINGS, value, type_='bool') Session().add(settings) - def _get_keyname(self, key, uid, prefix=''): - return '{}{}{}_{}'.format( - prefix, self.SETTINGS_PREFIX, key, uid) + def _get_keyname(self, key, uid, prefix='rhodecode_'): + return f'{prefix}{self.SETTINGS_PREFIX}{key}_{uid}' def _make_dict_for_settings(self, qs): - prefix_match = self._get_keyname('pat', '', 'rhodecode_') + prefix_match = self._get_keyname('pat', '',) issuetracker_entries = {} # create keys @@ -381,9 +382,9 @@ class IssueTrackerSettingsModel(object): # populate for uid in issuetracker_entries: - url_data = qs.get(self._get_keyname('url', uid, 'rhodecode_')) + url_data = qs.get(self._get_keyname('url', uid)) - pat = qs.get(self._get_keyname('pat', uid, 'rhodecode_')) + pat = qs.get(self._get_keyname('pat', uid)) try: pat_compiled = re.compile(r'%s' % pat) except re.error: @@ -393,11 +394,11 @@ class IssueTrackerSettingsModel(object): 'pat': pat, 'pat_compiled': pat_compiled, 'url': url_cleaner( - qs.get(self._get_keyname('url', uid, 'rhodecode_')) or ''), + qs.get(self._get_keyname('url', uid)) or ''), 'pref': sanitize_html( - qs.get(self._get_keyname('pref', uid, 'rhodecode_')) or ''), + qs.get(self._get_keyname('pref', uid)) or ''), 'desc': qs.get( - self._get_keyname('desc', uid, 'rhodecode_')), + self._get_keyname('desc', uid)), }) return issuetracker_entries @@ -436,7 +437,7 @@ class IssueTrackerSettingsModel(object): entries = all_patterns.get(uid, []) for del_key in entries: - setting_name = self._get_keyname(del_key, uid) + setting_name = self._get_keyname(del_key, uid, prefix='') entry = settings_model.get_setting_by_name(setting_name) if entry: Session().delete(entry) @@ -528,6 +529,9 @@ class VcsSettingsModel(object): self.repo_settings.create_or_update_setting( self.INHERIT_SETTINGS, value, type_='bool') + def get_keyname(self, key_name, prefix='rhodecode_'): + return f'{prefix}{key_name}' + def get_global_svn_branch_patterns(self): return self.global_settings.get_ui_by_section(self.SVN_BRANCH_SECTION) @@ -824,7 +828,7 @@ class VcsSettingsModel(object): return keep def _filter_general_settings(self, settings): - keys = [f'rhodecode_{key}' for key in self.GENERAL_SETTINGS] + keys = [self.get_keyname(key) for key in self.GENERAL_SETTINGS] return { k: settings[k] for k in settings if k in keys} @@ -848,7 +852,7 @@ class VcsSettingsModel(object): for name in self.GENERAL_SETTINGS: setting = settings.get_setting_by_name(name) if setting: - result_key = f'rhodecode_{name}' + result_key = self.get_keyname(name) result[result_key] = setting.app_settings_value return result @@ -882,7 +886,7 @@ class VcsSettingsModel(object): def _create_or_update_general_settings(self, settings, data): for name in self.GENERAL_SETTINGS: - data_key = f'rhodecode_{name}' + data_key = self.get_keyname(name) if data_key not in data: raise ValueError( f'The given data does not contain {data_key} key')