- share by email fix

This commit is contained in:
Čarodej
2022-03-25 11:10:35 +01:00
parent 8c1e59d81a
commit d7d95e22ea
6 changed files with 17 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
APP_NAME=Laravel APP_NAME=Laravel
APP_ENV=local APP_ENV=local
APP_KEY=base64:YE2Zo20UvRL3LkRLr54PjlayHUCoDEGVICIq76iFZlU= APP_KEY=base64:yMMyV3sJ87ArJwlbTKlr9O2JBr/eB4w3AEKj3Z1SoPM=
APP_DEBUG=true APP_DEBUG=true
APP_URL=http://localhost APP_URL=http://localhost
APP_DEMO=false APP_DEMO=false

View File

@@ -1,6 +1,7 @@
<?php <?php
namespace Domain\Sharing\Actions; namespace Domain\Sharing\Actions;
use App\Users\Models\User;
use Spatie\QueueableAction\QueueableAction; use Spatie\QueueableAction\QueueableAction;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Domain\Sharing\Notifications\SharedSendViaEmail; use Domain\Sharing\Notifications\SharedSendViaEmail;
@@ -12,10 +13,11 @@ class SendViaEmailAction
public function __invoke( public function __invoke(
array $emails, array $emails,
string $token, string $token,
User $user,
): void { ): void {
foreach ($emails as $email) { foreach ($emails as $email) {
Notification::route('mail', $email) Notification::route('mail', $email)
->notify(new SharedSendViaEmail($token)); ->notify(new SharedSendViaEmail($token, $user));
} }
} }
} }

View File

@@ -46,7 +46,8 @@ class ShareController extends Controller
if ($request->has('emails')) { if ($request->has('emails')) {
$sendLinkToEmailAction->onQueue()->execute( $sendLinkToEmailAction->onQueue()->execute(
emails: $request->input('emails'), emails: $request->input('emails'),
token: $shared->token token: $shared->token,
user: $shared->user,
); );
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
namespace Domain\Sharing\Controllers; namespace Domain\Sharing\Controllers;
use Auth;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
@@ -10,8 +11,7 @@ class ShareViaEmailController extends Controller
{ {
public function __construct( public function __construct(
private SendViaEmailAction $sendLinkToEmailAction, private SendViaEmailAction $sendLinkToEmailAction,
) { ) {}
}
public function __invoke( public function __invoke(
Request $request, Request $request,
@@ -20,6 +20,7 @@ class ShareViaEmailController extends Controller
($this->sendLinkToEmailAction)->onQueue()->execute( ($this->sendLinkToEmailAction)->onQueue()->execute(
emails: $request->input('emails'), emails: $request->input('emails'),
token: $token, token: $token,
user: Auth::user(),
); );
return response('Done.', 204); return response('Done.', 204);

View File

@@ -1,8 +1,8 @@
<?php <?php
namespace Domain\Sharing\Notifications; namespace Domain\Sharing\Notifications;
use App\Users\Models\User;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Notifications\Notification; use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\MailMessage;
@@ -12,33 +12,24 @@ class SharedSendViaEmail extends Notification
/** /**
* Create a new notification instance. * Create a new notification instance.
*
* @param $token
*/ */
public function __construct($token) public function __construct(
{ public string $token,
$this->token = $token; public User $user,
$this->user = Auth::user(); ) {}
}
/** /**
* Get the notification's delivery channels. * Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/ */
public function via($notifiable) public function via(mixed $notifiable): array
{ {
return ['mail']; return ['mail'];
} }
/** /**
* Get the mail representation of the notification. * Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/ */
public function toMail($notifiable) public function toMail(mixed $notifiable): MailMessage
{ {
return (new MailMessage) return (new MailMessage)
->subject(__t('shared_link_email_subject', ['user' => $this->user->settings->name])) ->subject(__t('shared_link_email_subject', ['user' => $this->user->settings->name]))
@@ -47,16 +38,4 @@ class SharedSendViaEmail extends Notification
->action(__t('shared_link_email_link'), url('/share', ['token' => $this->token])) ->action(__t('shared_link_email_link'), url('/share', ['token' => $this->token]))
->salutation(__t('shared_link_email_salutation', ['app_name' => get_settings('app_title') ?? 'VueFileManager'])); ->salutation(__t('shared_link_email_salutation', ['app_name' => get_settings('app_title') ?? 'VueFileManager']));
} }
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
];
}
} }

View File

@@ -85,7 +85,7 @@ class SetupWizardTest extends TestCase
]) ])
->assertDatabaseHas('settings', [ ->assertDatabaseHas('settings', [
'name' => 'user_verification', 'name' => 'user_verification',
'value' => 1, 'value' => 0,
]) ])
->assertDatabaseHas('settings', [ ->assertDatabaseHas('settings', [
'name' => 'app_color', 'name' => 'app_color',