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: #18881 Site Groups are missing VLAN and VM related objects #18932

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

renatoalmeidaoliveira
Copy link
Collaborator

@renatoalmeidaoliveira renatoalmeidaoliveira commented Mar 17, 2025

Fixes: #18881 Site Groups are missing VLAN and VM related objects

Setup Related Models tab for scoped models:

  • sitegroup
  • region
  • site
  • location
  • rack
  • clustergroup
  • cluster

Add models to SiteGroupView's get_extra_context:

  • VLANs
  • VLAN Groups
  • Virtual Machines
  • ASNs
  • Clusters
  • Devices

Add models to RegionView's get_extra_context:

  • VLANGroup

Add models to RackView's get_extra_context:

  • VLANGroup

Add models to ClusterGroupView's get_extra_context:

  • VLANGroup

  • Add Circuit Terminations Relations

@renatoalmeidaoliveira
Copy link
Collaborator Author

Waiting for #18933 and #18939

@renatoalmeidaoliveira
Copy link
Collaborator Author

The Cluster seens to be visible in the current version of the code. To list the Cluster you need to assign it to the Site Group scope.

image

@renatoalmeidaoliveira renatoalmeidaoliveira marked this pull request as ready for review March 21, 2025 20:20
@renatoalmeidaoliveira renatoalmeidaoliveira requested review from a team and arthanson and removed request for a team March 21, 2025 20:21
Copy link
Collaborator

@arthanson arthanson left a 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.

@corubba
Copy link
Contributor

corubba commented Apr 8, 2025

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 extra with the correct field name.

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'),

@renatoalmeidaoliveira
Copy link
Collaborator Author

Blocked by #19038

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: blocked Another issue or external requirement is preventing implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Site Groups are missing VLAN and VM related objects
3 participants