Skip to content

Commit

Permalink
fix multiple bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnider2195 committed Oct 3, 2024
1 parent 5b71b14 commit 2c273b9
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 13 deletions.
1 change: 1 addition & 0 deletions changes/222.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed server error when navigating to Policy detail view.
2 changes: 2 additions & 0 deletions changes/233.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed name fields being optional on multiple forms.
Fixed assigned devices and assigned dynamic groups fields not marked as optional on NATPolicy and Policy.
2 changes: 2 additions & 0 deletions changes/245.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed server error when navigating to NATPolicy detail view.
Fixed server error when updating device/dynamic group weights on NATPolicy.
3 changes: 1 addition & 2 deletions nautobot_firewall_models/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ class PolicyRuleFilterForm(LocalContextFilterForm, NautobotFilterForm):
class PolicyRuleForm(LocalContextModelForm, NautobotModelForm):
"""PolicyRule creation/edit form."""

name = forms.CharField(required=False, label="Name")
tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(), required=False)
source_users = DynamicModelMultipleChoiceField(
queryset=models.UserObject.objects.all(), label="Source User Objects", required=False
Expand Down Expand Up @@ -710,7 +709,7 @@ class NATPolicyRuleForm(LocalContextModelForm, NautobotModelForm):
"""NATPolicyRule creation/edit form."""

# Metadata
name = forms.CharField(required=False, label="Name")
name = forms.CharField(label="Name")
tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(), required=False)
request_id = forms.CharField(required=False, label="Optional field for request ticket identifier.")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 4.2.16 on 2024-10-03 21:29

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("dcim", "0062_module_data_migration"),
("extras", "0114_computedfield_grouping"),
("nautobot_firewall_models", "0021_alter_addressobject_status_and_more"),
]

