fix: globalen Mandantenfilter in Ordner-/Dokumentenbaum respektieren
Die Baumansichten (DocumentTreeView, DocumentCategoryTreeView) bauen ihr Queryset manuell statt ueber ein NetBoxModelFilterSet, wodurch das netbox-utilities-Plugin seinen tenant_id/tenant_group_id-Parameter nicht injizieren konnte und ausserhalb des gewaehlten Mandanten liegende Ordner/Dokumente mit angezeigt wurden. Liest jetzt den oeffentlichen Scope aus netbox_utilities.tenant_scope direkt aus (fallback: kein Filter, falls das Plugin nicht installiert ist). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@ class DocumentationConfig(PluginConfig):
|
||||
name = "netbox_documentation"
|
||||
verbose_name = "NetBox Dokumentation"
|
||||
description = "Wiki und Office-Dokumentation direkt in NetBox"
|
||||
version = "0.10.0"
|
||||
version = "0.11.1"
|
||||
author = "LKE"
|
||||
base_url = "documentation"
|
||||
min_version = "4.0.0"
|
||||
|
||||
@@ -30,6 +30,21 @@ from .models import (
|
||||
from .tables import DocumentTable, AssignmentTable, DocumentCategoryTable
|
||||
|
||||
|
||||
def _active_tenant_ids(request):
|
||||
"""Tenant IDs of the globally selected tenant/tenant-group (netbox-utilities), if any.
|
||||
|
||||
Our tree views build their querysets by hand rather than through a NetBoxModelFilterSet,
|
||||
so they don't pick up the tenant_id/tenant_group_id GET param that plugin's middleware
|
||||
injects for FilterSet-based views. Read its public scope API directly instead.
|
||||
"""
|
||||
try:
|
||||
from netbox_utilities.tenant_scope import active_tenant_scope
|
||||
except ImportError:
|
||||
return None
|
||||
scope = active_tenant_scope.get()
|
||||
return scope.tenant_ids if scope else None
|
||||
|
||||
|
||||
class EditorAssetView(View):
|
||||
"""Serve the bundled editor assets when NetBox's static proxy is unavailable."""
|
||||
|
||||
@@ -59,16 +74,16 @@ class DocumentTreeView(PermissionRequiredMixin, View):
|
||||
template_name = "netbox_documentation/document_tree.html"
|
||||
|
||||
def get(self, request):
|
||||
categories = list(
|
||||
DocumentCategory.objects.restrict(request.user, "view")
|
||||
.select_related("tenant_group", "tenant")
|
||||
.order_by("name")
|
||||
)
|
||||
documents = list(
|
||||
Document.objects.restrict(request.user, "view")
|
||||
.select_related("category", "tenant_group", "tenant")
|
||||
.order_by("title")
|
||||
)
|
||||
tenant_ids = _active_tenant_ids(request)
|
||||
|
||||
category_qs = DocumentCategory.objects.restrict(request.user, "view").select_related("tenant_group", "tenant")
|
||||
document_qs = Document.objects.restrict(request.user, "view").select_related("category", "tenant_group", "tenant")
|
||||
if tenant_ids is not None:
|
||||
category_qs = category_qs.filter(tenant_id__in=tenant_ids)
|
||||
document_qs = document_qs.filter(tenant_id__in=tenant_ids)
|
||||
|
||||
categories = list(category_qs.order_by("name"))
|
||||
documents = list(document_qs.order_by("title"))
|
||||
|
||||
nodes = {category.pk: {"object": category, "children": [], "documents": []} for category in categories}
|
||||
roots = []
|
||||
@@ -135,12 +150,17 @@ class DocumentCategoryTreeView(PermissionRequiredMixin, View):
|
||||
template_name = "netbox_documentation/documentcategory_tree.html"
|
||||
|
||||
def get(self, request):
|
||||
categories = list(
|
||||
tenant_ids = _active_tenant_ids(request)
|
||||
|
||||
category_qs = (
|
||||
DocumentCategory.objects.restrict(request.user, "view")
|
||||
.select_related("tenant_group", "tenant")
|
||||
.annotate(document_total=Count("documents", distinct=True))
|
||||
.order_by("name")
|
||||
)
|
||||
if tenant_ids is not None:
|
||||
category_qs = category_qs.filter(tenant_id__in=tenant_ids)
|
||||
|
||||
categories = list(category_qs.order_by("name"))
|
||||
nodes = {category.pk: {"object": category, "children": []} for category in categories}
|
||||
roots = []
|
||||
for category in categories:
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "netbox-documentation"
|
||||
version = "0.10.0"
|
||||
version = "0.11.1"
|
||||
description = "Integrated Markdown wiki and office document importer for NetBox"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
Reference in New Issue
Block a user