Skip to content

A free open source IT asset/license management system

Update introduction line

Marcus Moore4d5b3548d63a
diff --git a/app/Mail/CheckoutAccessoryMail.php b/app/Mail/CheckoutAccessoryMail.php
index f48236d0ae..f92843151d 100644
--- a/app/Mail/CheckoutAccessoryMail.php
+++ b/app/Mail/CheckoutAccessoryMail.php
@@ -91,14 +91,18 @@ class CheckoutAccessoryMail extends BaseMailable
return trans_choice('mail.new_item_checked_location', $this->checkout_qty, ['location' => $this->target->name]);
}
- if ($this->requiresAcceptance()) {
+ if ($this->firstTimeSending && $this->requiresAcceptance()) {
return trans_choice('mail.new_item_checked_with_acceptance', $this->checkout_qty);
}
- if (!$this->requiresAcceptance()) {
+ if ($this->firstTimeSending && !$this->requiresAcceptance()) {
return trans_choice('mail.new_item_checked', $this->checkout_qty);
}
+ if (!$this->firstTimeSending && $this->requiresAcceptance()) {
+ return trans('mail.recent_item_checked');
+ }
+
// we shouldn't get here but let's send a default message just in case
return trans('new_item_checked');
}
diff --git a/app/Mail/CheckoutConsumableMail.php b/app/Mail/CheckoutConsumableMail.php
index 76d0a12145..c679de4a70 100644
--- a/app/Mail/CheckoutConsumableMail.php
+++ b/app/Mail/CheckoutConsumableMail.php
@@ -68,6 +68,7 @@ class CheckoutConsumableMail extends BaseMailable
'req_accept' => $req_accept,
'accept_url' => $accept_url,
'qty' => $this->qty,
+ 'introduction_line' => $this->introductionLine(),
]
);
}
@@ -90,4 +91,27 @@ class CheckoutConsumableMail extends BaseMailable
return trans('mail.unaccepted_asset_reminder');
}
+
+ private function introductionLine()
+ {
+ if ($this->firstTimeSending && $this->requiresAcceptance()) {
+ return trans_choice('mail.new_item_checked_with_acceptance', $this->qty);
+ }
+
+ if ($this->firstTimeSending && !$this->requiresAcceptance()) {
+ return trans_choice('mail.new_item_checked', $this->qty);
+ }
+
+ if (!$this->firstTimeSending && $this->requiresAcceptance()) {
+ return trans('mail.recent_item_checked');
+ }
+
+ // we shouldn't get here but let's send a default message just in case
+ return trans('new_item_checked');
+ }
+
+ private function requiresAcceptance(): int|bool
+ {
+ return method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
+ }
}
diff --git a/app/Mail/CheckoutLicenseMail.php b/app/Mail/CheckoutLicenseMail.php
index 69c439b623..9d9e0fc6e1 100644
--- a/app/Mail/CheckoutLicenseMail.php
+++ b/app/Mail/CheckoutLicenseMail.php
@@ -72,6 +72,7 @@ class CheckoutLicenseMail extends BaseMailable
'eula' => $eula,
'req_accept' => $req_accept,
'accept_url' => $accept_url,
+ 'introduction_line' => $this->introductionLine(),
]
);
}
@@ -94,4 +95,27 @@ class CheckoutLicenseMail extends BaseMailable
return trans('mail.unaccepted_asset_reminder');
}
+
+ private function introductionLine(): string
+ {
+ if ($this->firstTimeSending && $this->requiresAcceptance()) {
+ return trans_choice('mail.new_item_checked_with_acceptance', 1);
+ }
+
+ if ($this->firstTimeSending && !$this->requiresAcceptance()) {
+ return trans_choice('mail.new_item_checked', 1);
+ }
+
+ if (!$this->firstTimeSending && $this->requiresAcceptance()) {
+ return trans('mail.recent_item_checked');
+ }
+
+ // we shouldn't get here but let's send a default message just in case
+ return trans('new_item_checked');
+ }
+
+ private function requiresAcceptance(): int|bool
+ {
+ return method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
+ }
}
diff --git a/database/factories/LicenseSeatFactory.php b/database/factories/LicenseSeatFactory.php
index ee516b6dac..6946a21792 100644
--- a/database/factories/LicenseSeatFactory.php
+++ b/database/factories/LicenseSeatFactory.php
@@ -49,4 +49,11 @@ class LicenseSeatFactory extends Factory
$seat->license->update(['reassignable' => false]);
});
}
+
+ public function requiringAcceptance()
+ {
+ return $this->afterCreating(function ($seat) {
+ $seat->license->category->update(['require_acceptance' => 1]);
+ });
+ }
}
diff --git a/resources/views/mail/markdown/checkout-consumable.blade.php b/resources/views/mail/markdown/checkout-consumable.blade.php
index 1e949700f4..6b3c33c79d 100644
--- a/resources/views/mail/markdown/checkout-consumable.blade.php
+++ b/resources/views/mail/markdown/checkout-consumable.blade.php
@@ -1,7 +1,7 @@
@component('mail::message')
# {{ trans('mail.hello') }} {{ $target->display_name }},
-{{ trans_choice('mail.new_item_checked', $qty) }}
+{{ $introduction_line }}
@component('mail::table')
diff --git a/resources/views/mail/markdown/checkout-license.blade.php b/resources/views/mail/markdown/checkout-license.blade.php
index d3b3fe7de0..4467ad8296 100644
--- a/resources/views/mail/markdown/checkout-license.blade.php
+++ b/resources/views/mail/markdown/checkout-license.blade.php
@@ -1,7 +1,7 @@
@component('mail::message')
# {{ trans('mail.hello').' '.$target.','}}
-{{ trans_choice('mail.new_item_checked', 1) }}
+{{ $introduction_line }}
@component('mail::table')
| | |
diff --git a/tests/Feature/Notifications/Email/AcceptanceReminderTest.php b/tests/Feature/Notifications/Email/AcceptanceReminderTest.php
index f2e4064560..a8845a895c 100644
--- a/tests/Feature/Notifications/Email/AcceptanceReminderTest.php
+++ b/tests/Feature/Notifications/Email/AcceptanceReminderTest.php
@@ -110,7 +110,7 @@ class AcceptanceReminderTest extends TestCase
public function testReminderIsSentToUserForAccessory()
{
- $accessory = Accessory::factory()->create();
+ $accessory = Accessory::factory()->requiringAcceptance()->create();
$acceptance = $this->createCheckoutAcceptance($accessory, $this->assignee);
@@ -137,11 +137,15 @@ class AcceptanceReminderTest extends TestCase
Mail::assertSent(CheckoutAccessoryMail::class, function (CheckoutAccessoryMail $mail) {
return $mail->hasSubject(trans('mail.unaccepted_asset_reminder'));
});
+
+ Mail::assertSent(CheckoutAccessoryMail::class, function (CheckoutAccessoryMail $mail) {
+ return str_contains($mail->render(), trans('mail.recent_item_checked'));
+ });
}
public function testReminderIsSentToUserForAsset()
{
- $asset = Asset::factory()->create();
+ $asset = Asset::factory()->requiresAcceptance()->create();
$acceptance = $this->createCheckoutAcceptance($asset, $this->assignee);
@@ -162,11 +166,15 @@ class AcceptanceReminderTest extends TestCase
Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
return $mail->hasSubject(trans('mail.unaccepted_asset_reminder'));
});
+
+ Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
+ return str_contains($mail->render(), trans('mail.recent_item_checked'));
+ });
}
public function testReminderIsSentToUserForConsumable()
{
- $consumable = Consumable::factory()->create();
+ $consumable = Consumable::factory()->requiringAcceptance()->create();
$acceptance = $this->createCheckoutAcceptance($consumable, $this->assignee);
@@ -187,11 +195,15 @@ class AcceptanceReminderTest extends TestCase
Mail::assertSent(CheckoutConsumableMail::class, function (CheckoutConsumableMail $mail) {
return $mail->hasSubject(trans('mail.unaccepted_asset_reminder'));
});
+
+ Mail::assertSent(CheckoutConsumableMail::class, function (CheckoutConsumableMail $mail) {
+ return str_contains($mail->render(), trans('mail.recent_item_checked'));
+ });
}
public function testReminderIsSentToUserForLicenseSeat()
{
- $licenseSeat = LicenseSeat::factory()->create();
+ $licenseSeat = LicenseSeat::factory()->requiringAcceptance()->create();
$acceptance = $this->createCheckoutAcceptance($licenseSeat, $this->assignee);
@@ -212,6 +224,10 @@ class AcceptanceReminderTest extends TestCase
Mail::assertSent(CheckoutLicenseMail::class, function (CheckoutLicenseMail $mail) {
return $mail->hasSubject(trans('mail.unaccepted_asset_reminder'));
});
+
+ Mail::assertSent(CheckoutLicenseMail::class, function (CheckoutLicenseMail $mail) {
+ return str_contains($mail->render(), trans('mail.recent_item_checked'));
+ });
}
private function createCheckoutAcceptance(Model $item, Model $assignee): CheckoutAcceptance