Skip to content

A free open source IT asset/license management system

Fixing #5470: Checkin emails not working (#5838)

Till Deeke3f334406d1f3
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;
}