##// END OF EJS Templates
settings: fixes for 5.0.0 release new license key storage
super-admin -
r5144:02a0c91d default
parent child Browse files
Show More
@@ -68,6 +68,9 b' class SettingsModel(BaseModel):'
68 RepoRhodeCodeSetting if repo else RhodeCodeSetting)
68 RepoRhodeCodeSetting if repo else RhodeCodeSetting)
69 super().__init__(sa)
69 super().__init__(sa)
70
70
71 def get_keyname(self, key_name, prefix='rhodecode_'):
72 return f'{prefix}{key_name}'
73
71 def get_ui_by_key(self, key):
74 def get_ui_by_key(self, key):
72 q = self.UiDbModel.query()
75 q = self.UiDbModel.query()
73 q = q.filter(self.UiDbModel.ui_key == key)
76 q = q.filter(self.UiDbModel.ui_key == key)
@@ -169,9 +172,9 b' class SettingsModel(BaseModel):'
169 return q.scalar()
172 return q.scalar()
170
173
171 def create_or_update_setting(
174 def create_or_update_setting(
172 self, name, val=Optional(''), type_=Optional('unicode')):
175 self, name, val: Optional | str = Optional(''), type_: Optional | str = Optional('unicode')):
173 """
176 """
174 Creates or updates RhodeCode setting. If updates is triggered it will
177 Creates or updates RhodeCode setting. If updates are triggered, it will
175 only update parameters that are explicitly set Optional instance will
178 only update parameters that are explicitly set Optional instance will
176 be skipped
179 be skipped
177
180
@@ -233,7 +236,7 b' class SettingsModel(BaseModel):'
233 raise Exception('Could not get application settings !')
236 raise Exception('Could not get application settings !')
234
237
235 settings = {
238 settings = {
236 f'rhodecode_{res.app_settings_name}': res.app_settings_value
239 self.get_keyname(res.app_settings_name): res.app_settings_value
237 for res in q
240 for res in q
238 }
241 }
239 return settings
242 return settings
@@ -243,7 +246,7 b' class SettingsModel(BaseModel):'
243 # defines if we use GLOBAL, or PER_REPO
246 # defines if we use GLOBAL, or PER_REPO
244 repo = self._get_repo(self.repo) if self.repo else None
247 repo = self._get_repo(self.repo) if self.repo else None
245
248
246 # initially try the requests context, this is the fastest
249 # initially try the request context; this is the fastest
247 # we only fetch global config, NOT for repo-specific
250 # we only fetch global config, NOT for repo-specific
248 if from_request and not repo:
251 if from_request and not repo:
249 request = get_current_request()
252 request = get_current_request()
@@ -302,8 +305,7 b' class SettingsModel(BaseModel):'
302 repo = self._get_repo(self.repo)
305 repo = self._get_repo(self.repo)
303 if not repo:
306 if not repo:
304 raise Exception(
307 raise Exception(
305 'Repository `{}` cannot be found inside the database'.format(
308 f'Repository `{self.repo}` cannot be found inside the database')
306 self.repo))
307 return repo
309 return repo
308
310
309 def _filter_by_repo(self, model, query):
311 def _filter_by_repo(self, model, query):
@@ -360,12 +362,11 b' class IssueTrackerSettingsModel(object):'
360 self.INHERIT_SETTINGS, value, type_='bool')
362 self.INHERIT_SETTINGS, value, type_='bool')
361 Session().add(settings)
363 Session().add(settings)
362
364
363 def _get_keyname(self, key, uid, prefix=''):
365 def _get_keyname(self, key, uid, prefix='rhodecode_'):
364 return '{}{}{}_{}'.format(
366 return f'{prefix}{self.SETTINGS_PREFIX}{key}_{uid}'
365 prefix, self.SETTINGS_PREFIX, key, uid)
366
367
367 def _make_dict_for_settings(self, qs):
368 def _make_dict_for_settings(self, qs):
368 prefix_match = self._get_keyname('pat', '', 'rhodecode_')
369 prefix_match = self._get_keyname('pat', '',)
369
370
370 issuetracker_entries = {}
371 issuetracker_entries = {}
371 # create keys
372 # create keys
@@ -381,9 +382,9 b' class IssueTrackerSettingsModel(object):'
381
382
382 # populate
383 # populate
383 for uid in issuetracker_entries:
384 for uid in issuetracker_entries:
384 url_data = qs.get(self._get_keyname('url', uid, 'rhodecode_'))
385 url_data = qs.get(self._get_keyname('url', uid))
385
386
386 pat = qs.get(self._get_keyname('pat', uid, 'rhodecode_'))
387 pat = qs.get(self._get_keyname('pat', uid))
387 try:
388 try:
388 pat_compiled = re.compile(r'%s' % pat)
389 pat_compiled = re.compile(r'%s' % pat)
389 except re.error:
390 except re.error:
@@ -393,11 +394,11 b' class IssueTrackerSettingsModel(object):'
393 'pat': pat,
394 'pat': pat,
394 'pat_compiled': pat_compiled,
395 'pat_compiled': pat_compiled,
395 'url': url_cleaner(
396 'url': url_cleaner(
396 qs.get(self._get_keyname('url', uid, 'rhodecode_')) or ''),
397 qs.get(self._get_keyname('url', uid)) or ''),
397 'pref': sanitize_html(
398 'pref': sanitize_html(
398 qs.get(self._get_keyname('pref', uid, 'rhodecode_')) or ''),
399 qs.get(self._get_keyname('pref', uid)) or ''),
399 'desc': qs.get(
400 'desc': qs.get(
400 self._get_keyname('desc', uid, 'rhodecode_')),
401 self._get_keyname('desc', uid)),
401 })
402 })
402
403
403 return issuetracker_entries
404 return issuetracker_entries
@@ -436,7 +437,7 b' class IssueTrackerSettingsModel(object):'
436 entries = all_patterns.get(uid, [])
437 entries = all_patterns.get(uid, [])
437
438
438 for del_key in entries:
439 for del_key in entries:
439 setting_name = self._get_keyname(del_key, uid)
440 setting_name = self._get_keyname(del_key, uid, prefix='')
440 entry = settings_model.get_setting_by_name(setting_name)
441 entry = settings_model.get_setting_by_name(setting_name)
441 if entry:
442 if entry:
442 Session().delete(entry)
443 Session().delete(entry)
@@ -528,6 +529,9 b' class VcsSettingsModel(object):'
528 self.repo_settings.create_or_update_setting(
529 self.repo_settings.create_or_update_setting(
529 self.INHERIT_SETTINGS, value, type_='bool')
530 self.INHERIT_SETTINGS, value, type_='bool')
530
531
532 def get_keyname(self, key_name, prefix='rhodecode_'):
533 return f'{prefix}{key_name}'
534
531 def get_global_svn_branch_patterns(self):
535 def get_global_svn_branch_patterns(self):
532 return self.global_settings.get_ui_by_section(self.SVN_BRANCH_SECTION)
536 return self.global_settings.get_ui_by_section(self.SVN_BRANCH_SECTION)
533
537
@@ -824,7 +828,7 b' class VcsSettingsModel(object):'
824 return keep
828 return keep
825
829
826 def _filter_general_settings(self, settings):
830 def _filter_general_settings(self, settings):
827 keys = [f'rhodecode_{key}' for key in self.GENERAL_SETTINGS]
831 keys = [self.get_keyname(key) for key in self.GENERAL_SETTINGS]
828 return {
832 return {
829 k: settings[k]
833 k: settings[k]
830 for k in settings if k in keys}
834 for k in settings if k in keys}
@@ -848,7 +852,7 b' class VcsSettingsModel(object):'
848 for name in self.GENERAL_SETTINGS:
852 for name in self.GENERAL_SETTINGS:
849 setting = settings.get_setting_by_name(name)
853 setting = settings.get_setting_by_name(name)
850 if setting:
854 if setting:
851 result_key = f'rhodecode_{name}'
855 result_key = self.get_keyname(name)
852 result[result_key] = setting.app_settings_value
856 result[result_key] = setting.app_settings_value
853
857
854 return result
858 return result
@@ -882,7 +886,7 b' class VcsSettingsModel(object):'
882
886
883 def _create_or_update_general_settings(self, settings, data):
887 def _create_or_update_general_settings(self, settings, data):
884 for name in self.GENERAL_SETTINGS:
888 for name in self.GENERAL_SETTINGS:
885 data_key = f'rhodecode_{name}'
889 data_key = self.get_keyname(name)
886 if data_key not in data:
890 if data_key not in data:
887 raise ValueError(
891 raise ValueError(
888 f'The given data does not contain {data_key} key')
892 f'The given data does not contain {data_key} key')
General Comments 0
You need to be logged in to leave comments. Login now