Fixes #22588: Filter VLANs by Site Group scope when assigning to a prefix#22684
Conversation
…igning to a prefix
…igning to a prefix
|
@claude /review Only report on issues of potential concern; we don't need commentary on anything that doesn't require further consideration. |
|
Claude finished @jeremystretch's task in 2m 21s —— View job Review
Two concerns worth addressing: 1. Every other # get_for_site() — includes global VLANs ✓
return self.filter(
Q(group__in=VLANGroup.objects.filter(q)) |
Q(site=site) |
Q(group__scope_id__isnull=True, site__isnull=True) | # Global group VLANs
Q(group__isnull=True, site__isnull=True) # Global VLANs
)
# get_for_site_group() — omits global VLANs ✗
return self.filter(
Q(group__in=VLANGroup.objects.filter(q))
)When a prefix is scoped to a site group, globally available VLANs (those not tied to any specific location scope) would not appear in the assignment dropdown. That seems unintentional. Fix this → 2. Test uses unsaved site_group = SiteGroup(name='Site Group 1', slug='site-group-1') # pk=None, not saved
form = PrefixForm(data={
'scope_type': ContentType.objects.get_for_model(SiteGroup).id,
'scope': site_group,
})The test works because it only checks widget attributes and never calls |
…se saved SiteGroup in test
|
Hi @arthanson — just wanted to do a friendly follow-up on this PR. The two concerns from the automated review have been addressed (global VLANs added to |
arthanson
left a comment
There was a problem hiding this comment.
Thanks @ascjreddy I'd request to just add a filterset test for the actual filtering.
The current Test does not exercise get_for_site_group() or the available_at_site_group filter at all. The bug-fixing logic is currently untested.
There's a ready-made pattern to mirror at ipam/tests/test_filtersets.py:2219:
def test_available_at_site(self):
site_id = Site.objects.first().pk
params = {'available_at_site': site_id}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 5) # 4 scoped + 1 global group + 1 global
Please add an analogous test_available_at_site_group that asserts a Site-Group-scoped VLAN is included while an out-of-scope VLAN is excluded
|
Hi @arthanson — added |
Closes: #22588
When a prefix's scope is set to a Site Group, the VLAN dropdown was showing all VLANs regardless of scope. This PR fixes that by:
get_for_site_group()method toVLANQuerySetthat filters VLANs to only those belonging to the VLAN Groups scoped to the specified Site Group (or its ancestors)available_at_site_groupfilter toVLANFilterSetthat calls this methodPrefixForm.__init__to swap theavailable_at_sitequery param foravailable_at_site_groupwhen the prefix scope is a Site Group