mirror of
https://github.com/lucaspalomodevelop/netbox-acls.git
synced 2026-03-12 23:27:23 +00:00
fixed acl type choice usage
This commit is contained in:
parent
ee851d333c
commit
e0c3a9a5f9
@ -51,9 +51,12 @@ class ACLAssignmentDirectionChoices(ChoiceSet):
|
||||
Defines the direction of the application of the ACL on an associated interface.
|
||||
"""
|
||||
|
||||
DIRECTION_INGRESS = "ingress"
|
||||
DIRECTION_EGRESS = "egress"
|
||||
|
||||
CHOICES = [
|
||||
("ingress", "Ingress", "blue"),
|
||||
("egress", "Egress", "purple"),
|
||||
(DIRECTION_INGRESS, "Ingress", "blue"),
|
||||
(DIRECTION_EGRESS, "Egress", "purple"),
|
||||
]
|
||||
|
||||
|
||||
@ -62,9 +65,12 @@ class ACLTypeChoices(ChoiceSet):
|
||||
Defines the choices availble for the Access Lists plugin specific to ACL type.
|
||||
"""
|
||||
|
||||
TYPE_STANDARD = "standard"
|
||||
TYPE_EXTENDED = "extended"
|
||||
|
||||
CHOICES = [
|
||||
("extended", "Extended", "purple"),
|
||||
("standard", "Standard", "blue"),
|
||||
(TYPE_EXTENDED, "Extended", "purple"),
|
||||
(TYPE_STANDARD, "Standard", "blue"),
|
||||
]
|
||||
|
||||
|
||||
@ -73,8 +79,12 @@ class ACLProtocolChoices(ChoiceSet):
|
||||
Defines the choices availble for the Access Lists plugin specific to ACL Rule protocol.
|
||||
"""
|
||||
|
||||
PROTOCOL_ICMP = "icmp"
|
||||
PROTOCOL_TCP = "tcp"
|
||||
PROTOCOL_UDP = "udp"
|
||||
|
||||
CHOICES = [
|
||||
("icmp", "ICMP", "purple"),
|
||||
("tcp", "TCP", "blue"),
|
||||
("udp", "UDP", "orange"),
|
||||
(PROTOCOL_ICMP, "ICMP", "purple"),
|
||||
(PROTOCOL_TCP, "TCP", "blue"),
|
||||
(PROTOCOL_UDP, "UDP", "orange"),
|
||||
]
|
||||
|
||||
@ -16,6 +16,7 @@ from utilities.forms import (
|
||||
)
|
||||
from virtualization.models import VirtualMachine, VMInterface
|
||||
|
||||
from ..choices import ACLTypeChoices
|
||||
from ..models import (
|
||||
AccessList,
|
||||
ACLExtendedRule,
|
||||
@ -201,8 +202,12 @@ class AccessListForm(NetBoxModelForm):
|
||||
"name": [error_same_acl_name],
|
||||
}
|
||||
# Check if Access List has no existing rules before change the Access List's type.
|
||||
if (acl_type == "extended" and self.instance.aclstandardrules.exists()) or (
|
||||
acl_type == "standard" and self.instance.aclextendedrules.exists()
|
||||
if (
|
||||
acl_type == ACLTypeChoices.TYPE_EXTENDED
|
||||
and self.instance.aclstandardrules.exists()
|
||||
) or (
|
||||
acl_type == ACLTypeChoices.TYPE_STANDARD
|
||||
and self.instance.aclextendedrules.exists()
|
||||
):
|
||||
error_message["type"] = [
|
||||
"This ACL has ACL rules associated, CANNOT change ACL type.",
|
||||
@ -425,7 +430,7 @@ class ACLStandardRuleForm(NetBoxModelForm):
|
||||
access_list = DynamicModelChoiceField(
|
||||
queryset=AccessList.objects.all(),
|
||||
query_params={
|
||||
"type": "standard",
|
||||
"type": ACLTypeChoices.TYPE_STANDARD,
|
||||
},
|
||||
help_text=mark_safe(
|
||||
"<b>*Note:</b> This field will only display Standard ACLs.",
|
||||
@ -507,7 +512,7 @@ class ACLExtendedRuleForm(NetBoxModelForm):
|
||||
access_list = DynamicModelChoiceField(
|
||||
queryset=AccessList.objects.all(),
|
||||
query_params={
|
||||
"type": "extended",
|
||||
"type": ACLTypeChoices.TYPE_EXTENDED,
|
||||
},
|
||||
help_text=mark_safe(
|
||||
"<b>*Note:</b> This field will only display Extended ACLs.",
|
||||
|
||||
@ -8,7 +8,7 @@ from django.db import models
|
||||
from django.urls import reverse
|
||||
from netbox.models import NetBoxModel
|
||||
|
||||
from ..choices import ACLProtocolChoices, ACLRuleActionChoices
|
||||
from ..choices import ACLProtocolChoices, ACLRuleActionChoices, ACLTypeChoices
|
||||
from .access_lists import AccessList
|
||||
|
||||
__all__ = (
|
||||
@ -84,7 +84,7 @@ class ACLStandardRule(ACLRule):
|
||||
on_delete=models.CASCADE,
|
||||
to=AccessList,
|
||||
verbose_name="Standard Access List",
|
||||
limit_choices_to={"type": "standard"},
|
||||
limit_choices_to={"type": ACLTypeChoices.TYPE_STANDARD},
|
||||
related_name="aclstandardrules",
|
||||
)
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ Specifically, all the various interactions with a client.
|
||||
from django.db.models import Count
|
||||
from netbox.views import generic
|
||||
|
||||
from . import filtersets, forms, models, tables
|
||||
from . import choices, filtersets, forms, models, tables
|
||||
|
||||
__all__ = (
|
||||
"AccessListView",
|
||||
@ -48,9 +48,10 @@ class AccessListView(generic.ObjectView):
|
||||
"""
|
||||
Depending on the Access List type, the list view will return the required ACL Rule using the previous defined tables in tables.py.
|
||||
"""
|
||||
if instance.type == "extended":
|
||||
|
||||
if instance.type == choices.ACLTypeChoices.TYPE_EXTENDED:
|
||||
table = tables.ACLExtendedRuleTable(instance.aclextendedrules.all())
|
||||
elif instance.type == "standard":
|
||||
elif instance.type == choices.ACLTypeChoices.TYPE_STANDARD:
|
||||
table = tables.ACLStandardRuleTable(instance.aclstandardrules.all())
|
||||
table.configure(request)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user