Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved wording in asset checkout emails #16446

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion app/Mail/CheckoutAssetMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function content(): Content
{
$this->item->load('assetstatus');
$eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : '';
$req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
$req_accept = $this->requiresAcceptance();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want to change this? I think this was there for checkout to location, other assets, etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snipe Double-check me but the old line is pulled as is into the private method so I can call it repeatedly in the introductionLine() method.

$fields = [];

// Check if the item has custom fields associated with it
Expand All @@ -98,6 +98,7 @@ public function content(): Content
'accept_url' => $accept_url,
'last_checkout' => $this->last_checkout,
'expected_checkin' => $this->expected_checkin,
'introduction_line' => $this->introductionLine(),
],
);
}
Expand All @@ -120,4 +121,27 @@ private function getSubject(): string

return trans('mail.unaccepted_asset_reminder');
}

private function introductionLine(): string
{
if ($this->firstTimeSending && $this->requiresAcceptance()) {
return trans('mail.new_item_checked_with_acceptance');
}

if ($this->firstTimeSending && !$this->requiresAcceptance()) {
return trans('mail.new_item_checked');
}

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;
}
}
10 changes: 10 additions & 0 deletions database/factories/AssetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Asset;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\CustomField;
use App\Models\Location;
use App\Models\Statuslabel;
Expand Down Expand Up @@ -333,6 +334,15 @@ public function requiresAcceptance()
});
}

public function doesNotRequireAcceptance()
{
return $this->state(function () {
return [
'model_id' => AssetModel::factory()->doesNotRequireAcceptance(),
];
});
}

public function deleted()
{
return $this->state(function () {
Expand Down
9 changes: 9 additions & 0 deletions database/factories/AssetModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,13 @@ public function hasMultipleCustomFields(array $fields = null)
];
});
}

public function doesNotRequireAcceptance()
{
return $this->state(function () {
return [
'category_id' => Category::factory()->doesNotRequireAcceptance(),
];
});
}
}
7 changes: 7 additions & 0 deletions database/factories/CategoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,11 @@ public function forConsumables()
'category_type' => 'consumable',
]);
}

public function doesNotRequireAcceptance()
{
return $this->state([
'require_acceptance' => false,
]);
}
}
4 changes: 3 additions & 1 deletion resources/lang/en-US/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
'min_QTY' => 'Min QTY',
'name' => 'Name',
'new_item_checked' => 'A new item has been checked out under your name, details are below.',
'new_item_checked_with_acceptance' => 'A new item has been checked out under your name that requires acceptance, details are below.',
'recent_item_checked' => 'An item was recently checked out under your name that requires acceptance, details are below.',
'notes' => 'Notes',
'password' => 'Password',
'password_reset' => 'Password Reset',
Expand All @@ -88,7 +90,7 @@
'upcoming-audits' => 'There is :count asset that is coming up for audit within :threshold days.|There are :count assets that are coming up for audit within :threshold days.',
'user' => 'User',
'username' => 'Username',
'unaccepted_asset_reminder' => 'You have Unaccepted Assets.',
'unaccepted_asset_reminder' => 'Reminder: You have Unaccepted Assets.',
'welcome' => 'Welcome :name',
'welcome_to' => 'Welcome to :web!',
'your_assets' => 'View Your Assets',
Expand Down
4 changes: 2 additions & 2 deletions resources/views/mail/markdown/checkout-asset.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@component('mail::message')
# {{ trans('mail.hello') }} {{ $target->present()->fullName() }},

{{ trans('mail.new_item_checked') }}
{{ $introduction_line }}

@if (($snipeSettings->show_images_in_email =='1') && $item->getImageUrl())
<center><img src="{{ $item->getImageUrl() }}" alt="Asset" style="max-width: 570px;"></center>
Expand Down Expand Up @@ -76,4 +76,4 @@

{{ $snipeSettings->site_name }}

@endcomponent
@endcomponent
75 changes: 75 additions & 0 deletions tests/Unit/Mail/CheckoutAssetMailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Tests\Unit\Mail;

use App\Mail\CheckoutAssetMail;
use App\Models\Asset;
use App\Models\CheckoutAcceptance;
use App\Models\User;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;

class CheckoutAssetMailTest extends TestCase
{
public static function data()
{
yield 'Asset requiring acceptance' => [
function () {
$asset = Asset::factory()->requiresAcceptance()->create();
return [
'asset' => $asset,
'acceptance' => CheckoutAcceptance::factory()->for($asset, 'checkoutable')->create(),
'first_time_sending' => true,
'expected_subject' => 'Asset checked out',
'expected_opening' => 'A new item has been checked out under your name that requires acceptance, details are below.'
];
}
];

yield 'Asset not requiring acceptance' => [
function () {
return [
'asset' => Asset::factory()->doesNotRequireAcceptance()->create(),
'acceptance' => null,
'first_time_sending' => true,
'expected_subject' => 'Asset checked out',
'expected_opening' => 'A new item has been checked out under your name, details are below.'
];
}
];

yield 'Reminder' => [
function () {
return [
'asset' => Asset::factory()->requiresAcceptance()->create(),
'acceptance' => CheckoutAcceptance::factory()->create(),
'first_time_sending' => false,
'expected_subject' => 'Reminder: You have Unaccepted Assets.',
'expected_opening' => 'An item was recently checked out under your name that requires acceptance, details are below.'
];
}
];
}

#[DataProvider('data')]
public function testSubjectLineAndOpening($data)
{
[
'asset' => $asset,
'acceptance' => $acceptance,
'first_time_sending' => $firstTimeSending,
'expected_subject' => $expectedSubject,
'expected_opening' => $expectedOpening,
] = $data();

(new CheckoutAssetMail(
$asset,
User::factory()->create(),
User::factory()->create(),
$acceptance,
'A note goes here',
$firstTimeSending,
))->assertHasSubject($expectedSubject)
->assertSeeInText($expectedOpening);
}
}
Loading