From 5bfc032108969bc808729d86260ede0aad3af52f Mon Sep 17 00:00:00 2001 From: Abdelhammied Elsayed Date: Tue, 21 Jan 2025 01:58:51 +0200 Subject: [PATCH 1/2] Get user by the panel guard. Add Getting user by the panel guard for different guard and assert the filament function exists for panels usage --- packages/actions/src/Concerns/CanExportRecords.php | 4 ++++ packages/actions/src/Concerns/CanImportRecords.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/actions/src/Concerns/CanExportRecords.php b/packages/actions/src/Concerns/CanExportRecords.php index 15f2332ef6f..1c04b3fe61e 100644 --- a/packages/actions/src/Concerns/CanExportRecords.php +++ b/packages/actions/src/Concerns/CanExportRecords.php @@ -146,6 +146,10 @@ protected function setUp(): void $user = auth()->user(); + if (function_exists('filament')) { + $user = auth(filament()->getAuthGuard())->user(); + } + if ($action->hasColumnMapping()) { $columnMap = collect($data['columnMap']) ->dot() diff --git a/packages/actions/src/Concerns/CanImportRecords.php b/packages/actions/src/Concerns/CanImportRecords.php index 7092360993f..4e4f3a212e0 100644 --- a/packages/actions/src/Concerns/CanImportRecords.php +++ b/packages/actions/src/Concerns/CanImportRecords.php @@ -214,6 +214,10 @@ protected function setUp(): void $user = auth()->user(); + if (function_exists('filament')) { + $user = auth(filament()->getAuthGuard())->user(); + } + $import = app(Import::class); $import->user()->associate($user); $import->file_name = $csvFile->getClientOriginalName(); From 38079bb089b879c4a1b971d21227402146b88d6d Mon Sep 17 00:00:00 2001 From: Abdelhammied Elsayed Date: Tue, 21 Jan 2025 02:03:58 +0200 Subject: [PATCH 2/2] Update DownloadExport.php add the fix in the download export handler --- .../src/Exports/Http/Controllers/DownloadExport.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/actions/src/Exports/Http/Controllers/DownloadExport.php b/packages/actions/src/Exports/Http/Controllers/DownloadExport.php index 3c115c8fdac..5a8c133d816 100644 --- a/packages/actions/src/Exports/Http/Controllers/DownloadExport.php +++ b/packages/actions/src/Exports/Http/Controllers/DownloadExport.php @@ -17,7 +17,13 @@ public function __invoke(Request $request, Export $export): StreamedResponse if (filled(Gate::getPolicyFor($export::class))) { authorize('view', $export); } else { - abort_unless($export->user()->is(auth()->user()), 403); + $user = auth()->user(); + + if (function_exists('filament')) { + $user = auth(filament()->getAuthGuard())->user(); + } + + abort_unless($export->user()->is($user), 403); } $format = ExportFormat::tryFrom($request->query('format'));