From 3ce77a9ec7d7f444a83c772fdcf4073b92be38c2 Mon Sep 17 00:00:00 2001
From: Rom1-B <8530352+Rom1-B@users.noreply.github.com>
Date: Fri, 13 Nov 2026 10:56:02 +0100
Subject: [PATCH] feat: make plugin CSP compliant
---
CHANGELOG.md | 6 ++++++
inc/dashboard.class.php | 4 ++--
public/metabase.js | 9 +++++++++
setup.php | 13 +++++++------
4 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 461137d..2a77110 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [Unreleased]
+
+### Changed
+
+- Make the plugin compatible with the Content Security Policy
+
## [1.4.3] - 2026-10-06
### Fixed
diff --git a/inc/dashboard.class.php b/inc/dashboard.class.php
index 9ad8cde..f394f72 100644
--- a/inc/dashboard.class.php
+++ b/inc/dashboard.class.php
@@ -123,8 +123,8 @@ function ($dashboard) {
'current_dashboard',
array_combine(array_column($dashboards, 'id'), array_column($dashboards, 'name')),
[
- 'on_change' => ($is_helpdesk) ? 'location.href = location.origin+location.pathname+"?uuid="+$(this).val()' : 'reloadTab("uuid=" + $(this).val());',
- 'value' => $currentUuid,
+ 'add_data_attributes' => ['metabase-dashboard-switch' => ($is_helpdesk) ? 'helpdesk' : 'central'],
+ 'value' => $currentUuid,
],
);
diff --git a/public/metabase.js b/public/metabase.js
index c75fabf..9d57229 100644
--- a/public/metabase.js
+++ b/public/metabase.js
@@ -55,4 +55,13 @@ $(function() {
}
});
});
+
+ // jQuery event: select2 triggers change on the native select
+ $(document).on("change", "select[data-metabase-dashboard-switch]", function() {
+ if ($(this).data('metabaseDashboardSwitch') === 'helpdesk') {
+ location.href = location.origin + location.pathname + "?uuid=" + $(this).val();
+ } else {
+ reloadTab("uuid=" + $(this).val());
+ }
+ });
});
diff --git a/setup.php b/setup.php
index f82f6ec..4abd6ad 100644
--- a/setup.php
+++ b/setup.php
@@ -106,12 +106,13 @@ function plugin_init_metabase()
function plugin_version_metabase()
{
return [
- 'name' => 'Metabase',
- 'version' => PLUGIN_METABASE_VERSION,
- 'author' => 'Teclib\'',
- 'license' => 'GPLv2+',
- 'homepage' => 'https://github.com/pluginsGLPI/metabase',
- 'requirements' => [
+ 'name' => 'Metabase',
+ 'version' => PLUGIN_METABASE_VERSION,
+ 'author' => 'Teclib\'',
+ 'license' => 'GPLv2+',
+ 'homepage' => 'https://github.com/pluginsGLPI/metabase',
+ 'csp_compliant' => true,
+ 'requirements' => [
'glpi' => [
'min' => PLUGIN_METABASE_MIN_GLPI,
'max' => PLUGIN_METABASE_MAX_GLPI,