Fix CSRF failure when saving layout; rename plugin to NetBox-Floorplaner

Read the CSRF token from a rendered {% csrf_token %} instead of the
cookie, which may be HttpOnly or use a custom name. Set the plugin
author to Claude and bump the version to 0.1.1 (busts static cache).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-11-04 12:47:34 +01:00
1 parent b8f2e5155e
commit 6b47b0fd5b
4 files changed
+13 -9

No files matched your search

+3 -3
View File
@@ -1,15 +1,15 @@
from django.utils.translation import gettext_lazy as _
from netbox.plugins import PluginConfig
__version__ = '0.1.0'
__version__ = '0.1.1'
class FloorPlannerConfig(PluginConfig):
name = 'netbox_floorplanner'
verbose_name = _('Floor Planner')
verbose_name = 'NetBox-Floorplaner'
description = _('Drag & drop floor plan designer for sites and locations')
version = __version__
author = 'Louis'
author = 'Claude'
base_url = 'floorplanner'
min_version = '4.7.2'
default_settings = {
@@ -144,6 +144,10 @@
buildDom() {
this.root.classList.add(this.edit ? 'fp-edit' : 'fp-view');
this.root.tabIndex = 0;
// The template renders {% csrf_token %} into the root; the cookie may be
// unavailable (CSRF_COOKIE_HTTPONLY, custom cookie name), so prefer this.
const tokenInput = this.root.querySelector('input[name=csrfmiddlewaretoken]');
this.csrfToken = tokenInput ? tokenInput.value : getCookie('csrftoken');
this.root.innerHTML = '';
this.toolbar = html('div', { class: 'fp-toolbar' });
@@ -410,7 +414,7 @@
const resp = await fetch(this.cfg.api.layout, {
method: 'PUT',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRFToken': getCookie('csrftoken') },
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRFToken': this.csrfToken },
body: JSON.stringify(this.serialize()),
});
const data = await resp.json().catch(() => ({}));
@@ -1,5 +1,5 @@
{% load static %}
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.0">
<div class="fp-root" data-fp-config="fp-config"></div>
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.1">
<div class="fp-root" data-fp-config="fp-config">{% csrf_token %}</div>
{{ designer_config|json_script:"fp-config" }}
<script src="{% static 'netbox_floorplanner/floorplanner.js' %}?v=0.1.0"></script>
<script src="{% static 'netbox_floorplanner/floorplanner.js' %}?v=0.1.1"></script>
+2 -2
View File
@@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"
[project]
name = "netbox-floorplanner"
version = "0.1.0"
version = "0.1.1"
description = "Modern drag & drop floor plan designer for NetBox 4.7+"
readme = "README.md"
license = "Apache-2.0"
requires-python = ">=3.12"
authors = [{ name = "Louis" }]
authors = [{ name = "Claude" }]
classifiers = [
"Framework :: Django",
"Programming Language :: Python :: 3",