diff --git a/InvenTree/InvenTree/api_version.py b/InvenTree/InvenTree/api_version.py index 0901fdc13b..2618e9d0b5 100644 --- a/InvenTree/InvenTree/api_version.py +++ b/InvenTree/InvenTree/api_version.py @@ -2,11 +2,15 @@ # InvenTree API version -INVENTREE_API_VERSION = 137 +INVENTREE_API_VERSION = 138 """ Increment this API version number whenever there is a significant change to the API that any clients need to know about +v138 -> 2023-10-11 : https://github.com/inventree/InvenTree/pull/5679 + - Settings keys are no longer case sensitive + - Include settings units in API serializer + v137 -> 2023-10-04 : https://github.com/inventree/InvenTree/pull/5588 - Adds StockLocationType API endpoints - Adds custom_icon, location_type to StockLocation endpoint @@ -89,7 +93,7 @@ v113 -> 2023-05-13 : https://github.com/inventree/InvenTree/pull/4800 - Adds API endpoints for scrapping a build output v112 -> 2023-05-13: https://github.com/inventree/InvenTree/pull/4741 - - Adds flag use_pack_size to the stock addition API, which allows addings packs + - Adds flag use_pack_size to the stock addition API, which allows adding packs v111 -> 2023-05-02 : https://github.com/inventree/InvenTree/pull/4367 - Adds tags to the Part serializer @@ -169,7 +173,7 @@ v90 -> 2023-01-25 : https://github.com/inventree/InvenTree/pull/4186/files v89 -> 2023-01-25 : https://github.com/inventree/InvenTree/pull/4214 - Adds updated field to SupplierPart API - - Adds API date orddering for supplier part list + - Adds API date ordering for supplier part list v88 -> 2023-01-17: https://github.com/inventree/InvenTree/pull/4225 - Adds 'priority' field to Build model and api endpoints diff --git a/InvenTree/InvenTree/serializers.py b/InvenTree/InvenTree/serializers.py index 8260fb05ef..a209f5c329 100644 --- a/InvenTree/InvenTree/serializers.py +++ b/InvenTree/InvenTree/serializers.py @@ -298,7 +298,11 @@ class UserSerializer(InvenTreeModelSerializer): 'username', 'first_name', 'last_name', - 'email' + 'email', + ] + + read_only_fields = [ + 'username', ] diff --git a/InvenTree/common/api.py b/InvenTree/common/api.py index d77bddc3ca..c13ae456dd 100644 --- a/InvenTree/common/api.py +++ b/InvenTree/common/api.py @@ -229,9 +229,9 @@ class GlobalSettingsDetail(RetrieveUpdateAPI): def get_object(self): """Attempt to find a global setting object with the provided key.""" - key = self.kwargs['key'] + key = str(self.kwargs['key']).upper() - if key not in common.models.InvenTreeSetting.SETTINGS.keys(): + if key.startswith('_') or key not in common.models.InvenTreeSetting.SETTINGS.keys(): raise NotFound() return common.models.InvenTreeSetting.get_setting_object( @@ -296,9 +296,9 @@ class UserSettingsDetail(RetrieveUpdateAPI): def get_object(self): """Attempt to find a user setting object with the provided key.""" - key = self.kwargs['key'] + key = str(self.kwargs['key']).upper() - if key not in common.models.InvenTreeUserSetting.SETTINGS.keys(): + if key.startswith('_') or key not in common.models.InvenTreeUserSetting.SETTINGS.keys(): raise NotFound() return common.models.InvenTreeUserSetting.get_setting_object( diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index a07697130c..a198e29e82 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -205,6 +205,12 @@ class BaseInvenTreeSetting(models.Model): If a particular setting is not present, create it with the default value """ + cache_key = f"BUILD_DEFAULT_VALUES:{str(cls.__name__)}" + + if InvenTree.helpers.str2bool(cache.get(cache_key, False)): + # Already built default values + return + try: existing_keys = cls.objects.filter(**kwargs).values_list('key', flat=True) settings_keys = cls.SETTINGS.keys() @@ -224,6 +230,8 @@ class BaseInvenTreeSetting(models.Model): logger.exception("Failed to build default values for %s (%s)", str(cls), str(type(exc))) pass + cache.set(cache_key, True, timeout=3600) + def _call_settings_function(self, reference: str, args, kwargs): """Call a function associated with a particular setting. @@ -1241,7 +1249,7 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'BARCODE_ENABLE': { 'name': _('Barcode Support'), - 'description': _('Enable barcode scanner support'), + 'description': _('Enable barcode scanner support in the web interface'), 'default': True, 'validator': bool, }, diff --git a/InvenTree/common/serializers.py b/InvenTree/common/serializers.py index 4c1d0b5a54..94109eb831 100644 --- a/InvenTree/common/serializers.py +++ b/InvenTree/common/serializers.py @@ -51,6 +51,8 @@ class SettingsSerializer(InvenTreeModelSerializer): value = SettingsValueField() + units = serializers.CharField(read_only=True) + def get_choices(self, obj): """Returns the choices available for a given item.""" results = [] @@ -81,6 +83,7 @@ class GlobalSettingsSerializer(SettingsSerializer): 'name', 'description', 'type', + 'units', 'choices', 'model_name', 'api_url', @@ -103,6 +106,7 @@ class UserSettingsSerializer(SettingsSerializer): 'description', 'user', 'type', + 'units', 'choices', 'model_name', 'api_url',