From 1904b089bd58998e9301134eb00470f4355c0ea7 Mon Sep 17 00:00:00 2001 From: Baspa Date: Fri, 3 Jan 2025 11:40:34 +0100 Subject: [PATCH 1/3] Move mail routes to class and update docs --- README.md | 24 ++++++++++++++++++++++++ resources/views/mails/download.blade.php | 8 +++++++- resources/views/mails/preview.blade.php | 5 +++-- routes/web.php | 8 -------- src/FilamentMails.php | 13 ++++++++++++- src/FilamentMailsServiceProvider.php | 7 ++----- 6 files changed, 48 insertions(+), 17 deletions(-) delete mode 100644 routes/web.php diff --git a/README.md b/README.md index 851fbf7..e1ec03e 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,14 @@ Optionally, you can publish the views using php artisan vendor:publish --tag="filament-mails-views" ``` +Add the routes to your `web.php` file: + +```php +use Vormkracht10\FilamentMails\Facades\FilamentMails; + +FilamentMails::routes(); +``` + Then add the plugin to your `PanelProvider` ```php @@ -73,6 +81,22 @@ public function panel(Panel $panel): Panel } ``` +### Tenant middleware / route protection + +If you want to protect the mail routes with your (tenant) middleware, you can do so by adding the routes to the `tenantRoutes`: + +```php +use Vormkracht10\FilamentMails\FilamentMailsPlugin; +use Vormkracht10\FilamentMails\Facades\FilamentMails; + +public function panel(Panel $panel): Panel +{ + return $panel + ->plugin(FilamentMailsPlugin::make()) + ->tenantRoutes(fn() => FilamentMails::routes()); +} +``` + > [!IMPORTANT] > For setting up the webhooks to register mail events, please look into the README of [Laravel Mails](https://github.com/vormkracht10/laravel-mails), the underlying package that powers this package. diff --git a/resources/views/mails/download.blade.php b/resources/views/mails/download.blade.php index ff0d0a5..f94285c 100644 --- a/resources/views/mails/download.blade.php +++ b/resources/views/mails/download.blade.php @@ -1,2 +1,8 @@ -Download diff --git a/resources/views/mails/preview.blade.php b/resources/views/mails/preview.blade.php index aac81a4..0f45184 100644 --- a/resources/views/mails/preview.blade.php +++ b/resources/views/mails/preview.blade.php @@ -1,5 +1,6 @@
-
diff --git a/routes/web.php b/routes/web.php deleted file mode 100644 index efe5467..0000000 --- a/routes/web.php +++ /dev/null @@ -1,8 +0,0 @@ -name('mail.preview'); -Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mail.attachment.download'); diff --git a/src/FilamentMails.php b/src/FilamentMails.php index 62565f5..1805ed0 100644 --- a/src/FilamentMails.php +++ b/src/FilamentMails.php @@ -2,4 +2,15 @@ namespace Vormkracht10\FilamentMails; -class FilamentMails {} +use Illuminate\Support\Facades\Route; +use Vormkracht10\FilamentMails\Controllers\MailDownloadController; +use Vormkracht10\FilamentMails\Controllers\MailPreviewController; + +class FilamentMails +{ + public static function routes() + { + Route::get('mails/{mail}/preview', MailPreviewController::class)->name('mails.preview'); + Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mails.attachment.download'); + } +} \ No newline at end of file diff --git a/src/FilamentMailsServiceProvider.php b/src/FilamentMailsServiceProvider.php index 9d584a3..4a37f5c 100644 --- a/src/FilamentMailsServiceProvider.php +++ b/src/FilamentMailsServiceProvider.php @@ -56,8 +56,6 @@ public function configurePackage(Package $package): void if (file_exists($package->basePath('/../resources/views'))) { $package->hasViews(static::$viewNamespace); } - - $package->hasRoute('web'); } public function packageRegistered(): void {} @@ -113,8 +111,7 @@ protected function getAssets(): array */ protected function getCommands(): array { - return [ - ]; + return []; } /** @@ -150,4 +147,4 @@ protected function getMigrations(): array 'create_filament-mails_table', ]; } -} +} \ No newline at end of file From ad08cf4255ca6506c2b13ec20ace2ba05fc808aa Mon Sep 17 00:00:00 2001 From: Baspa Date: Fri, 3 Jan 2025 11:40:44 +0100 Subject: [PATCH 2/3] Fix downloading attachments --- src/Controllers/MailDownloadController.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Controllers/MailDownloadController.php b/src/Controllers/MailDownloadController.php index 05c1a32..49b5813 100644 --- a/src/Controllers/MailDownloadController.php +++ b/src/Controllers/MailDownloadController.php @@ -2,20 +2,25 @@ namespace Vormkracht10\FilamentMails\Controllers; -use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Storage; use Vormkracht10\Mails\Models\MailAttachment; class MailDownloadController extends Controller { - public function __invoke(Request $request) + public function __invoke(string $tenant, string $mail, string $attachment, string $filename) { /** @var MailAttachment $attachment */ - $attachment = MailAttachment::find($request->attachment); + $attachment = MailAttachment::find($attachment); - $file = Storage::disk($attachment->disk)->get($attachment->uuid); + $file = Storage::disk($attachment->disk)->path($attachment->uuid); - return response()->download($file); + return response()->download( + file: $file, + name: $filename, + headers: [ + 'Content-Type' => $attachment->mime, + ] + ); } -} +} \ No newline at end of file From f754129a8351e4b7e76b49e3e860457c2a32eed9 Mon Sep 17 00:00:00 2001 From: Baspa Date: Fri, 3 Jan 2025 10:41:13 +0000 Subject: [PATCH 3/3] Fix styling --- src/Controllers/MailDownloadController.php | 2 +- src/FilamentMails.php | 2 +- src/FilamentMailsServiceProvider.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Controllers/MailDownloadController.php b/src/Controllers/MailDownloadController.php index 49b5813..7bc96cc 100644 --- a/src/Controllers/MailDownloadController.php +++ b/src/Controllers/MailDownloadController.php @@ -23,4 +23,4 @@ public function __invoke(string $tenant, string $mail, string $attachment, strin ] ); } -} \ No newline at end of file +} diff --git a/src/FilamentMails.php b/src/FilamentMails.php index 1805ed0..73bcc54 100644 --- a/src/FilamentMails.php +++ b/src/FilamentMails.php @@ -13,4 +13,4 @@ public static function routes() Route::get('mails/{mail}/preview', MailPreviewController::class)->name('mails.preview'); Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mails.attachment.download'); } -} \ No newline at end of file +} diff --git a/src/FilamentMailsServiceProvider.php b/src/FilamentMailsServiceProvider.php index 4a37f5c..a96236c 100644 --- a/src/FilamentMailsServiceProvider.php +++ b/src/FilamentMailsServiceProvider.php @@ -147,4 +147,4 @@ protected function getMigrations(): array 'create_filament-mails_table', ]; } -} \ No newline at end of file +}