diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 51b4bfd00d..8ceb16e748 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -108,7 +108,9 @@ class BaseInvenTreeSetting(models.Model): for key, value in settings.items(): validator = cls.get_setting_validator(key) - if cls.validator_is_bool(validator): + if cls.is_protected(key): + value = '***' + elif cls.validator_is_bool(validator): value = InvenTree.helpers.str2bool(value) elif cls.validator_is_int(validator): try: @@ -538,6 +540,19 @@ class BaseInvenTreeSetting(models.Model): return value + @classmethod + def is_protected(cls, key): + """ + Check if the setting value is protected + """ + + key = str(key).strip().upper() + + if key in cls.GLOBAL_SETTINGS: + return cls.GLOBAL_SETTINGS[key].get('protected', False) + else: + return False + def settings_group_options(): """build up group tuple for settings based on gour choices""" diff --git a/InvenTree/common/serializers.py b/InvenTree/common/serializers.py index 4a27e3f30e..60eb609dc1 100644 --- a/InvenTree/common/serializers.py +++ b/InvenTree/common/serializers.py @@ -45,6 +45,18 @@ class SettingsSerializer(InvenTreeModelSerializer): return results + def get_value(self, obj): + """ + Make sure protected values are not returned + """ + result = obj.value + + # never return protected values + if obj.is_protected: + result = '***' + + return result + class GlobalSettingsSerializer(SettingsSerializer): """