# HG changeset patch # User Johannes Bornhold # Date 2016-06-20 09:52:24 # Node ID 299ebd928d1393aab05ec541931bfc10ace468a1 # Parent b3a11d63dd7d8922421867ff2a890a81198b29eb authn: Don't use setting value to compute the setting type. diff --git a/rhodecode/authentication/base.py b/rhodecode/authentication/base.py --- a/rhodecode/authentication/base.py +++ b/rhodecode/authentication/base.py @@ -22,6 +22,7 @@ Authentication modules """ +import colander import logging import time import traceback @@ -97,11 +98,10 @@ class RhodeCodeAuthPluginBase(object): # Mapping of python to DB settings model types. Plugins may override or # extend this mapping. _settings_type_map = { - str: 'str', - int: 'int', - unicode: 'unicode', - bool: 'bool', - list: 'list', + colander.String: 'unicode', + colander.Integer: 'int', + colander.Boolean: 'bool', + colander.List: 'list', } def __init__(self, plugin_id): @@ -119,16 +119,19 @@ class RhodeCodeAuthPluginBase(object): # PluginSetting or to use the plugin id here. return 'auth_{}_{}'.format(self.name, name) - def _get_setting_type(self, name, value): + def _get_setting_type(self, name): + """ + Return the type of a setting. This type is defined by the SettingsModel + and determines how the setting is stored in DB. Optionally the suffix + `.encrypted` is appended to instruct SettingsModel to store it + encrypted. """ - Get the type as used by the SettingsModel accordingly to type of passed - value. Optionally the suffix `.encrypted` is appended to instruct - SettingsModel to store it encrypted. - """ - type_ = self._settings_type_map.get(type(value), 'unicode') + schema_node = self.get_settings_schema().get(name) + db_type = self._settings_type_map.get( + schema_node.typ.__class__, 'unicode') if name in self._settings_encrypted: - type_ = '{}.encrypted'.format(type_) - return type_ + db_type = '{}.encrypted'.format(db_type) + return db_type def is_enabled(self): """ @@ -177,7 +180,7 @@ class RhodeCodeAuthPluginBase(object): Create or update a setting for this plugin in the persistent storage. """ full_name = self._get_setting_full_name(name) - type_ = self._get_setting_type(name, value) + type_ = self._get_setting_type(name) db_setting = SettingsModel().create_or_update_setting( full_name, value, type_) return db_setting.app_settings_value