From 0e16d8a0235dab054783ddc38cd841c40cf3c385 Mon Sep 17 00:00:00 2001 From: antoine Date: Tue, 21 Oct 2025 16:15:58 +0200 Subject: [PATCH] Fix authorized for dashboard command --- .../Commands/ExportStatsAsCsvCommand.php | 5 +++++ resources/js/dashboard/Dashboard.ts | 20 ++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/demo/app/Sharp/Dashboard/Commands/ExportStatsAsCsvCommand.php b/demo/app/Sharp/Dashboard/Commands/ExportStatsAsCsvCommand.php index fcc81dc79..f0ee90f5a 100644 --- a/demo/app/Sharp/Dashboard/Commands/ExportStatsAsCsvCommand.php +++ b/demo/app/Sharp/Dashboard/Commands/ExportStatsAsCsvCommand.php @@ -38,6 +38,11 @@ public function buildFormFields(FieldsContainer $formFields): void ); } + public function authorize(): bool + { + return auth()->user()->isAdmin(); + } + public function execute(array $data = []): array { $this->validate($data, [ diff --git a/resources/js/dashboard/Dashboard.ts b/resources/js/dashboard/Dashboard.ts index eded596ac..cad7dcd0e 100644 --- a/resources/js/dashboard/Dashboard.ts +++ b/resources/js/dashboard/Dashboard.ts @@ -38,18 +38,14 @@ export class Dashboard { } get visibleCommands(): ConfigCommandsData { - if(this.hiddenCommands) { - return Object.fromEntries( - Object.entries(this.config.commands ?? {}).map(([key, commands]) => [ - key, - commands.map(group => group.filter(command => { - return !this.hiddenCommands.includes(command.key); - })) - ]) - ); - } - - return this.config.commands; + return Object.fromEntries( + Object.entries(this.config.commands ?? {}).map(([key, commands]) => [ + key, + commands.map(group => group.filter(command => { + return command.authorization && !this.hiddenCommands?.includes(command.key); + })) + ]) + ); } sectionVisibleFilters(section: DashboardLayoutSectionData) {