mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-29 11:56:25 -06:00
Fixes: #15924 - Prevent API payload from allowing tagged_vlans while interface mode is set to taged-all
This commit is contained in:
parent
96802b4edb
commit
5c9a145255
@ -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)
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user