##// 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 68 RepoRhodeCodeSetting if repo else RhodeCodeSetting)
69 69 super().__init__(sa)
70 70
71 def get_keyname(self, key_name, prefix='rhodecode_'):
72 return f'{prefix}{key_name}'
73
71 74 def get_ui_by_key(self, key):
72 75 q = self.UiDbModel.query()
73 76 q = q.filter(self.UiDbModel.ui_key == key)
@@ -169,9 +172,9 b' class SettingsModel(BaseModel):'
169 172 return q.scalar()
170 173
171 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 178 only update parameters that are explicitly set Optional instance will
176 179 be skipped
177 180
@@ -233,7 +236,7 b' class SettingsModel(BaseModel):'
233 236 raise Exception('Could not get application settings !')
234 237
235 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 240 for res in q
238 241 }
239 242 return settings
@@ -243,7 +246,7 b' class SettingsModel(BaseModel):'
243 246 # defines if we use GLOBAL, or PER_REPO
244 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 250 # we only fetch global config, NOT for repo-specific
248 251 if from_request and not repo:
249 252 request = get_current_request()
@@ -302,8 +305,7 b' class SettingsModel(BaseModel):'
302 305 repo = self._get_repo(self.repo)
303 306 if not repo:
304 307 raise Exception(
305 'Repository `{}` cannot be found inside the database'.format(
306 self.repo))
308 f'Repository `{self.repo}` cannot be found inside the database')
307 309 return repo
308 310
309 311 def _filter_by_repo(self, model, query):
@@ -360,12 +362,11 b' class IssueTrackerSettingsModel(object):'
360 362 self.INHERIT_SETTINGS, value, type_='bool')
361 363 Session().add(settings)
362 364
363 def _get_keyname(self, key, uid, prefix=''):
364 return '{}{}{}_{}'.format(
365 prefix, self.SETTINGS_PREFIX, key, uid)
365 def _get_keyname(self, key, uid, prefix='rhodecode_'):
366 return f'{prefix}{self.SETTINGS_PREFIX}{key}_{uid}'
366 367
367 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 371 issuetracker_entries = {}
371 372 # create keys
@@ -381,9 +382,9 b' class IssueTrackerSettingsModel(object):'
381 382
382 383 # populate
383 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 388 try:
388 389 pat_compiled = re.compile(r'%s' % pat)
389 390 except re.error:
@@ -393,11 +394,11 b' class IssueTrackerSettingsModel(object):'
393 394 'pat': pat,
394 395 'pat_compiled': pat_compiled,
395 396 'url': url_cleaner(
396 qs.get(self._get_keyname('url', uid, 'rhodecode_')) or ''),
397 qs.get(self._get_keyname('url', uid)) or ''),
397 398 'pref': sanitize_html(
398 qs.get(self._get_keyname('pref', uid, 'rhodecode_')) or ''),
399 qs.get(self._get_keyname('pref', uid)) or ''),
399 400 'desc': qs.get(
400 self._get_keyname('desc', uid, 'rhodecode_')),
401 self._get_keyname('desc', uid)),
401 402 })
402 403
403 404 return issuetracker_entries
@@ -436,7 +437,7 b' class IssueTrackerSettingsModel(object):'
436 437 entries = all_patterns.get(uid, [])
437 438
438 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 441 entry = settings_model.get_setting_by_name(setting_name)
441 442 if entry:
442 443 Session().delete(entry)
@@ -528,6 +529,9 b' class VcsSettingsModel(object):'
528 529 self.repo_settings.create_or_update_setting(
529 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 535 def get_global_svn_branch_patterns(self):
532 536 return self.global_settings.get_ui_by_section(self.SVN_BRANCH_SECTION)
533 537
@@ -824,7 +828,7 b' class VcsSettingsModel(object):'
824 828 return keep
825 829
826 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 832 return {
829 833 k: settings[k]
830 834 for k in settings if k in keys}
@@ -848,7 +852,7 b' class VcsSettingsModel(object):'
848 852 for name in self.GENERAL_SETTINGS:
849 853 setting = settings.get_setting_by_name(name)
850 854 if setting:
851 result_key = f'rhodecode_{name}'
855 result_key = self.get_keyname(name)
852 856 result[result_key] = setting.app_settings_value
853 857
854 858 return result
@@ -882,7 +886,7 b' class VcsSettingsModel(object):'
882 886
883 887 def _create_or_update_general_settings(self, settings, data):
884 888 for name in self.GENERAL_SETTINGS:
885 data_key = f'rhodecode_{name}'
889 data_key = self.get_keyname(name)
886 890 if data_key not in data:
887 891 raise ValueError(
888 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