mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Update settings API endpoints: (#5684)
* Update settings API endpoints: - Use cache to prevent unnecessary hits to db - Make settings detail endpoints case insensitive - Update API version * Remove is_admin and is_superuser - Contaminated from other commit * revert seralizers.py * Revert breaking change to users/api.py
This commit is contained in:
parent
e8e0b57cea
commit
89faf8e59d
@ -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
|
||||
|
@ -298,7 +298,11 @@ class UserSerializer(InvenTreeModelSerializer):
|
||||
'username',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email'
|
||||
'email',
|
||||
]
|
||||
|
||||
read_only_fields = [
|
||||
'username',
|
||||
]
|
||||
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user