added email notification about fulfilling upload request

This commit is contained in:
Čarodej
2022-02-24 10:43:35 +01:00
parent a589ee5f7a
commit 45dcdcce16
6 changed files with 82 additions and 4 deletions

View File

@@ -42,7 +42,7 @@ const actions = {
resolve(response)
// Stop loading spinner
if (response.data.data.attributes.status === 'active')
if (['active', 'filled', 'expired'].includes(response.data.data.attributes.status) )
commit('LOADING_STATE', { loading: false, data: [] })
commit('SET_UPLOAD_REQUEST', response.data)

View File

@@ -194,11 +194,14 @@ export default {
isFolder() {
return this.item && this.item.data.type === 'folder'
},
userName() {
return this.uploadRequest.data.relationships.user.data.attributes.name
},
emptyPageTitle() {
// Todo: add name into translation
return {
active: this.$t('{name} Request You for File Upload', {name: this.uploadRequest.data.relationships.user.data.attributes.name}),
filled: this.$t('Upload Request for {name} was Fulfilled Successfully', {name: this.uploadRequest.data.relationships.user.data.attributes.name}),
active: this.$t('{name} Request You for File Upload', {name: this.userName}),
filled: this.$t('Upload Request for {name} was Fulfilled Successfully', {name: this.userName}),
expired: this.$t('Upload Request Expired'),
}[this.uploadRequest.data.attributes.status]
},
@@ -218,7 +221,7 @@ export default {
methods: {
uploadingDone() {
events.$emit('confirm:open', {
title: this.$t('Are you sure you uploaded all files you want for {name}?', {name: this.uploadRequest.data.relationships.user.data.attributes.name}),
title: this.$t('Are you sure you uploaded all files you want for {name}?', {name: this.userName}),
message: this.$t("You won't be able to upload any files here once again."),
action: {
id: this.$router.currentRoute.params.token,

View File

@@ -1,6 +1,7 @@
<?php
namespace Domain\UploadRequest\Controllers;
use Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification;
use Illuminate\Http\Response;
use Domain\UploadRequest\Models\UploadRequest;
use Illuminate\Contracts\Foundation\Application;
@@ -15,6 +16,9 @@ class SetUploadRequestAsFilledController
'status' => 'filled',
]);
// Send user notification
$uploadRequest->user->notify(new UploadRequestFulfilledNotification($uploadRequest));
return response(new UploadRequestResource($uploadRequest), 201);
}
}

View File

@@ -49,6 +49,11 @@ class UploadRequest extends Model
return $this->hasOne(Folder::class, 'id', 'id');
}
public function parent(): HasOne
{
return $this->hasOne(Folder::class, 'id', 'folder_id');
}
protected static function boot()
{
parent::boot();

View File

@@ -0,0 +1,63 @@
<?php
namespace Domain\UploadRequest\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Domain\UploadRequest\Models\UploadRequest;
use Illuminate\Notifications\Messages\MailMessage;
class UploadRequestFulfilledNotification extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(
public UploadRequest $uploadRequest
) {
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
// TODO: add to language strings
return (new MailMessage)
->subject("Your file request was fulfilled in your '{$this->uploadRequest->parent->name}' folder")
->greeting('Hello')
->line("We are emailing you because your file request was fulfilled. Please click on the link below to show uploaded files.")
->action('Show Files', url("/platform/files/{$this->uploadRequest->id}"))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
];
}
}

View File

@@ -1,6 +1,7 @@
<?php
namespace Tests\Domain\UploadRequest;
use Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification;
use Storage;
use Notification;
use Tests\TestCase;
@@ -194,6 +195,8 @@ class UploadRequestTest extends TestCase
'id' => $uploadRequest->id,
'status' => 'filled',
]);
Notification::assertSentTo($user, UploadRequestFulfilledNotification::class);
}
/**