From c1b57af7718f08bcef4108cb365d35a4fbd1bcbc Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 22 Sep 2020 10:06:13 -0400 Subject: [PATCH] Monkey-patch DRF to treat bulk_destroy as a built-in operation --- netbox/netbox/api.py | 11 +++++++++++ netbox/netbox/settings.py | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/netbox/netbox/api.py b/netbox/netbox/api.py index 28403f181..9d65ba8b8 100644 --- a/netbox/netbox/api.py +++ b/netbox/netbox/api.py @@ -4,11 +4,22 @@ from rest_framework import authentication, exceptions from rest_framework.pagination import LimitOffsetPagination from rest_framework.permissions import DjangoObjectPermissions, SAFE_METHODS from rest_framework.renderers import BrowsableAPIRenderer +from rest_framework.schemas import coreapi from rest_framework.utils import formatting from users.models import Token +def is_custom_action(action): + return action not in { + 'retrieve', 'list', 'create', 'update', 'partial_update', 'destroy', 'bulk_destroy' + } + + +# Monkey-patch DRF to treat bulk_destroy() as a non-custom action (see #3436) +coreapi.is_custom_action = is_custom_action + + # # Renderers # diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index bd247070f..7e1966edb 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -472,6 +472,13 @@ REST_FRAMEWORK = { 'DEFAULT_VERSION': REST_FRAMEWORK_VERSION, 'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning', 'PAGE_SIZE': PAGINATE_COUNT, + 'SCHEMA_COERCE_METHOD_NAMES': { + # Default mappings + 'retrieve': 'read', + 'destroy': 'delete', + # Custom operations + 'bulk_destroy': 'bulk_delete', + }, 'VIEW_NAME_FUNCTION': 'netbox.api.get_view_name', }