Skip to content

A free open source IT asset/license management system

adds a check for category checkin/out emails, also updates our test

Godfrey Mc8b5b3f17673
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index a13b0dd438..2bf93afc94 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -385,9 +385,25 @@ class CheckoutableListener
private function shouldNotSendAnyNotifications($checkoutable): bool
{
- return in_array(get_class($checkoutable), $this->skipNotificationsFor);
+ if(in_array(get_class($checkoutable), $this->skipNotificationsFor)) {
+ return true;
+ }
+ //runs a check if the category wants to send checkin/checkout emails to users
+ $category = match (true) {
+ $checkoutable instanceof Asset => $checkoutable->model->category,
+ $checkoutable instanceof Accessory,
+ $checkoutable instanceof Consumable => $checkoutable->category,
+ $checkoutable instanceof LicenseSeat => $checkoutable->license->category,
+ default => null,
+ };
+
+ if (!$category->checkin_email) {
+ return true;
+ }
+ return false;
}
+
private function shouldSendWebhookNotification(): bool
{
return Setting::getSettings() && Setting::getSettings()->webhook_endpoint;
diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
index 93235789ca..457ff4f861 100644
--- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
+++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
@@ -3,6 +3,9 @@
namespace Tests\Feature\Notifications\Email;
use App\Mail\CheckinAssetMail;
+use App\Models\Accessory;
+use App\Models\Consumable;
+use App\Models\LicenseSeat;
use Illuminate\Support\Facades\Mail;
use PHPUnit\Framework\Attributes\Group;
use App\Events\CheckoutableCheckedIn;
@@ -45,20 +48,49 @@ class EmailNotificationsUponCheckinTest extends TestCase
Mail::fake();
$user = User::factory()->create();
- $asset = Asset::factory()->assignedToUser($user)->create();
-
- $asset->model->category->update([
- 'checkin_email' => false,
- 'eula_text' => null,
- 'require_acceptance' => false,
+ $checkoutables = collect([
+ Asset::factory()->assignedToUser($user)->create(),
+ LicenseSeat::factory()->assignedToUser($user)->create(),
+ Accessory::factory()->checkedOutToUser($user)->create(),
+ Consumable::factory()->checkedOutToUser($user)->create(),
]);
- $this->fireCheckInEvent($asset, $user);
+ foreach ($checkoutables as $checkoutable) {
- Mail::assertNotSent(CheckinAssetMail::class, function($mail) use ($user) {
- return $mail->hasTo($user->email);
+ if ($checkoutable instanceof Asset) {
+ $checkoutable->model->category->update([
+ 'checkin_email' => false,
+ 'eula_text' => null,
+ 'require_acceptance' => false,
+ ]);
+ $checkoutable = $checkoutable->fresh(['model.category']);
+ }
+
+ if ($checkoutable instanceof Accessory || $checkoutable instanceof \App\Models\Consumable) {
+ $checkoutable->category->update([
+ 'checkin_email' => false,
+ 'eula_text' => null,
+ 'require_acceptance' => false,
+ ]);
+ $checkoutable = $checkoutable->fresh(['category']);
}
- );
+
+ if ($checkoutable instanceof LicenseSeat) {
+ $checkoutable->license->category->update([
+ 'checkin_email' => false,
+ 'eula_text' => null,
+ 'require_acceptance' => false,
+ ]);
+ $checkoutable = $checkoutable->fresh(['license.category']);
+ }
+
+ // Fire event manually
+ $this->fireCheckInEvent($checkoutable, $user);
+ }
+
+ Mail::assertNotSent(CheckinAssetMail::class, function ($mail) use ($user) {
+ return $mail->hasTo($user->email);
+ });
}
private function fireCheckInEvent($asset, $user): void