From e96d65d2622b9e62c2a066af1c3a66df464b61d2 Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 1 Apr 2026 18:02:46 +0200 Subject: [PATCH 1/4] Add clear session button to Request panel Adds a "Clear Session" button to the Session section of the Request panel, allowing developers to quickly clear their session data during development without needing to manually delete session files or use browser dev tools. Follows the existing pattern used by the cache clearing functionality. Refs #1065 --- src/Controller/ToolbarController.php | 17 ++++++++++ templates/element/request_panel.php | 14 ++++++++ webroot/js/main.js | 2 ++ webroot/js/modules/Panels/RequestPanel.js | 41 +++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 webroot/js/modules/Panels/RequestPanel.js diff --git a/src/Controller/ToolbarController.php b/src/Controller/ToolbarController.php index f41e008d4..a236b5e8d 100644 --- a/src/Controller/ToolbarController.php +++ b/src/Controller/ToolbarController.php @@ -53,4 +53,21 @@ public function clearCache(): void $this->set(compact('success', 'message')); $this->viewBuilder()->setOption('serialize', ['success', 'message']); } + + /** + * Clear the session. + * + * @return void + */ + public function clearSession(): void + { + $this->request->allowMethod('post'); + $session = $this->request->getSession(); + $session->destroy(); + + $success = true; + $message = 'Session cleared.'; + $this->set(compact('success', 'message')); + $this->viewBuilder()->setOption('serialize', ['success', 'message']); + } } diff --git a/templates/element/request_panel.php b/templates/element/request_panel.php index d036b01fa..16ae169fa 100644 --- a/templates/element/request_panel.php +++ b/templates/element/request_panel.php @@ -95,6 +95,20 @@

Session

+

+ +

+
Toolbar->dumpNode($session) ?>

No Session data.

diff --git a/webroot/js/main.js b/webroot/js/main.js index 35ba8273c..760bfb24d 100644 --- a/webroot/js/main.js +++ b/webroot/js/main.js @@ -6,6 +6,7 @@ import RoutesPanel from './modules/Panels/RoutesPanel.js'; import VariablesPanel from './modules/Panels/VariablesPanel.js'; import PackagesPanel from './modules/Panels/PackagesPanel.js'; import MailPanel from './modules/Panels/MailPanel.js'; +import RequestPanel from './modules/Panels/RequestPanel.js'; document.addEventListener('DOMContentLoaded', () => { const toolbar = Start.init(); @@ -14,6 +15,7 @@ document.addEventListener('DOMContentLoaded', () => { // Init Panels CachePanel.onEvent(); + RequestPanel.onEvent(); RoutesPanel.onEvent(); PackagesPanel.onEvent(); MailPanel.onEvent(); diff --git a/webroot/js/modules/Panels/RequestPanel.js b/webroot/js/modules/Panels/RequestPanel.js new file mode 100644 index 000000000..7e5da6145 --- /dev/null +++ b/webroot/js/modules/Panels/RequestPanel.js @@ -0,0 +1,41 @@ +export default (($) => { + const addMessage = (text) => { + $(`

${text}

`) + .appendTo('.c-request-panel__messages') + .fadeOut(2000); + }; + + const init = () => { + $('.js-clear-session').on('click', function triggerSessionClear(e) { + const el = $(this); + const baseUrl = el.attr('data-url'); + const csrf = el.attr('data-csrf'); + + $.ajax({ + headers: { 'X-CSRF-TOKEN': csrf }, + url: baseUrl, + dataType: 'json', + type: 'POST', + success(data) { + addMessage(data.message); + }, + error(jqXHR, textStatus, errorThrown) { + addMessage(errorThrown); + }, + }); + e.preventDefault(); + }); + }; + + const onEvent = () => { + document.addEventListener('initPanel', (e) => { + if (e.detail === 'panelrequest') { + init(); + } + }); + }; + + return { + onEvent, + }; +})(jQuery); From 02cbd3467c168ac7af42cc485aafceb58651c9b2 Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 1 Apr 2026 18:03:31 +0200 Subject: [PATCH 2/4] Add tests for clearSession action --- .../Controller/ToolbarControllerTest.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/TestCase/Controller/ToolbarControllerTest.php b/tests/TestCase/Controller/ToolbarControllerTest.php index dddac6ac2..11581e84a 100644 --- a/tests/TestCase/Controller/ToolbarControllerTest.php +++ b/tests/TestCase/Controller/ToolbarControllerTest.php @@ -70,4 +70,30 @@ public function testClearCache() $this->assertResponseOk(); $this->assertResponseContains('success'); } + + /** + * Test clearing the session does not work with GET + * + * @return void + */ + public function testClearSessionNoGet() + { + $this->get('/debug-kit/toolbar/clear-session'); + $this->assertResponseCode(405); + } + + /** + * Test clearing the session. + * + * @return void + */ + public function testClearSession() + { + $this->session(['test' => 'value']); + $this->configRequest(['headers' => ['Accept' => 'application/json']]); + $this->post('/debug-kit/toolbar/clear-session'); + $this->assertResponseOk(); + $this->assertResponseContains('success'); + $this->assertResponseContains('Session cleared'); + } } From aa70ce15891c3c01f49a2ce8b4bbf85fb172bb0d Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 1 Apr 2026 18:05:27 +0200 Subject: [PATCH 3/4] Remove redundant GET test for clearSession --- tests/TestCase/Controller/ToolbarControllerTest.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/TestCase/Controller/ToolbarControllerTest.php b/tests/TestCase/Controller/ToolbarControllerTest.php index 11581e84a..34722a909 100644 --- a/tests/TestCase/Controller/ToolbarControllerTest.php +++ b/tests/TestCase/Controller/ToolbarControllerTest.php @@ -71,17 +71,6 @@ public function testClearCache() $this->assertResponseContains('success'); } - /** - * Test clearing the session does not work with GET - * - * @return void - */ - public function testClearSessionNoGet() - { - $this->get('/debug-kit/toolbar/clear-session'); - $this->assertResponseCode(405); - } - /** * Test clearing the session. * From a6f8904f69ecb991a804be8251c6d506601c778c Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 1 Apr 2026 18:06:12 +0200 Subject: [PATCH 4/4] Add route for clearSession action --- config/routes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/routes.php b/config/routes.php index beca12119..2505a17d7 100644 --- a/config/routes.php +++ b/config/routes.php @@ -12,6 +12,10 @@ '/toolbar/clear-cache', ['controller' => 'Toolbar', 'action' => 'clearCache'] ); + $routes->connect( + '/toolbar/clear-session', + ['controller' => 'Toolbar', 'action' => 'clearSession'] + ); $routes->connect( '/toolbar/*', ['controller' => 'Requests', 'action' => 'view']