From 8458cbe8cf89290775ab38cb3a1d90b72f1dd7b8 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 12 Oct 2026 11:40:58 +0200 Subject: [PATCH] fix: allow moving documents into any folder regardless of tenant Drag & drop no longer rejects folders that belong to another tenant. Moving only changes the document's folder; its tenant stays untouched. Co-Authored-By: Claude Opus 5.5 --- .../netbox_documentation/document_tree.html | 17 +++-------------- .../inc/explorer_file_tile.html | 1 - .../inc/explorer_folder_tile.html | 1 - netbox_documentation/views.py | 7 +------ 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/netbox_documentation/templates/netbox_documentation/document_tree.html b/netbox_documentation/templates/netbox_documentation/document_tree.html index 058388a..055ef5e 100644 --- a/netbox_documentation/templates/netbox_documentation/document_tree.html +++ b/netbox_documentation/templates/netbox_documentation/document_tree.html @@ -124,7 +124,6 @@ .netbox-explorer-tile[draggable="true"] { cursor: grab; } .netbox-explorer-tile.dragging { opacity: .4; } .netbox-explorer-drop { background-color: rgba(var(--tblr-success-rgb, 47,179,68), .18) !important; outline: 2px dashed rgba(var(--tblr-success-rgb, 47,179,68), .8); outline-offset: -2px; } - .netbox-explorer-nodrop { background-color: rgba(var(--tblr-danger-rgb, 214,57,57), .12) !important; outline: 2px dashed rgba(var(--tblr-danger-rgb, 214,57,57), .7); outline-offset: -2px; cursor: not-allowed; } @media (max-width: 767px) { .netbox-explorer-nav { display: none; } } @@ -440,13 +439,6 @@ document.addEventListener('DOMContentLoaded', function () { function dropHighlight(el) { return el.closest('.netbox-explorer-tile[data-kind="folder"], .netbox-explorer-nav-row, .netbox-explorer-address [data-open]') || el.closest('.netbox-explorer-content'); } - // Same rule as the server: a folder with a tenant only accepts documents of that tenant. - function tenantConflict(doc, folderId) { - if (folderId === 'root') return null; - var f = folderTile(folderId); - if (!f || !f.dataset.tenant || f.dataset.tenant === doc.dataset.tenant) return null; - return 'Der Ordner gehört zum Mandanten „' + f.dataset.tenantName + '“. Das Dokument muss im selben Mandanten bleiben.'; - } function originalTile(pk) { return explorer.querySelector('.netbox-explorer-pane[data-folder] .netbox-explorer-tile[data-kind="document"][data-pk="' + pk + '"]'); } function refreshFolderTile(folderId) { @@ -465,15 +457,13 @@ document.addEventListener('DOMContentLoaded', function () { var dragged = null, lastHighlight = null; function clearHighlight() { - if (lastHighlight) lastHighlight.classList.remove('netbox-explorer-drop', 'netbox-explorer-nodrop'); + if (lastHighlight) lastHighlight.classList.remove('netbox-explorer-drop'); lastHighlight = null; } function moveDocument(doc, folderId) { var source = doc.closest('.netbox-explorer-pane[data-folder]').dataset.folder; if (source === folderId) return; - var conflict = tenantConflict(doc, folderId); - if (conflict) { toast(conflict, false); return; } var body = new FormData(); body.append('category', folderId === 'root' ? '' : folderId); body.append('csrfmiddlewaretoken', document.querySelector('#doc-explorer-export [name=csrfmiddlewaretoken]').value); @@ -512,11 +502,10 @@ document.addEventListener('DOMContentLoaded', function () { var el = folderId && dropHighlight(e.target); if (el !== lastHighlight) clearHighlight(); if (!folderId) return; - var ok = !tenantConflict(dragged, folderId); e.preventDefault(); - e.dataTransfer.dropEffect = ok ? 'move' : 'none'; + e.dataTransfer.dropEffect = 'move'; lastHighlight = el; - el.classList.add(ok ? 'netbox-explorer-drop' : 'netbox-explorer-nodrop'); + el.classList.add('netbox-explorer-drop'); }); explorer.addEventListener('drop', function (e) { if (!dragged) return; diff --git a/netbox_documentation/templates/netbox_documentation/inc/explorer_file_tile.html b/netbox_documentation/templates/netbox_documentation/inc/explorer_file_tile.html index e0f4266..58ea33d 100644 --- a/netbox_documentation/templates/netbox_documentation/inc/explorer_file_tile.html +++ b/netbox_documentation/templates/netbox_documentation/inc/explorer_file_tile.html @@ -1,6 +1,5 @@ diff --git a/netbox_documentation/templates/netbox_documentation/inc/explorer_folder_tile.html b/netbox_documentation/templates/netbox_documentation/inc/explorer_folder_tile.html index 2146bf8..623723a 100644 --- a/netbox_documentation/templates/netbox_documentation/inc/explorer_folder_tile.html +++ b/netbox_documentation/templates/netbox_documentation/inc/explorer_folder_tile.html @@ -1,6 +1,5 @@
diff --git a/netbox_documentation/views.py b/netbox_documentation/views.py index b5ff1db..7205a38 100644 --- a/netbox_documentation/views.py +++ b/netbox_documentation/views.py @@ -127,7 +127,7 @@ class DocumentEditView(generic.ObjectEditView): class DocumentMoveView(PermissionRequiredMixin, View): - """Move a document into another folder (drag & drop in the Explorer). The tenant never changes.""" + """Move a document into any other folder (drag & drop in the Explorer). Only the folder changes, never the tenant.""" permission_required = "netbox_documentation.change_document" @@ -139,11 +139,6 @@ class DocumentMoveView(PermissionRequiredMixin, View): category = DocumentCategory.objects.restrict(request.user, "view").filter(pk=category_id).first() if category is None: return JsonResponse({"error": "Der Zielordner existiert nicht."}, status=404) - if category.tenant_id and category.tenant_id != document.tenant_id: - return JsonResponse({ - "error": f"Der Ordner „{category.name}“ gehört zum Mandanten „{category.tenant}“. " - f"Das Dokument muss im selben Mandanten bleiben.", - }, status=400) if document.category_id != (category.pk if category else None): document.snapshot() document.category = category