Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions netbox_acls/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ class Meta:
"last_updated",
"rule_count",
)
brief_fields = ("id", "url", "name", "display")
brief_fields = ("id", "url", "display", "name")

@extend_schema_field(serializers.DictField())
@extend_schema_field(serializers.JSONField(allow_null=True))
def get_assigned_object(self, obj):
serializer = get_serializer_for_model(
obj.assigned_object,
)
if obj.assigned_object is None:
return None
serializer = get_serializer_for_model(obj.assigned_object)
context = {"request": self.context["request"]}
return serializer(obj.assigned_object, nested=True, context=context).data

Expand Down Expand Up @@ -126,6 +126,7 @@ class Meta:
fields = (
"id",
"url",
"display",
"access_list",
"direction",
"assigned_object_type",
Expand All @@ -137,10 +138,12 @@ class Meta:
"created",
"last_updated",
)
brief_fields = ("id", "url", "access_list")
brief_fields = ("id", "url", "display", "access_list")

@extend_schema_field(serializers.DictField())
@extend_schema_field(serializers.JSONField(allow_null=True))
def get_assigned_object(self, obj):
if obj.assigned_object is None:
return None
serializer = get_serializer_for_model(obj.assigned_object)
context = {"request": self.context["request"]}
return serializer(obj.assigned_object, nested=True, context=context).data
Expand Down Expand Up @@ -203,15 +206,15 @@ class Meta:
"access_list",
"index",
"action",
"tags",
"description",
"remark",
"source_prefix",
"description",
"tags",
"created",
"custom_fields",
"last_updated",
"source_prefix",
)
brief_fields = ("id", "url", "display")
brief_fields = ("id", "url", "display", "access_list", "index")

def validate(self, data):
"""
Expand Down Expand Up @@ -274,19 +277,19 @@ class Meta:
"access_list",
"index",
"action",
"tags",
"description",
"created",
"custom_fields",
"last_updated",
"remark",
"protocol",
"source_prefix",
"source_ports",
"destination_prefix",
"destination_ports",
"protocol",
"remark",
"description",
"tags",
"created",
"custom_fields",
"last_updated",
)
brief_fields = ("id", "url", "display")
brief_fields = ("id", "url", "display", "access_list", "index")

def validate(self, data):
"""
Expand Down
13 changes: 6 additions & 7 deletions netbox_acls/models/access_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class AccessList(NetBoxModel):
"""
Model defintion for Access Lists.
Model definition for Access Lists.
"""

name = models.CharField(
Expand Down Expand Up @@ -89,10 +89,9 @@ def get_type_color(self):

class ACLInterfaceAssignment(NetBoxModel):
"""
Model defintion for Access Lists associations with other Host interfaces:
Model definition for Access Lists associations with other Host interfaces:
- VM interfaces
- device interface
- tbd on more
"""

access_list = models.ForeignKey(
Expand All @@ -119,6 +118,7 @@ class ACLInterfaceAssignment(NetBoxModel):
)

clone_fields = ("access_list", "direction")
prerequisite_models = ("netbox_acls.AccessList",)

class Meta:
unique_together = [
Expand All @@ -136,6 +136,9 @@ class Meta:
verbose_name = "ACL Interface Assignment"
verbose_name_plural = "ACL Interface Assignments"

def __str__(self):
return f"{self.access_list}: Interface {self.assigned_object}"

def get_absolute_url(self):
"""
The method is a Django convention; although not strictly required,
Expand All @@ -146,10 +149,6 @@ def get_absolute_url(self):
args=[self.pk],
)

@classmethod
def get_prerequisite_models(cls):
return [AccessList]

def get_direction_color(self):
return ACLAssignmentDirectionChoices.colors.get(self.direction)

Expand Down