Skip to content

A free open source IT asset/license management system

Send email if asset has checkin_email set to true

Marcus Moore0bca66b67122
diff --git a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
index 7eef9d69c9..e081d767ee 100644
--- a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
+++ b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
@@ -76,6 +76,10 @@ class CheckoutablesCheckedOutInBulkListener
return true;
}
+ if ($this->hasAssetWithCategorySettingToSendEmail($assets)) {
+ return true;
+ }
+
return $this->requiresAcceptance($assets);
}
@@ -109,6 +113,17 @@ class CheckoutablesCheckedOutInBulkListener
return false;
}
+ private function hasAssetWithCategorySettingToSendEmail(Collection $assets): bool
+ {
+ foreach ($assets as $asset) {
+ if ($asset->checkin_email()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private function requiresAcceptance(Collection $assets): bool
{
return (bool) $assets->reduce(
diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php
index 38df7e58e4..6ebd8e4074 100644
--- a/database/factories/CategoryFactory.php
+++ b/database/factories/CategoryFactory.php
@@ -222,6 +222,13 @@ class CategoryFactory extends Factory
]);
}
+ public function sendsCheckinEmail()
+ {
+ return $this->state([
+ 'checkin_email' => true,
+ ]);
+ }
+
public function hasLocalEula()
{
return $this->state([
@@ -229,4 +236,12 @@ class CategoryFactory extends Factory
'eula_text' => 'Some EULA text here',
]);
}
+
+ public function withNoLocalOrGlobalEula()
+ {
+ return $this->state([
+ 'use_default_eula' => false,
+ 'eula_text' => '',
+ ]);
+ }
}
diff --git a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
index a9647b2e3d..9fc637228d 100644
--- a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
+++ b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
@@ -132,9 +132,29 @@ class BulkCheckoutEmailTest extends TestCase
});
}
- public function test_email_is_sent_when_assets_do_not_require_acceptance_but_category_is_set_to_send_email()
+ public function test_email_is_sent_when_assets_do_not_require_acceptance_or_have_a_eula_but_category_is_set_to_send_email()
{
- $this->markTestIncomplete();
+ $this->assets = Asset::factory()->count(2)->create();
+
+ $category = Category::factory()
+ ->doesNotRequireAcceptance()
+ ->withNoLocalOrGlobalEula()
+ ->sendsCheckinEmail()
+ ->create();
+
+ $this->assets->each(fn($asset) => $asset->model->category()->associate($category)->save());
+
+ $this->sendRequest();
+
+ Mail::assertNotSent(CheckoutAssetMail::class);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, 1);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {
+ return $mail->hasTo($this->target->email)
+ && $mail->assertSeeInText('Assets have been checked out to you')
+ && $mail->assertDontSeeInText('review the terms');
+ });
}
public function test_email_is_sent_to_cc_address()