operations = [
migrations.AlterField(
model_name="natpolicy",
name="assigned_devices",
field=models.ManyToManyField(
blank=True,
related_name="nat_policies",
through="nautobot_firewall_models.NATPolicyDeviceM2M",
to="dcim.device",
),
),
migrations.AlterField(
model_name="natpolicy",
name="assigned_dynamic_groups",
field=models.ManyToManyField(
blank=True,
related_name="nat_policies",
through="nautobot_firewall_models.NATPolicyDynamicGroupM2M",
to="extras.dynamicgroup",
),
),
migrations.AlterField(
model_name="policy",
name="assigned_devices",
field=models.ManyToManyField(
blank=True,
related_name="firewall_policies",
through="nautobot_firewall_models.PolicyDeviceM2M",
to="dcim.device",
),
),
migrations.AlterField(
model_name="policy",
name="assigned_dynamic_groups",
field=models.ManyToManyField(
blank=True,
related_name="firewall_policies",
through="nautobot_firewall_models.PolicyDynamicGroupM2M",
to="extras.dynamicgroup",
),
),
]
10 changes: 8 additions & 2 deletions nautobot_firewall_models/models/nat_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,16 @@ class NATPolicy(PrimaryModel):
to="nautobot_firewall_models.NATPolicyRule", blank=True, related_name="nat_policies"
)
assigned_devices = models.ManyToManyField(
to="dcim.Device", through="NATPolicyDeviceM2M", related_name="nat_policies"
to="dcim.Device",
through="NATPolicyDeviceM2M",
related_name="nat_policies",
blank=True,
)
assigned_dynamic_groups = models.ManyToManyField(
to="extras.DynamicGroup", through="NATPolicyDynamicGroupM2M", related_name="nat_policies"
to="extras.DynamicGroup",
through="NATPolicyDynamicGroupM2M",
related_name="nat_policies",
blank=True,
)
status = StatusField(
on_delete=models.PROTECT,
Expand Down
10 changes: 8 additions & 2 deletions nautobot_firewall_models/models/security_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,16 @@ class Policy(PrimaryModel):
name = models.CharField(max_length=100, unique=True)
policy_rules = models.ManyToManyField(to=PolicyRule, blank=True, related_name="policies")
assigned_devices = models.ManyToManyField(
to="dcim.Device", through="PolicyDeviceM2M", related_name="firewall_policies"
to="dcim.Device",
through="PolicyDeviceM2M",
related_name="firewall_policies",
blank=True,
)
assigned_dynamic_groups = models.ManyToManyField(
to="extras.DynamicGroup", through="PolicyDynamicGroupM2M", related_name="firewall_policies"
to="extras.DynamicGroup",
through="PolicyDynamicGroupM2M",
related_name="firewall_policies",
blank=True,
)
status = StatusField(
on_delete=models.PROTECT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<strong>Assign NAT Policy Weight to Device</strong>
</div>
{% if object.natpolicydevicem2m_set.all %}
<form action="{% url 'plugins:nautobot_firewall_models:natpolicy_set_device_weight' pk=object.id %}" method="post" enctype="multipart/form-data" class="form form-horizontal">
<form action="{% url 'plugins:nautobot_firewall_models:natpolicy_devices' pk=object.id %}" method="post" enctype="multipart/form-data" class="form form-horizontal">
{% csrf_token %}
<table class="table table-hover panel-body">
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<strong>Assign NAT Policy Weight to Dynamic Group</strong>
</div>
{% if object.natpolicydynamicgroupm2m_set.all %}
<form action="{% url 'plugins:nautobot_firewall_models:natpolicy_set_dynamic_group_weight' pk=object.id %}" method="post" enctype="multipart/form-data" class="form form-horizontal">
<form action="{% url 'plugins:nautobot_firewall_models:natpolicy_dynamic-groups' pk=object.id %}" method="post" enctype="multipart/form-data" class="form form-horizontal">
{% csrf_token %}
<table class="table table-hover panel-body">
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<strong>Assign Policy Weight to Dynamic Group</strong>
</div>
{% if object.policydynamicgroupm2m_set.all %}
<form action="{% url 'plugins:nautobot_firewall_models:policy_set_dynamic_group_weight' pk=object.id %}" method="post" enctype="multipart/form-data" class="form form-horizontal">
<form action="{% url 'plugins:nautobot_firewall_models:policy_dynamic-groups' pk=object.id %}" method="post" enctype="multipart/form-data" class="form form-horizontal">
{% csrf_token %}
<table class="table table-hover panel-body">
<tr>
Expand Down
8 changes: 4 additions & 4 deletions nautobot_firewall_models/viewsets/nat_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def devices(self, request, pk, *args, **kwargs):
form_data = dict(request.POST)
form_data.pop("csrfmiddlewaretoken", None)
for device, weight in form_data.items():
m2m = NATPolicyDeviceM2M.objects.get(device=device, policy=pk)
m2m = NATPolicyDeviceM2M.objects.get(device=device, nat_policy=pk)
m2m.weight = weight[0]
m2m.validated_save()
return redirect(reverse("plugins:nautobot_firewall_models:nat_policy", kwargs={"pk": pk}))
return redirect(reverse("plugins:nautobot_firewall_models:natpolicy", kwargs={"pk": pk}))

@action(detail=True, methods=["post"])
def dynamic_groups(self, request, pk, *args, **kwargs):
Expand All @@ -90,10 +90,10 @@ def dynamic_groups(self, request, pk, *args, **kwargs):
form_data = dict(request.POST)
form_data.pop("csrfmiddlewaretoken", None)
for group, weight in form_data.items():
m2m = NATPolicyDynamicGroupM2M.objects.get(dynamic_group=group, policy=pk)
m2m = NATPolicyDynamicGroupM2M.objects.get(dynamic_group=group, nat_policy=pk)
m2m.weight = weight[0]
m2m.validated_save()
return redirect(reverse("plugins:nautobot_firewall_models:nat_policy", kwargs={"pk": pk}))
return redirect(reverse("plugins:nautobot_firewall_models:natpolicy", kwargs={"pk": pk}))

def get_queryset(self):
"""Overload to overwrite permissiosn action map."""
Expand Down

0 comments on commit 2c273b9

Please sign in to comment.