-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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: #18881 Site Groups are missing VLAN and VM related objects #18932
base: main
Are you sure you want to change the base?
Conversation
…-missing-VLAN-and-VM-related-objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, but can you check / extend it to other scope objects - it looks like the same thing is happening for regions and racks (may be more, those are the ones I spot checked). Do the same repro steps just assign "Example VLAN Group" to a region instead of a Site Group, then check the region assigned to and it won't be in the related objects list.
I had a look at Circuit Terminations. It was missing for Site because there it was explicitly omitted since #15876, probably to keep the listed objects the same as before. To fix the generated query string, you have to omit it so the automatic entry with the wrong field name is not used, and then add it explicitly as diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py
index 1c54f93d1..482d346ab 100644
--- a/netbox/dcim/views.py
+++ b/netbox/dcim/views.py
@@ -237,7 +237,7 @@ class RegionView(GetRelatedModelsMixin, generic.ObjectView):
'related_models': self.get_related_models(
request,
regions,
- omit=(Cluster, Prefix, WirelessLAN),
+ omit=(CircuitTermination, Cluster, Prefix, WirelessLAN),
extra=(
(Location.objects.restrict(request.user, 'view').filter(site__region__in=regions), 'region_id'),
(Rack.objects.restrict(request.user, 'view').filter(site__region__in=regions), 'region_id'),
@@ -249,6 +249,7 @@ class RegionView(GetRelatedModelsMixin, generic.ObjectView):
),
# Handle these relations manually to avoid erroneous filter name resolution
+ (CircuitTermination.objects.restrict(request.user, 'view').filter(_region__in=regions), 'region_id'),
(Cluster.objects.restrict(request.user, 'view').filter(_region__in=regions), 'region_id'),
(Prefix.objects.restrict(request.user, 'view').filter(_region__in=regions), 'region_id'),
(WirelessLAN.objects.restrict(request.user, 'view').filter(_region__in=regions), 'region_id'),
@@ -336,7 +337,7 @@ class SiteGroupView(GetRelatedModelsMixin, generic.ObjectView):
'related_models': self.get_related_models(
request,
groups,
- omit=(Cluster, Prefix, WirelessLAN),
+ omit=(CircuitTermination, Cluster, Prefix, WirelessLAN),
extra=(
(Location.objects.restrict(request.user, 'view').filter(site__group__in=groups), 'site_group_id'),
(Rack.objects.restrict(request.user, 'view').filter(site__group__in=groups), 'site_group_id'),
@@ -348,6 +349,10 @@ class SiteGroupView(GetRelatedModelsMixin, generic.ObjectView):
),
# Handle these relations manually to avoid erroneous filter name resolution
+ (
+ CircuitTermination.objects.restrict(request.user, 'view').filter(_site_group__in=groups),
+ 'site_group_id'
+ ),
(
Cluster.objects.restrict(request.user, 'view').filter(_site_group__in=groups),
'site_group_id'
@@ -452,6 +457,7 @@ class SiteView(GetRelatedModelsMixin, generic.ObjectView):
),
# Handle these relations manually to avoid erroneous filter name resolution
+ (CircuitTermination.objects.restrict(request.user, 'view').filter(_site=instance), 'site_id'),
(Cluster.objects.restrict(request.user, 'view').filter(_site=instance), 'site_id'),
(Prefix.objects.restrict(request.user, 'view').filter(_site=instance), 'site_id'),
(WirelessLAN.objects.restrict(request.user, 'view').filter(_site=instance), 'site_id'),
@@ -539,7 +545,7 @@ class LocationView(GetRelatedModelsMixin, generic.ObjectView):
'related_models': self.get_related_models(
request,
locations,
- omit=[CableTermination, Cluster, Prefix, WirelessLAN],
+ omit=[CircuitTermination, CableTermination, Cluster, Prefix, WirelessLAN],
extra=(
(
Circuit.objects.restrict(request.user, 'view').filter(
@@ -549,6 +555,7 @@ class LocationView(GetRelatedModelsMixin, generic.ObjectView):
),
# Handle these relations manually to avoid erroneous filter name resolution
+ (CircuitTermination.objects.restrict(request.user, 'view').filter(_location=instance), 'location_id'),
(Cluster.objects.restrict(request.user, 'view').filter(_location=instance), 'location_id'),
(Prefix.objects.restrict(request.user, 'view').filter(_location=instance), 'location_id'),
(WirelessLAN.objects.restrict(request.user, 'view').filter(_location=instance), 'location_id'),
|
Blocked by #19038 |
Fixes: #18881 Site Groups are missing VLAN and VM related objects
Setup Related Models tab for scoped models:
Add models to
SiteGroupView
'sget_extra_context
:Add models to
RegionView
'sget_extra_context
:Add models to
RackView
'sget_extra_context
:Add models to
ClusterGroupView
'sget_extra_context
:VLANGroup
Add
Circuit Terminations
Relations