Skip to content

Commit f31c46e

Browse files
[main] feat: make plugin CSP compliant (#258)
Forward-port of #255 to `main`. ## Description The plugin now declares `csp_compliant` and no longer relies on inline event handlers, so it keeps working when GLPI sends its Content Security Policy. Converted patterns: - `templates/view.html.twig`: fullscreen button `onclick="gantt.ext.fullscreen.toggle();"` replaced by the `data-gantt-fullscreen` attribute (category a). - `templates/view.html.twig`: search field `oninput="gantt.$doFilter(this.value);"` replaced by the `data-gantt-filter` attribute (category a). - `public/js/gantt-helper.js`: two delegated listeners bound once at file load, calling the same functions with the same arguments. - `setup.php`: `'csp_compliant' => true` added to `plugin_version_gantt()`. No `<script>` tag was printed from PHP or created from JavaScript: the only inline script is literal Twig text and receives the nonce automatically. No behaviour change. ## Blocked by - glpi-project/glpi#26020 (CSP) and its 11.0 / 12.0 backports: the minimum GLPI version (`PLUGIN_GANTT_MIN_GLPI_VERSION`, currently 11.0.0) must be bumped to the first CSP-enabled release before merging. ## Manual test checklist Open a project with the Gantt tab (Project item, Gantt tab) and keep the browser console open. CSP violations are reported there as `Refused to execute inline event handler` or `Refused to execute inline script`. - Click the fullscreen button (icon at the top right of the Gantt controls): the Gantt enters and leaves fullscreen mode. - Type in the "by name" search field with the Find option selected: matching tasks are highlighted and the view refreshes about 500 ms after typing stops. - Type in the same field with the Filter option selected: only matching tasks are displayed. - No CSP error appears in the console. Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com>
1 parent 7120ac1 commit f31c46e

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Add Transifex translations link to README
1313

14+
### Changed
15+
16+
- Make the plugin compatible with the Content Security Policy: inline event handlers in the Gantt view are replaced by delegated listeners.
17+
1418
## [1.4.0] - 2026-10-06
1519

1620
### Changed

‎public/js/gantt-helper.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,3 +1057,17 @@ const GlpiGantt = (function() {
10571057

10581058
// <<<<< Functions
10591059
})();
1060+
1061+
// Delegated listeners for the view template, bound once at file load
1062+
document.addEventListener('click', (e) => {
1063+
if (e.target.closest('[data-gantt-fullscreen]') !== null) {
1064+
gantt.ext.fullscreen.toggle();
1065+
}
1066+
});
1067+
1068+
document.addEventListener('input', (e) => {
1069+
const input = e.target.closest('[data-gantt-filter]');
1070+
if (input !== null) {
1071+
gantt.$doFilter(input.value);
1072+
}
1073+
});

‎setup.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function plugin_version_gantt()
8181
return [
8282
'name' => 'gantt',
8383
'version' => PLUGIN_GANTT_VERSION,
84+
'csp_compliant' => true,
8485
'author' => '<a href="http://www.teclib.com">Teclib\'</a>',
8586
'license' => 'GPL-2.0-or-later',
8687
'homepage' => '',

‎templates/view.html.twig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<div class="gantt-block__features">
3232
<ul class="gantt-block__controls mt-3">
3333
<li class="gantt-menu-item gantt-menu-item-right">
34-
<a href="#" class="btn btn-outline-secondary btn-icon" onclick="gantt.ext.fullscreen.toggle();"
34+
<a href="#" class="btn btn-outline-secondary btn-icon" data-gantt-fullscreen
3535
title="{{ __('Fullscreen', 'gantt') }}" data-bs-toggle="tooltip">
3636
<i class="fas fa-expand"></i>
3737
</a>
@@ -90,7 +90,7 @@
9090

9191
<input id="search" data-text-filter type="field" placeholder="{{ __('by name', 'gantt') }}"
9292
class="form-control"
93-
oninput="gantt.$doFilter(this.value);" />
93+
data-gantt-filter />
9494
</div>
9595
</li>
9696
</ul>

0 commit comments

Comments
 (0)