Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 17 commits into
base: feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion netbox/dcim/api/serializers_/device_components.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -236,8 +237,8 @@ class Meta:

def validate(self, data):

# Validate many-to-many VLAN assignments
if not self.nested:
# Validate many-to-many VLAN assignments
device = self.instance.device if self.instance else data.get('device')
for vlan in data.get('tagged_vlans', []):
if vlan.site not in [device.site, None]:
Expand Down
6 changes: 6 additions & 0 deletions netbox/dcim/models/device_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,12 @@ def clean(self):
).format(untagged_vlan=self.untagged_vlan)
})

# Validate that tagged-all payload does not include tagged_vlans
if self.mode != InterfaceModeChoices.MODE_TAGGED and self.tagged_vlans:
DanSheps marked this conversation as resolved.
Show resolved Hide resolved
raise ValidationError({
'tagged_vlans': "Interface mode does not support including tagged vlans"
})

def save(self, *args, **kwargs):

# Set absolute channel attributes from selected options
Expand Down
Loading