Skip to content

Commit 0bc9cf2

Browse files
committed
feat: Adding Database Constraint for ACLExtended Rule, so that at max only one Destination Field can be specified
1 parent a84cd18 commit 0bc9cf2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

netbox_acls/models/access_list_rules.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,27 @@ class Meta(ACLRule.Meta):
322322
),
323323
name='not_more_than_one_source_for_extended_rule'
324324
),
325+
models.CheckConstraint(
326+
check=(
327+
(
328+
Q(destination_prefix__isnull=True) & Q(destination_iprange__isnull=True) & Q(destination_ipaddress__isnull=True) & Q(destination_aggregate__isnull=True) & Q(destination_service__isnull=True)
329+
) |
330+
(
331+
Q(destination_prefix__isnull=False) & Q(destination_iprange__isnull=True) & Q(destination_ipaddress__isnull=True) & Q(destination_aggregate__isnull=True) & Q(destination_service__isnull=True)
332+
) |
333+
(
334+
Q(destination_prefix__isnull=True) & Q(destination_iprange__isnull=False) & Q(destination_ipaddress__isnull=True) & Q(destination_aggregate__isnull=True) & Q(destination_service__isnull=True)
335+
) |
336+
(
337+
Q(destination_prefix__isnull=True) & Q(destination_iprange__isnull=True) & Q(destination_ipaddress__isnull=False) & Q(destination_aggregate__isnull=True) & Q(destination_service__isnull=True)
338+
) |
339+
(
340+
Q(destination_prefix__isnull=True) & Q(destination_iprange__isnull=True) & Q(destination_ipaddress__isnull=True) & Q(destination_aggregate__isnull=False) & Q(destination_service__isnull=True)
341+
) |
342+
(
343+
Q(destination_prefix__isnull=True) & Q(destination_iprange__isnull=True) & Q(destination_ipaddress__isnull=True) & Q(destination_aggregate__isnull=True) & Q(destination_service__isnull=False)
344+
)
345+
),
346+
name='not_more_than_one_destination_for_extended_rule'
347+
)
348+
]

0 commit comments

Comments
 (0)