Skip to content

Commit 237f951

Browse files
authored
Merge pull request #653 from code16/fix-authorized-dashboard-command
Fix authorized for dashboard command
2 parents 73e904c + 0e16d8a commit 237f951

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

demo/app/Sharp/Dashboard/Commands/ExportStatsAsCsvCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public function buildFormFields(FieldsContainer $formFields): void
3838
);
3939
}
4040

41+
public function authorize(): bool
42+
{
43+
return auth()->user()->isAdmin();
44+
}
45+
4146
public function execute(array $data = []): array
4247
{
4348
$this->validate($data, [

resources/js/dashboard/Dashboard.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,14 @@ export class Dashboard {
3838
}
3939

4040
get visibleCommands(): ConfigCommandsData {
41-
if(this.hiddenCommands) {
42-
return Object.fromEntries(
43-
Object.entries(this.config.commands ?? {}).map(([key, commands]) => [
44-
key,
45-
commands.map(group => group.filter(command => {
46-
return !this.hiddenCommands.includes(command.key);
47-
}))
48-
])
49-
);
50-
}
51-
52-
return this.config.commands;
41+
return Object.fromEntries(
42+
Object.entries(this.config.commands ?? {}).map(([key, commands]) => [
43+
key,
44+
commands.map(group => group.filter(command => {
45+
return command.authorization && !this.hiddenCommands?.includes(command.key);
46+
}))
47+
])
48+
);
5349
}
5450

5551
sectionVisibleFilters(section: DashboardLayoutSectionData) {

0 commit comments

Comments
 (0)