Fixes: #15924 - Prevent API payload from allowing tagged_vlans while interface mode is set to taged-all

This commit is contained in:
Daniel Sheppard 2024-08-19 20:26:27 -05:00
parent 96802b4edb
commit 5c9a145255
2 changed files with 12 additions and 0 deletions

View File

@ -1,3 +1,4 @@
from django.utils.translation import gettext as _
from django.contrib.contenttypes.models import ContentType
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
@ -246,6 +247,13 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
f"or it must be global."
})
# Validate that tagged-all payload does not include tagged_vlans
mode = data.get('mode') or self.instance.mode
if mode == InterfaceModeChoices.MODE_TAGGED_ALL and data.get('tagged_vlans'):
raise serializers.ValidationError({
'tagged_vlans': "Tagged-All interface mode must not include any tagged vlans"
})
return super().validate(data)

View File

@ -912,6 +912,10 @@ class Interface(ModularComponentModel, BaseInterface, CabledObjectModel, PathEnd
if self.rf_channel and not self.rf_channel_width:
self.rf_channel_width = get_channel_attr(self.rf_channel, 'width')
# Clear any tagged vlans set when mode is tagged-all
if self.mode == InterfaceModeChoices.MODE_TAGGED_ALL and self.tagged_vlans:
self.tagged_vlans.set([])
super().save(*args, **kwargs)
@property