Sfoglia il codice sorgente

Fixes #3001: Fix API representation of ObjectChange action and add changed_object_type

Jeremy Stretch 6 anni fa
parent
commit
3f5f75c71f
3 ha cambiato i file con 18 aggiunte e 5 eliminazioni
  1. 1 0
      CHANGELOG.md
  2. 15 4
      netbox/extras/api/serializers.py
  3. 2 1
      netbox/extras/api/views.py

+ 1 - 0
CHANGELOG.md

@@ -13,6 +13,7 @@ v2.5.9 (FUTURE)
 * [#2924](https://github.com/digitalocean/netbox/issues/2924) - Add interface type for QSFP28 50GE
 * [#2936](https://github.com/digitalocean/netbox/issues/2936) - Fix device role selection showing duplicate first entry
 * [#2998](https://github.com/digitalocean/netbox/issues/2998) - Limit device query to non-racked devices if no rack selected when creating a cable
+* [#3001](https://github.com/digitalocean/netbox/issues/3001) - Fix API representation of ObjectChange `action` and add `changed_object_type`
 * [#3014](https://github.com/digitalocean/netbox/issues/3014) - Fixes VM Role filtering
 * [#3022](https://github.com/digitalocean/netbox/issues/3022) - Add missing cable termination types to DCIM `_choices` endpoint
 

+ 15 - 4
netbox/extras/api/serializers.py

@@ -208,14 +208,25 @@ class ReportDetailSerializer(ReportSerializer):
 #
 
 class ObjectChangeSerializer(serializers.ModelSerializer):
-    user = NestedUserSerializer(read_only=True)
-    content_type = ContentTypeField(read_only=True)
-    changed_object = serializers.SerializerMethodField(read_only=True)
+    user = NestedUserSerializer(
+        read_only=True
+    )
+    action = ChoiceField(
+        choices=OBJECTCHANGE_ACTION_CHOICES,
+        read_only=True
+    )
+    changed_object_type = ContentTypeField(
+        read_only=True
+    )
+    changed_object = serializers.SerializerMethodField(
+        read_only=True
+    )
 
     class Meta:
         model = ObjectChange
         fields = [
-            'id', 'time', 'user', 'user_name', 'request_id', 'action', 'content_type', 'changed_object', 'object_data',
+            'id', 'time', 'user', 'user_name', 'request_id', 'action', 'changed_object_type', 'changed_object',
+            'object_data',
         ]
 
     def get_changed_object(self, obj):

+ 2 - 1
netbox/extras/api/views.py

@@ -10,7 +10,7 @@ from taggit.models import Tag
 
 from extras import filters
 from extras.models import (
-    ConfigContext, CustomField, ExportTemplate, Graph, ImageAttachment, ObjectChange, ReportResult, TopologyMap,
+    ConfigContext, ExportTemplate, Graph, ImageAttachment, ObjectChange, ReportResult, TopologyMap,
 )
 from extras.reports import get_report, get_reports
 from utilities.api import FieldChoicesViewSet, IsAuthenticatedOrLoginNotRequired, ModelViewSet
@@ -24,6 +24,7 @@ from . import serializers
 class ExtrasFieldChoicesViewSet(FieldChoicesViewSet):
     fields = (
         (Graph, ['type']),
+        (ObjectChange, ['action']),
     )