From f8cb879e42a9f85a34a30f3238588ceb525a726c Mon Sep 17 00:00:00 2001 From: Peter Papp Date: Fri, 23 Jul 2021 18:13:58 +0200 Subject: [PATCH] queueable email sharing --- composer.json | 1 + composer.lock | 86 ++++++++++++++++++- src/Domain/Folders/Models/Folder.php | 6 +- .../Sharing/Actions/SendViaEmailAction.php | 7 +- .../Sharing/Controllers/ShareController.php | 6 +- .../Controllers/ShareViaEmailController.php | 2 +- src/Support/helpers.php | 2 +- tests/App/Users/UserAccountTest.php | 8 +- tests/Domain/Files/FileTest.php | 1 - 9 files changed, 103 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index f02984ac..cec043cd 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "madnest/madzipper": "^1.1.0", "spatie/laravel-backup": "^6.16.1", "spatie/laravel-query-builder": "^3.5", + "spatie/laravel-queueable-action": "^2.12", "spatie/laravel-tail": "^4.3.3", "teamtnt/laravel-scout-tntsearch-driver": "^11.5.0.0", "vimeo/psalm": "^4.8.1" diff --git a/composer.lock b/composer.lock index 6d21b645..b08e6de4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "50eedc067d37499da24bee315d3008da", + "content-hash": "e4a7f5591e1c7216ee06ab20feba09d3", "packages": [ { "name": "amphp/amp", @@ -7284,6 +7284,90 @@ ], "time": "2021-07-05T14:17:44+00:00" }, + { + "name": "spatie/laravel-queueable-action", + "version": "2.12.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-queueable-action.git", + "reference": "27c156a8b41d2d5ef191594fc91f2bed73f4c2e1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-queueable-action/zipball/27c156a8b41d2d5ef191594fc91f2bed73f4c2e1", + "reference": "27c156a8b41d2d5ef191594fc91f2bed73f4c2e1", + "shasum": "" + }, + "require": { + "laravel/framework": "^8.0", + "php": "^7.4|^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.4", + "orchestra/testbench": "^4.0|^5.0|^6.0", + "phpunit/phpunit": "^8.4|^9.3" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\QueueableAction\\QueueableActionServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\QueueableAction\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brent Roose", + "email": "brent@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Alex Vanderbist", + "email": "alex@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Sebastian De Deyne", + "email": "sebastian@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Queueable action support in Laravel", + "homepage": "https://github.com/spatie/laravel-queueable-action", + "keywords": [ + "laravel-queueable-action", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-queueable-action/issues", + "source": "https://github.com/spatie/laravel-queueable-action/tree/2.12.0" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + } + ], + "time": "2021-06-01T11:45:12+00:00" + }, { "name": "spatie/laravel-tail", "version": "4.3.3", diff --git a/src/Domain/Folders/Models/Folder.php b/src/Domain/Folders/Models/Folder.php index 6072afd2..082b482c 100644 --- a/src/Domain/Folders/Models/Folder.php +++ b/src/Domain/Folders/Models/Folder.php @@ -121,7 +121,8 @@ class Folder extends Model public function getCreatedAtAttribute(): string { return format_date( - set_time_by_user_timezone($this->attributes['created_at']), __t('time') + set_time_by_user_timezone($this->attributes['created_at']), + __t('time') ); } @@ -135,7 +136,8 @@ class Folder extends Model } return format_date( - set_time_by_user_timezone($this->attributes['deleted_at']), __t('time') + set_time_by_user_timezone($this->attributes['deleted_at']), + __t('time') ); } diff --git a/src/Domain/Sharing/Actions/SendViaEmailAction.php b/src/Domain/Sharing/Actions/SendViaEmailAction.php index 5730e7cb..c147dc53 100644 --- a/src/Domain/Sharing/Actions/SendViaEmailAction.php +++ b/src/Domain/Sharing/Actions/SendViaEmailAction.php @@ -1,20 +1,21 @@ notify( - new SharedSendViaEmail($token) - ); + ->notify(new SharedSendViaEmail($token)); } } } diff --git a/src/Domain/Sharing/Controllers/ShareController.php b/src/Domain/Sharing/Controllers/ShareController.php index 7a7a1092..f645a599 100644 --- a/src/Domain/Sharing/Controllers/ShareController.php +++ b/src/Domain/Sharing/Controllers/ShareController.php @@ -41,9 +41,9 @@ class ShareController extends Controller // Send shared link via email if ($request->has('emails')) { - ($sendLinkToEmailAction)( - $request->input('emails'), - $shared->token + $sendLinkToEmailAction->onQueue()->execute( + emails: $request->input('emails'), + token: $shared->token ); } diff --git a/src/Domain/Sharing/Controllers/ShareViaEmailController.php b/src/Domain/Sharing/Controllers/ShareViaEmailController.php index ea266922..be30d399 100644 --- a/src/Domain/Sharing/Controllers/ShareViaEmailController.php +++ b/src/Domain/Sharing/Controllers/ShareViaEmailController.php @@ -17,7 +17,7 @@ class ShareViaEmailController extends Controller Request $request, string $token, ): Response { - ($this->sendLinkToEmailAction)( + ($this->sendLinkToEmailAction)->onQueue()->execute( emails: $request->input('emails'), token: $token, ); diff --git a/src/Support/helpers.php b/src/Support/helpers.php index b37344aa..1d5ae2dc 100644 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -927,7 +927,7 @@ if (! function_exists('set_time_by_user_timezone')) { /** * Set time by user timezone GMT */ - function set_time_by_user_timezone(string $time): string|Carbon + function set_time_by_user_timezone(string $time): string | Carbon { $user = Auth::user(); diff --git a/tests/App/Users/UserAccountTest.php b/tests/App/Users/UserAccountTest.php index c3cb886d..75680d8a 100644 --- a/tests/App/Users/UserAccountTest.php +++ b/tests/App/Users/UserAccountTest.php @@ -1,11 +1,11 @@ create([ - 'user_id' => $user->id, + 'user_id' => $user->id, 'created_at' => now(), ]); $user->settings()->update([ - 'timezone' => '2.0' + 'timezone' => '2.0', ]); $this ->actingAs($user) - ->getJson("/api/browse/folders/undefined") + ->getJson('/api/browse/folders/undefined') ->assertJsonFragment([ 'created_at' => '01. January. 2021 at 02:00', ]); diff --git a/tests/Domain/Files/FileTest.php b/tests/Domain/Files/FileTest.php index 078786cc..0cd0897e 100644 --- a/tests/Domain/Files/FileTest.php +++ b/tests/Domain/Files/FileTest.php @@ -1,5 +1,4 @@