From 163287da4fb2eae31a811cbe1bb7cff6d1fa32e0 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Mon, 18 Jul 2022 20:05:54 +0000 Subject: [PATCH] put in logic to prevent ACL type change if it has rules --- netbox_access_lists/forms.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/netbox_access_lists/forms.py b/netbox_access_lists/forms.py index 6d4d741..a3ee881 100644 --- a/netbox_access_lists/forms.py +++ b/netbox_access_lists/forms.py @@ -51,7 +51,7 @@ class AccessListForm(NetBoxModelForm): help_texts = { 'default_action': 'The default behavior of the ACL.', 'name': 'The name uniqueness per device is case insensitive.', - 'type': 'Sets the type of the ACL & its rules.', + 'type': mark_safe('*Note: CANNOT be changed if ACL Rules are assoicated to this Access-List.'), } def clean(self): @@ -60,8 +60,13 @@ class AccessListForm(NetBoxModelForm): return cleaned_data name = cleaned_data.get('name') device = cleaned_data.get('device') + type = cleaned_data.get('type') if ('name' in self.changed_data or 'device' in self.changed_data) and AccessList.objects.filter(name__iexact=name, device=device).exists(): raise forms.ValidationError('An ACL with this name (case insensitive) is already associated to this device.') + if type == 'extended' and self.instance.aclstandardrules.exists(): + raise forms.ValidationError('This ACL has Standard ACL rules already associated, CANNOT change ACL type!!') + elif type == 'standard' and self.instance.aclextendedrules.exists(): + raise forms.ValidationError('This ACL has Extended ACL rules already associated, CANNOT change ACL type!!') return cleaned_data class AccessListFilterForm(NetBoxModelFilterSetForm):