Skip to content

Commit

Permalink
fix permissions of views based on rbac, fixes #863
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkala committed Jan 15, 2025
1 parent bda93e1 commit ec91616
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changes/863.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update the queryset altering to be after permissions restriction.
Updated the queryset before rendering the compliance reporting to be after permissions restriction.
5 changes: 4 additions & 1 deletion nautobot_golden_config/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ def get_extra_context(self, request, instance=None, **kwargs):

def alter_queryset(self, request):
"""Build actual runtime queryset as the build time queryset of table `pivoted`."""
# Super because alter_queryset() calls get_queryset(), which is what calls queryset.restrict()
self.queryset = super().alter_queryset(request)
return pivot(
self.queryset,
["device", "device__name"],
Expand Down Expand Up @@ -375,7 +377,8 @@ def setup(self, request, *args, **kwargs):
"""Using request object to perform filtering based on query params."""
super().setup(request, *args, **kwargs)
filter_params = self.get_filter_params(request)
main_qs = models.ConfigCompliance.objects
# Add .restrict() to the queryset to restrict the view based on user permissions.
main_qs = models.ConfigCompliance.objects.restrict(request.user, "view")
device_aggr, feature_aggr = get_global_aggr(main_qs, self.filterset, filter_params)
feature_qs = self.filterset(request.GET, self.queryset).qs
self.extra_content = {
Expand Down

0 comments on commit ec91616

Please sign in to comment.