From 3f334406d1f3c1c616d285b27582ee06376e90c6 Mon Sep 17 00:00:00 2001 From: Till Deeke Date: Mon, 16 Jul 2018 23:09:04 +0200 Subject: [PATCH] Fixing #5470: Checkin emails not working (#5838) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Always send checkin notifications to users This fixes the routing of the notifications, to only send „checkin“ emails if the „mail on checkin“ flag on the category was set. (and we checkout to a user with a non-empty email) * Fixes checkout notification routing Notifications to users should be send if the category of the resource (accessory/asset/consumable/license): a) requires the user to confirm acceptance b) should send notifications on checkin/checkout * adds a check for EULAs Adds back a check for the EULA, since the user should receive the EULA if it was set (regardless of other setings on the category, etc) --- .../CheckinAccessoryNotification.php | 9 +++-- .../CheckinAssetNotification.php | 8 +++-- .../CheckinLicenseNotification.php | 8 +++-- .../CheckoutAccessoryNotification.php | 33 ++++++++++++++--- .../CheckoutAssetNotification.php | 33 ++++++++++++++--- .../CheckoutConsumableNotification.php | 32 ++++++++++++++--- .../CheckoutLicenseNotification.php | 35 +++++++++++++++---- 7 files changed, 134 insertions(+), 24 deletions(-) diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index 8907dcbde6..052279892e 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -4,6 +4,7 @@ namespace App\Notifications; use App\Models\Setting; use App\Models\SnipeModel; +use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -56,9 +57,13 @@ class CheckinAccessoryNotification extends Notification $notifyBy[] = 'slack'; } - // Make sure the target is a user and that its appropriate to send them an email - if (($this->target_type == \App\Models\User::class) && (($this->item->requireAcceptance() == '1') || ($this->item->getEula()))) + /** + * Only send checkin notifications to users if the category + * has the corresponding checkbox checked. + */ + if ($this->item->checkin_email() && $this->target instanceof User && $this->target->email != '') { + \Log::debug('use email'); $notifyBy[] = 'mail'; } diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 72a950fdcd..78f3f00664 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -4,6 +4,7 @@ namespace App\Notifications; use App\Models\Setting; use Illuminate\Bus\Queueable; +use App\Models\User; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -55,8 +56,11 @@ class CheckinAssetNotification extends Notification $notifyBy[] = 'slack'; } - // Make sure the target is a user and that its appropriate to send them an email - if ((($this->target->email!='') && ($this->target_type == 'App\Models\User')) && (($this->item->requireAcceptance() == '1') || ($this->item->getEula()))) + /** + * Only send checkin notifications to users if the category + * has the corresponding checkbox checked. + */ + if ($this->item->checkin_email() && $this->target instanceof User && $this->target->email != '') { \Log::debug('use email'); $notifyBy[] = 'mail'; diff --git a/app/Notifications/CheckinLicenseNotification.php b/app/Notifications/CheckinLicenseNotification.php index 12212b7c4c..f8a52ccf3c 100644 --- a/app/Notifications/CheckinLicenseNotification.php +++ b/app/Notifications/CheckinLicenseNotification.php @@ -4,6 +4,7 @@ namespace App\Notifications; use App\Models\Setting; use App\Models\SnipeModel; +use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -53,8 +54,11 @@ class CheckinLicenseNotification extends Notification $notifyBy[] = 'slack'; } - - if (($this->target_type == \App\Models\User::class) && (($this->item->requireAcceptance() == '1') || ($this->item->getEula()))) + /** + * Only send checkin notifications to users if the category + * has the corresponding checkbox checked. + */ + if ($this->item->checkin_email() && $this->target instanceof User && $this->target->email != '') { $notifyBy[] = 'mail'; } diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index 1ffb1a1ed4..4e8950619d 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -4,6 +4,7 @@ namespace App\Notifications; use App\Models\Setting; use App\Models\SnipeModel; +use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -59,10 +60,34 @@ class CheckoutAccessoryNotification extends Notification $notifyBy[] = 'slack'; } - // Make sure the target is a user and that its appropriate to send them an email - if ((($this->target->email!='') && ($this->target_type == 'App\Models\User')) && (($this->item->requireAcceptance() == '1') || ($this->item->getEula()))) - { - $notifyBy[] = 'mail'; + + /** + * Only send notifications to users that have email addresses + */ + if ($this->target instanceof User && $this->target->email != '') { + + /** + * Send an email if the asset requires acceptance, + * so the user can accept or decline the asset + */ + if ($this->item->requireAcceptance()) { + $notifyBy[1] = 'mail'; + } + + /** + * Send an email if the item has a EULA, since the user should always receive it + */ + if ($this->item->getEula()) { + $notifyBy[1] = 'mail'; + } + + /** + * Send an email if an email should be sent at checkin/checkout + */ + if ($this->item->checkin_email()) { + $notifyBy[1] = 'mail'; + } + } return $notifyBy; diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 15c9f21987..8451d6dcd9 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -3,6 +3,7 @@ namespace App\Notifications; use App\Models\Setting; +use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; @@ -67,11 +68,35 @@ class CheckoutAssetNotification extends Notification $notifyBy[] = 'slack'; } - // Make sure the target is a user and that its appropriate to send them an email - if (($this->target_type == \App\Models\User::class) && (($this->item->requireAcceptance() == '1') || ($this->item->getEula()))) - { - $notifyBy[] = 'mail'; + /** + * Only send notifications to users that have email addresses + */ + if ($this->target instanceof User && $this->target->email != '') { + + /** + * Send an email if the asset requires acceptance, + * so the user can accept or decline the asset + */ + if ($this->item->requireAcceptance()) { + $notifyBy[1] = 'mail'; + } + + /** + * Send an email if the item has a EULA, since the user should always receive it + */ + if ($this->item->getEula()) { + $notifyBy[1] = 'mail'; + } + + /** + * Send an email if an email should be sent at checkin/checkout + */ + if ($this->item->checkin_email()) { + $notifyBy[1] = 'mail'; + } + } + return $notifyBy; } diff --git a/app/Notifications/CheckoutConsumableNotification.php b/app/Notifications/CheckoutConsumableNotification.php index 2fcc0f67da..ef5ab79e4c 100644 --- a/app/Notifications/CheckoutConsumableNotification.php +++ b/app/Notifications/CheckoutConsumableNotification.php @@ -4,6 +4,7 @@ namespace App\Notifications; use App\Models\Setting; use App\Models\SnipeModel; +use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -56,10 +57,33 @@ class CheckoutConsumableNotification extends Notification $notifyBy[] = 'slack'; } - // Make sure the target is a user and that its appropriate to send them an email - if ((($this->target->email!='') && ($this->target_type == 'App\Models\User')) && (($this->item->requireAcceptance() == '1') || ($this->item->getEula()))) - { - $notifyBy[] = 'mail'; + /** + * Only send notifications to users that have email addresses + */ + if ($this->target instanceof User && $this->target->email != '') { + + /** + * Send an email if the asset requires acceptance, + * so the user can accept or decline the asset + */ + if ($this->item->requireAcceptance()) { + $notifyBy[1] = 'mail'; + } + + /** + * Send an email if the item has a EULA, since the user should always receive it + */ + if ($this->item->getEula()) { + $notifyBy[1] = 'mail'; + } + + /** + * Send an email if an email should be sent at checkin/checkout + */ + if ($this->item->checkin_email()) { + $notifyBy[1] = 'mail'; + } + } return $notifyBy; diff --git a/app/Notifications/CheckoutLicenseNotification.php b/app/Notifications/CheckoutLicenseNotification.php index fe1b202042..93530e2cde 100644 --- a/app/Notifications/CheckoutLicenseNotification.php +++ b/app/Notifications/CheckoutLicenseNotification.php @@ -4,6 +4,7 @@ namespace App\Notifications; use App\Models\Setting; use App\Models\SnipeModel; +use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -57,13 +58,35 @@ class CheckoutLicenseNotification extends Notification $notifyBy[] = 'slack'; } - if (($this->target_type == \App\Models\User::class) && (($this->item->requireAcceptance() == '1') || ($this->item->getEula()))) - { - $notifyBy[] = 'mail'; + /** + * Only send notifications to users that have email addresses + */ + if ($this->target instanceof User && $this->target->email != '') { + + /** + * Send an email if the asset requires acceptance, + * so the user can accept or decline the asset + */ + if ($this->item->requireAcceptance()) { + $notifyBy[1] = 'mail'; + } + + /** + * Send an email if the item has a EULA, since the user should always receive it + */ + if ($this->item->getEula()) { + $notifyBy[1] = 'mail'; + } + + /** + * Send an email if an email should be sent at checkin/checkout + */ + if ($this->item->checkin_email()) { + $notifyBy[1] = 'mail'; + } + } - - - + return $notifyBy; }