User settings are now accessed via unique KEY

This commit is contained in:
Oliver Walters 2022-05-08 10:58:31 +10:00
parent dd017f36c7
commit 5560706c33
2 changed files with 16 additions and 2 deletions

View File

@ -226,9 +226,22 @@ class UserSettingsDetail(generics.RetrieveUpdateAPIView):
- User can only view / edit settings their own settings objects
"""
lookup_field = 'key'
queryset = common.models.InvenTreeUserSetting.objects.all()
serializer_class = common.serializers.UserSettingsSerializer
def get_object(self):
"""
Attempt to find a user setting object with the provided key.
"""
key = self.kwargs['key']
if key not in common.models.InvenTreeUserSetting.SETTINGS.keys():
raise NotFound()
return common.models.InvenTreeUserSetting.get_setting_object(key, user=self.request.user)
permission_classes = [
UserSettingsPermissions,
]
@ -391,7 +404,7 @@ settings_api_urls = [
# User settings
re_path(r'^user/', include([
# User Settings Detail
re_path(r'^(?P<pk>\d+)/', UserSettingsDetail.as_view(), name='api-user-setting-detail'),
re_path(r'^(?P<key>\w+)/', UserSettingsDetail.as_view(), name='api-user-setting-detail'),
# User Settings List
re_path(r'^.*$', UserSettingsList.as_view(), name='api-user-setting-list'),

View File

@ -80,7 +80,7 @@ $('table').find('.boolean-setting').change(function() {
if (plugin) {
url = `/api/plugin/settings/${pk}/`;
} else if (user) {
url = `/api/settings/user/${pk}/`;
url = `/api/settings/user/${setting}/`;
} else if (notification) {
url = `/api/settings/notification/${pk}/`;
}
@ -125,6 +125,7 @@ $('table').find('.btn-edit-setting').click(function() {
pk = setting;
} else {
title = '{% trans "Edit User Setting" %}';
pk = setting;
}
editSetting(pk, {