From 32083e58c0c20d386fc422e0bec1e53cf8f2ae97 Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Mon, 5 Feb 2024 10:57:30 -0600 Subject: [PATCH] Fixes: #14840 - Forces API to use django user model instead of proxy model (#14881) * Fixes: #14840 - Forces API to use proxy model * Update tests to use proxy model * Revert "Update tests to use proxy model" This reverts commit 1d784cfe5d689a00ae3c75edc56ce226e62e8fc3. * Revert "Fixes: #14840 - Forces API to use proxy model" This reverts commit df85cc967c2e951cb02c8ea3b9074dc6bd7dc301. * More realistic change to resole issue with netboxusers-list * Revert "More realistic change to resole issue with netboxusers-list" This reverts commit 15df8082aafbebf32c932c4c38b970851492eea8. * Fixes: #14840 - Better fix for netboxusers-list * Swap model for serializer from proxy model --- netbox/utilities/api.py | 7 +++++++ netbox/utilities/utils.py | 2 ++ 2 files changed, 9 insertions(+) diff --git a/netbox/utilities/api.py b/netbox/utilities/api.py index 50bb033e4..b53edf53a 100644 --- a/netbox/utilities/api.py +++ b/netbox/utilities/api.py @@ -27,6 +27,13 @@ def get_serializer_for_model(model, prefix=''): # Serializers for Django's auth models are in the users app if app_name == 'auth': app_name = 'users' + # Account for changes using Proxy model + if app_name == 'users': + if model_name == 'NetBoxUser': + model_name = 'User' + elif model_name == 'NetBoxGroup': + model_name = 'Group' + serializer_name = f'{app_name}.api.serializers.{prefix}{model_name}Serializer' try: return dynamic_import(serializer_name) diff --git a/netbox/utilities/utils.py b/netbox/utilities/utils.py index f3f8c7c50..05597b80c 100644 --- a/netbox/utilities/utils.py +++ b/netbox/utilities/utils.py @@ -52,6 +52,8 @@ def get_viewname(model, action=None, rest_api=False): # Alter the app_label for group and user model_name to point to users app if app_label == 'auth' and model_name in ['group', 'user']: app_label = 'users' + if app_label == 'users' and model._meta.proxy and model_name in ['netboxuser', 'netboxgroup']: + model_name = model._meta.proxy_for_model._meta.model_name viewname = f'{app_label}-api:{model_name}' # Append the action, if any