Skip to content

A free open source IT asset/license management system

Ensure CC emails are always sent for assets

Marcus Moore5f7aadfba07a
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index 1b1310a7b2..5bb5904f63 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -399,6 +399,10 @@ class CheckoutableListener
private function shouldSendEmailNotifications($checkoutable): bool
{
+ if (Setting::getSettings()->admin_cc_email) {
+ 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,
diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
index 9a40712fb5..cc4fa0be2c 100644
--- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
+++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php
@@ -4,6 +4,8 @@ namespace Tests\Feature\Notifications\Email;
use App\Mail\CheckinAssetMail;
use App\Models\Accessory;
+use App\Models\AssetModel;
+use App\Models\Category;
use App\Models\Consumable;
use App\Models\LicenseSeat;
use Illuminate\Support\Facades\Mail;
@@ -93,7 +95,17 @@ class EmailNotificationsUponCheckinTest extends TestCase
public function testAdminCCEmailStillSentWhenCategoryEmailIsNotSetToSendEmailToUser()
{
- $this->markTestIncomplete();
+ $this->settings->enableAdminCC('[email protected]');
+
+ $category = Category::factory()->create(['checkin_email' => false]);
+ $assetModel = AssetModel::factory()->create(['category_id' => $category->id]);
+ $asset = Asset::factory()->create(['model_id' => $assetModel->id]);
+
+ $this->fireCheckInEvent($asset, User::factory()->create());
+
+ Mail::assertSent(CheckinAssetMail::class, function ($mail) {
+ return $mail->hasTo('[email protected]');
+ });
}
private function fireCheckInEvent($asset, $user): void
diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckoutTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckoutTest.php
index c714a26aec..edeae63658 100644
--- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckoutTest.php
+++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckoutTest.php
@@ -2,14 +2,44 @@
namespace Tests\Feature\Notifications\Email;
+use App\Events\CheckoutableCheckedOut;
+use App\Mail\CheckinAssetMail;
+use App\Mail\CheckoutAssetMail;
+use App\Models\Asset;
+use App\Models\AssetModel;
+use App\Models\Category;
+use App\Models\User;
+use Illuminate\Support\Facades\Mail;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;
#[Group('notifications')]
class EmailNotificationsUponCheckoutTest extends TestCase
{
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ Mail::fake();
+ }
+
public function testAdminCCEmailStillSentWhenCategoryEmailIsNotSetToSendEmailToUser()
{
- $this->markTestIncomplete();
+ $this->settings->enableAdminCC('[email protected]');
+
+ $category = Category::factory()->create(['checkin_email' => false]);
+ $assetModel = AssetModel::factory()->create(['category_id' => $category->id]);
+ $asset = Asset::factory()->create(['model_id' => $assetModel->id]);
+
+ event(new CheckoutableCheckedOut(
+ $asset,
+ User::factory()->create(),
+ User::factory()->superuser()->create(),
+ '',
+ ));
+
+ Mail::assertSent(CheckoutAssetMail::class, function ($mail) {
+ return $mail->hasTo('[email protected]');
+ });
}
}
diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php
index a4c6e65ccc..bcbd83d8b6 100644
--- a/tests/Support/Settings.php
+++ b/tests/Support/Settings.php
@@ -46,6 +46,13 @@ class Settings
]);
}
+ public function enableAdminCC(string $email = '[email protected]'): Settings
+ {
+ return $this->update([
+ 'admin_cc_email' => $email,
+ ]);
+ }
+
public function disableAdminCC(): Settings
{
return $this->update([