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 <[email protected]>
This commit is contained in:
1 parent
de8d13aec1
commit
8458cbe8cf
4 files changed
+4
-22
No files matched your search
@@ -124,7 +124,6 @@
|
|||||||
.netbox-explorer-tile[draggable="true"] { cursor: grab; }
|
.netbox-explorer-tile[draggable="true"] { cursor: grab; }
|
||||||
.netbox-explorer-tile.dragging { opacity: .4; }
|
.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-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; } }
|
@media (max-width: 767px) { .netbox-explorer-nav { display: none; } }
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@@ -440,13 +439,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
function dropHighlight(el) {
|
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');
|
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 originalTile(pk) { return explorer.querySelector('.netbox-explorer-pane[data-folder] .netbox-explorer-tile[data-kind="document"][data-pk="' + pk + '"]'); }
|
||||||
|
|
||||||
function refreshFolderTile(folderId) {
|
function refreshFolderTile(folderId) {
|
||||||
@@ -465,15 +457,13 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
|
|
||||||
var dragged = null, lastHighlight = null;
|
var dragged = null, lastHighlight = null;
|
||||||
function clearHighlight() {
|
function clearHighlight() {
|
||||||
if (lastHighlight) lastHighlight.classList.remove('netbox-explorer-drop', 'netbox-explorer-nodrop');
|
if (lastHighlight) lastHighlight.classList.remove('netbox-explorer-drop');
|
||||||
lastHighlight = null;
|
lastHighlight = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveDocument(doc, folderId) {
|
function moveDocument(doc, folderId) {
|
||||||
var source = doc.closest('.netbox-explorer-pane[data-folder]').dataset.folder;
|
var source = doc.closest('.netbox-explorer-pane[data-folder]').dataset.folder;
|
||||||
if (source === folderId) return;
|
if (source === folderId) return;
|
||||||
var conflict = tenantConflict(doc, folderId);
|
|
||||||
if (conflict) { toast(conflict, false); return; }
|
|
||||||
var body = new FormData();
|
var body = new FormData();
|
||||||
body.append('category', folderId === 'root' ? '' : folderId);
|
body.append('category', folderId === 'root' ? '' : folderId);
|
||||||
body.append('csrfmiddlewaretoken', document.querySelector('#doc-explorer-export [name=csrfmiddlewaretoken]').value);
|
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);
|
var el = folderId && dropHighlight(e.target);
|
||||||
if (el !== lastHighlight) clearHighlight();
|
if (el !== lastHighlight) clearHighlight();
|
||||||
if (!folderId) return;
|
if (!folderId) return;
|
||||||
var ok = !tenantConflict(dragged, folderId);
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.dataTransfer.dropEffect = ok ? 'move' : 'none';
|
e.dataTransfer.dropEffect = 'move';
|
||||||
lastHighlight = el;
|
lastHighlight = el;
|
||||||
el.classList.add(ok ? 'netbox-explorer-drop' : 'netbox-explorer-nodrop');
|
el.classList.add('netbox-explorer-drop');
|
||||||
});
|
});
|
||||||
explorer.addEventListener('drop', function (e) {
|
explorer.addEventListener('drop', function (e) {
|
||||||
if (!dragged) return;
|
if (!dragged) return;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<a class="netbox-explorer-tile" href="{{ document.get_absolute_url }}" data-name="{{ document.title|lower }}" title="{{ document.title }}"
|
<a class="netbox-explorer-tile" href="{{ document.get_absolute_url }}" data-name="{{ document.title|lower }}" title="{{ document.title }}"
|
||||||
data-kind="document" data-pk="{{ document.pk }}" data-print="{% url 'plugins:netbox_documentation:document_print' pk=document.pk %}"
|
data-kind="document" data-pk="{{ document.pk }}" data-print="{% url 'plugins:netbox_documentation:document_print' pk=document.pk %}"
|
||||||
data-tenant="{{ document.tenant_id|default:'' }}"
|
|
||||||
{% if perms.netbox_documentation.change_document %}data-edit="{% url 'plugins:netbox_documentation:document_edit' pk=document.pk %}" data-move="{% url 'plugins:netbox_documentation:document_move' pk=document.pk %}" draggable="true"{% endif %}
|
{% if perms.netbox_documentation.change_document %}data-edit="{% url 'plugins:netbox_documentation:document_edit' pk=document.pk %}" data-move="{% url 'plugins:netbox_documentation:document_move' pk=document.pk %}" draggable="true"{% endif %}
|
||||||
{% if perms.netbox_documentation.delete_document %}data-delete="{% url 'plugins:netbox_documentation:document_delete' pk=document.pk %}"{% endif %}>
|
{% if perms.netbox_documentation.delete_document %}data-delete="{% url 'plugins:netbox_documentation:document_delete' pk=document.pk %}"{% endif %}>
|
||||||
<i class="mdi mdi-file-document-outline netbox-explorer-icon text-primary"></i>
|
<i class="mdi mdi-file-document-outline netbox-explorer-icon text-primary"></i>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<div class="netbox-explorer-tile" data-open="{{ node.object.pk }}" data-name="{{ node.object.name|lower }}" title="{{ node.object.name }}" tabindex="0"
|
<div class="netbox-explorer-tile" data-open="{{ node.object.pk }}" data-name="{{ node.object.name|lower }}" title="{{ node.object.name }}" tabindex="0"
|
||||||
data-kind="folder" data-pk="{{ node.object.pk }}" data-url="{{ node.object.get_absolute_url }}"
|
data-kind="folder" data-pk="{{ node.object.pk }}" data-url="{{ node.object.get_absolute_url }}"
|
||||||
data-tenant="{{ node.object.tenant_id|default:'' }}" data-tenant-name="{{ node.object.tenant|default:'' }}"
|
|
||||||
{% if perms.netbox_documentation.change_documentcategory %}data-edit="{% url 'plugins:netbox_documentation:documentcategory_edit' pk=node.object.pk %}"{% endif %}
|
{% if perms.netbox_documentation.change_documentcategory %}data-edit="{% url 'plugins:netbox_documentation:documentcategory_edit' pk=node.object.pk %}"{% endif %}
|
||||||
{% if perms.netbox_documentation.delete_documentcategory %}data-delete="{% url 'plugins:netbox_documentation:documentcategory_delete' pk=node.object.pk %}"{% endif %}>
|
{% if perms.netbox_documentation.delete_documentcategory %}data-delete="{% url 'plugins:netbox_documentation:documentcategory_delete' pk=node.object.pk %}"{% endif %}>
|
||||||
<i class="mdi {% if node.children or node.documents %}mdi-folder{% else %}mdi-folder-outline{% endif %} netbox-explorer-icon text-warning"></i>
|
<i class="mdi {% if node.children or node.documents %}mdi-folder{% else %}mdi-folder-outline{% endif %} netbox-explorer-icon text-warning"></i>
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ class DocumentEditView(generic.ObjectEditView):
|
|||||||
|
|
||||||
|
|
||||||
class DocumentMoveView(PermissionRequiredMixin, View):
|
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"
|
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()
|
category = DocumentCategory.objects.restrict(request.user, "view").filter(pk=category_id).first()
|
||||||
if category is None:
|
if category is None:
|
||||||
return JsonResponse({"error": "Der Zielordner existiert nicht."}, status=404)
|
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):
|
if document.category_id != (category.pk if category else None):
|
||||||
document.snapshot()
|
document.snapshot()
|
||||||
document.category = category
|
document.category = category
|
||||||
|
|||||||
Reference in new issue
Block a user