Merge remote-tracking branch 'origin/develop'
This commit is contained in:
@@ -650,6 +650,7 @@ class SettingsController extends Controller
|
||||
|
||||
$setting->alert_email = $alert_email;
|
||||
$setting->admin_cc_email = $admin_cc_email;
|
||||
$setting->admin_cc_always = $request->validated('admin_cc_always');
|
||||
$setting->alerts_enabled = $request->input('alerts_enabled', '0');
|
||||
$setting->alert_interval = $request->input('alert_interval');
|
||||
$setting->alert_threshold = $request->input('alert_threshold');
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Requests;
|
||||
use App\Models\Accessory;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreNotificationSettings extends FormRequest
|
||||
{
|
||||
@@ -26,6 +27,9 @@ class StoreNotificationSettings extends FormRequest
|
||||
return [
|
||||
'alert_email' => 'email_array|nullable',
|
||||
'admin_cc_email' => 'email_array|nullable',
|
||||
'admin_cc_always' => [
|
||||
Rule::in('0', '1'),
|
||||
],
|
||||
'alert_threshold' => 'numeric|nullable',
|
||||
'alert_interval' => 'numeric|nullable|gt:0',
|
||||
'audit_warning_days' => 'numeric|nullable',
|
||||
|
||||
@@ -80,7 +80,16 @@ class AssetImporter extends ItemImporter
|
||||
$asset_tag = Asset::autoincrement_asset();
|
||||
}
|
||||
|
||||
$asset = Asset::where(['asset_tag'=> (string) $asset_tag])->first();
|
||||
|
||||
|
||||
if ($this->findCsvMatch($row, 'id')!='') {
|
||||
// Override asset if an ID was given
|
||||
\Log::debug('Finding asset by ID: '.$this->findCsvMatch($row, 'id'));
|
||||
$asset = Asset::find($this->findCsvMatch($row, 'id'));
|
||||
} else {
|
||||
$asset = Asset::where(['asset_tag'=> (string) $asset_tag])->first();
|
||||
}
|
||||
|
||||
if ($asset) {
|
||||
if (! $this->updating) {
|
||||
$exists_error = trans('general.import_asset_tag_exists', ['asset_tag' => $asset_tag]);
|
||||
|
||||
@@ -69,16 +69,16 @@ class CheckoutableListener
|
||||
return;
|
||||
}
|
||||
|
||||
$acceptance = $this->getCheckoutAcceptance($event);
|
||||
|
||||
$shouldSendEmailToUser = $this->shouldSendCheckoutEmailToUser($event->checkoutable);
|
||||
$shouldSendEmailToAlertAddress = $this->shouldSendEmailToAlertAddress();
|
||||
$shouldSendEmailToAlertAddress = $this->shouldSendEmailToAlertAddress($acceptance);
|
||||
$shouldSendWebhookNotification = $this->shouldSendWebhookNotification();
|
||||
|
||||
if (!$shouldSendEmailToUser && !$shouldSendEmailToAlertAddress && !$shouldSendWebhookNotification) {
|
||||
return;
|
||||
}
|
||||
|
||||
$acceptance = $this->getCheckoutAcceptance($event);
|
||||
|
||||
if ($shouldSendEmailToUser || $shouldSendEmailToAlertAddress) {
|
||||
$mailable = $this->getCheckoutMailType($event, $acceptance);
|
||||
$notifiable = $this->getNotifiableUser($event);
|
||||
@@ -419,9 +419,19 @@ class CheckoutableListener
|
||||
return false;
|
||||
}
|
||||
|
||||
private function shouldSendEmailToAlertAddress(): bool
|
||||
private function shouldSendEmailToAlertAddress($acceptance = null): bool
|
||||
{
|
||||
return Setting::getSettings() && Setting::getSettings()->admin_cc_email;
|
||||
$setting = Setting::getSettings();
|
||||
|
||||
if (!$setting) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null($acceptance) && !$setting->admin_cc_always) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $setting->admin_cc_email;
|
||||
}
|
||||
|
||||
private function getFormattedAlertAddresses(): array
|
||||
|
||||
@@ -203,6 +203,7 @@ class Importer extends Component
|
||||
];
|
||||
|
||||
$this->assets_fields = [
|
||||
'id' => trans('general.id'),
|
||||
'asset_eol_date' => trans('admin/hardware/form.eol_date'),
|
||||
'asset_model' => trans('general.model_name'),
|
||||
'asset_notes' => trans('general.item_notes', ['item' => trans('admin/hardware/general.asset')]),
|
||||
|
||||
@@ -122,9 +122,9 @@ class Asset extends Depreciable
|
||||
'assigned_to' => ['nullable', 'integer', 'required_with:assigned_type'],
|
||||
'assigned_type' => ['nullable', 'required_with:assigned_to', 'in:'.User::class.",".Location::class.",".Asset::class],
|
||||
'requestable' => ['nullable', 'boolean'],
|
||||
'assigned_user' => ['nullable', 'exists:users,id,deleted_at,NULL'],
|
||||
'assigned_location' => ['nullable', 'exists:locations,id,deleted_at,NULL', 'fmcs_location'],
|
||||
'assigned_asset' => ['nullable', 'exists:assets,id,deleted_at,NULL']
|
||||
'assigned_user' => ['integer', 'nullable', 'exists:users,id,deleted_at,NULL'],
|
||||
'assigned_location' => ['integer', 'nullable', 'exists:locations,id,deleted_at,NULL', 'fmcs_location'],
|
||||
'assigned_asset' => ['integer', 'nullable', 'exists:assets,id,deleted_at,NULL']
|
||||
];
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->boolean('admin_cc_always')->after('admin_cc_email')->default(1);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->dropColumn('admin_cc_always');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -9,6 +9,7 @@ return [
|
||||
'bulk_checkin' => 'Bulk Checkin',
|
||||
'checkin' => 'Checkin Asset',
|
||||
'checkout' => 'Checkout Asset',
|
||||
'clear' => 'Clear',
|
||||
'clone' => 'Clone Asset',
|
||||
'deployable' => 'Deployable',
|
||||
'deleted' => 'This asset has been deleted.',
|
||||
|
||||
@@ -9,6 +9,8 @@ return [
|
||||
'ad_append_domain_help' => 'User isn\'t required to write "username@domain.local", they can just type "username".',
|
||||
'admin_cc_email' => 'CC Email',
|
||||
'admin_cc_email_help' => 'Send a copy of checkin/checkout emails to this address.',
|
||||
'admin_cc_always' => 'Always send copy upon checkin/checkout',
|
||||
'admin_cc_when_acceptance_required' => 'Only send copy upon checkout if acceptance is required',
|
||||
'admin_settings' => 'Admin Settings',
|
||||
'is_ad' => 'This is an Active Directory server',
|
||||
'alerts' => 'Alerts',
|
||||
|
||||
@@ -266,3 +266,16 @@
|
||||
</div> <!--/.col-md-8-->
|
||||
</div>
|
||||
@stop
|
||||
@section('moar_scripts')
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.querySelectorAll('.clear-radio').forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
const name = this.dataset.targetName;
|
||||
const radios = document.querySelectorAll('input[type="radio"][name="' + name + '"]');
|
||||
radios.forEach(radio => radio.checked = false);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
@@ -35,9 +35,9 @@
|
||||
@if($field->is_unique)
|
||||
<input type="text" class="form-control" disabled value="{{ trans('/admin/hardware/form.bulk_update_custom_field_unique') }}">
|
||||
@endif
|
||||
@if(!$field->is_unique)
|
||||
@if(!$field->is_unique)
|
||||
<textarea class="col-md-6 form-control" id="{{ $field->db_column_name() }}" name="{{ $field->db_column_name() }}">{{ old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))) }}</textarea>
|
||||
@endif
|
||||
@endif
|
||||
@elseif ($field->element=='checkbox')
|
||||
<!-- Checkboxes -->
|
||||
@foreach ($field->formatFieldValuesAsArray() as $key => $value)
|
||||
@@ -56,7 +56,11 @@
|
||||
</label>
|
||||
|
||||
@endforeach
|
||||
|
||||
<button type="button"
|
||||
class="btn btn-default btn-xs clear-radio"
|
||||
data-target-name="{{ $field->db_column_name() }}">
|
||||
{{ trans('/admin/hardware/general.clear') }}
|
||||
</button>
|
||||
@endif
|
||||
|
||||
@else
|
||||
@@ -119,4 +123,4 @@
|
||||
</div>
|
||||
@endforeach
|
||||
@endif
|
||||
@endforeach
|
||||
@endforeach
|
||||
|
||||
@@ -96,8 +96,28 @@
|
||||
<input type="email" name="admin_cc_email" value="{{ old('admin_cc_email', $setting->admin_cc_email) }}" class="form-control" placeholder="admin@yourcompany.com" maxlength="191">
|
||||
{!! $errors->first('admin_cc_email', '<span class="alert-msg" aria-hidden="true">:message</span><br>') !!}
|
||||
<p class="help-block">{{ trans('admin/settings/general.admin_cc_email_help') }}</p>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<label class="form-control">
|
||||
<input
|
||||
type="radio"
|
||||
name="admin_cc_always"
|
||||
value="1"
|
||||
@checked($setting->admin_cc_always == 1)
|
||||
>
|
||||
{{ trans('admin/settings/general.admin_cc_always') }}
|
||||
</label>
|
||||
<label class="form-control">
|
||||
<input
|
||||
type="radio"
|
||||
name="admin_cc_always"
|
||||
value="0"
|
||||
@checked($setting->admin_cc_always == 0)
|
||||
>
|
||||
{{ trans('admin/settings/general.admin_cc_when_acceptance_required') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Models\Supplier;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StoreAssetTest extends TestCase
|
||||
@@ -572,6 +573,64 @@ class StoreAssetTest extends TestCase
|
||||
$this->assertTrue($asset->assignedTo->is($userAssigned));
|
||||
}
|
||||
|
||||
public static function checkoutTargets()
|
||||
{
|
||||
yield 'Users' => [
|
||||
function () {
|
||||
return [
|
||||
'key' => 'assigned_user',
|
||||
'value' => [
|
||||
User::factory()->create()->id,
|
||||
User::factory()->create()->id,
|
||||
],
|
||||
];
|
||||
},
|
||||
];
|
||||
|
||||
yield 'Locations' => [
|
||||
function () {
|
||||
return [
|
||||
'key' => 'assigned_location',
|
||||
'value' => [
|
||||
Location::factory()->create()->id,
|
||||
Location::factory()->create()->id,
|
||||
],
|
||||
];
|
||||
},
|
||||
];
|
||||
|
||||
yield 'Assets' => [
|
||||
function () {
|
||||
return [
|
||||
'key' => 'assigned_asset',
|
||||
'value' => [
|
||||
Asset::factory()->create()->id,
|
||||
Asset::factory()->create()->id,
|
||||
],
|
||||
];
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** @link https://app.shortcut.com/grokability/story/29181 */
|
||||
#[DataProvider('checkoutTargets')]
|
||||
public function testAssignedFieldValidationCannotBeArray($data)
|
||||
{
|
||||
['key' => $key, 'value' => $value] = $data();
|
||||
|
||||
$this->actingAsForApi(User::factory()->createAssets()->create())
|
||||
->postJson(route('api.assets.store'), [
|
||||
'asset_tag' => '123456',
|
||||
'model_id' => AssetModel::factory()->create()->id,
|
||||
'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id,
|
||||
$key => $value,
|
||||
])
|
||||
->assertStatusMessageIs('error')
|
||||
->assertJson(function (AssertableJson $json) use ($key) {
|
||||
$json->has("messages.{$key}")->etc();
|
||||
});
|
||||
}
|
||||
|
||||
public function testAnAssetCanBeCheckedOutToLocationOnStore()
|
||||
{
|
||||
$model = AssetModel::factory()->create();
|
||||
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Notifications\Email;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Mail\CheckinAssetMail;
|
||||
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 EmailNotificationsToAdminAlertEmailUponCheckinTest extends TestCase
|
||||
{
|
||||
private Asset $asset;
|
||||
private AssetModel $assetModel;
|
||||
private Category $category;
|
||||
private User $user;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Mail::fake();
|
||||
|
||||
$this->user = User::factory()->create();
|
||||
|
||||
$this->category = Category::factory()->create([
|
||||
'checkin_email' => false,
|
||||
'eula_text' => null,
|
||||
'require_acceptance' => false,
|
||||
'use_default_eula' => false,
|
||||
]);
|
||||
|
||||
$this->assetModel = AssetModel::factory()->for($this->category)->create();
|
||||
|
||||
$this->asset = Asset::factory()
|
||||
->for($this->assetModel, 'model')
|
||||
->assignedToUser($this->user)
|
||||
->create();
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_sends()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$this->category->update(['checkin_email' => true]);
|
||||
|
||||
$this->fireCheckInEvent($this->asset, $this->user);
|
||||
|
||||
Mail::assertSent(CheckinAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo($this->user->email) && $mail->hasCc('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_still_sent_when_category_email_is_not_set_to_send_email_to_user()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$this->category->update(['checkin_email' => false]);
|
||||
|
||||
$this->fireCheckInEvent($this->asset, $this->user);
|
||||
|
||||
Mail::assertSent(CheckinAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_still_sent_when_user_has_no_email_address()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$this->user->update(['email' => null]);
|
||||
|
||||
$this->category->update(['checkin_email' => true]);
|
||||
|
||||
$this->fireCheckInEvent($this->asset, $this->user);
|
||||
|
||||
Mail::assertSent(CheckinAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_sent_when_always_send_is_true_and_asset_does_not_require_acceptance()
|
||||
{
|
||||
$this->settings
|
||||
->enableAdminCC('cc@example.com')
|
||||
->enableAdminCCAlways();
|
||||
|
||||
$this->category->update(['checkin_email' => false]);
|
||||
|
||||
$this->fireCheckInEvent($this->asset, $this->user);
|
||||
|
||||
Mail::assertSent(CheckinAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com') || $mail->hasCc('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_not_sent_when_always_send_is_false_and_asset_does_not_require_acceptance()
|
||||
{
|
||||
$this->settings
|
||||
->enableAdminCC('cc@example.com')
|
||||
->disableAdminCCAlways();
|
||||
|
||||
$this->category->update(['checkin_email' => false]);
|
||||
|
||||
$this->fireCheckInEvent($this->asset, $this->user);
|
||||
|
||||
Mail::assertNotSent(CheckinAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com') || $mail->hasCc('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
private function fireCheckInEvent($asset, $user): void
|
||||
{
|
||||
event(new CheckoutableCheckedIn(
|
||||
$asset,
|
||||
$user,
|
||||
User::factory()->checkinAssets()->create(),
|
||||
''
|
||||
));
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Notifications\Email;
|
||||
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
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 EmailNotificationsToAdminAlertEmailUponCheckoutTest extends TestCase
|
||||
{
|
||||
private Asset $asset;
|
||||
private AssetModel $assetModel;
|
||||
private Category $category;
|
||||
private User $user;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Mail::fake();
|
||||
|
||||
$this->category = Category::factory()->create([
|
||||
'checkin_email' => false,
|
||||
'eula_text' => null,
|
||||
'require_acceptance' => false,
|
||||
'use_default_eula' => false,
|
||||
]);
|
||||
|
||||
$this->assetModel = AssetModel::factory()->for($this->category)->create();
|
||||
$this->asset = Asset::factory()->for($this->assetModel, 'model')->create();
|
||||
|
||||
$this->user = User::factory()->create();
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_sends()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$this->category->update(['checkin_email' => true]);
|
||||
|
||||
$this->fireCheckoutEvent();
|
||||
|
||||
Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
|
||||
return $mail->hasCc('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_still_sent_when_category_is_not_set_to_send_email_to_user()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$this->fireCheckoutEvent();
|
||||
|
||||
Mail::assertSent(CheckoutAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_still_sent_when_user_has_no_email_address()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$this->category->update(['checkin_email' => true]);
|
||||
$this->user->update(['email' => null]);
|
||||
|
||||
$this->fireCheckoutEvent();
|
||||
|
||||
Mail::assertSent(CheckoutAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_sent_when_always_send_is_true_and_asset_does_not_require_acceptance()
|
||||
{
|
||||
$this->settings
|
||||
->enableAdminCC('cc@example.com')
|
||||
->enableAdminCCAlways();
|
||||
|
||||
$this->category->update(['checkin_email' => false]);
|
||||
|
||||
$this->fireCheckoutEvent();
|
||||
|
||||
Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
|
||||
return $mail->hasTo('cc@example.com') || $mail->hasCc('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_not_sent_when_always_send_is_false_and_asset_does_not_require_acceptance()
|
||||
{
|
||||
$this->settings
|
||||
->enableAdminCC('cc@example.com')
|
||||
->disableAdminCCAlways();
|
||||
|
||||
$this->category->update(['checkin_email' => false]);
|
||||
|
||||
$this->fireCheckoutEvent();
|
||||
|
||||
Mail::assertNotSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
|
||||
return $mail->hasTo('cc@example.com') || $mail->hasCc('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
private function fireCheckoutEvent(): void
|
||||
{
|
||||
event(new CheckoutableCheckedOut(
|
||||
$this->asset,
|
||||
$this->user,
|
||||
User::factory()->superuser()->create(),
|
||||
'',
|
||||
));
|
||||
}
|
||||
}
|
||||
+1
-54
@@ -4,8 +4,6 @@ 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;
|
||||
@@ -16,7 +14,7 @@ use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
#[Group('notifications')]
|
||||
class EmailNotificationsUponCheckinTest extends TestCase
|
||||
class EmailNotificationsToUserUponCheckinTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
@@ -101,57 +99,6 @@ class EmailNotificationsUponCheckinTest extends TestCase
|
||||
Mail::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_sends()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$user = User::factory()->create();
|
||||
$asset = Asset::factory()->assignedToUser($user)->create();
|
||||
|
||||
$asset->model->category->update(['checkin_email' => true]);
|
||||
|
||||
$this->fireCheckInEvent($asset, $user);
|
||||
|
||||
Mail::assertSent(CheckinAssetMail::class, function ($mail) use ($user) {
|
||||
return $mail->hasTo($user->email) && $mail->hasCc('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_still_sent_when_category_email_is_not_set_to_send_email_to_user()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$category = Category::factory()->create([
|
||||
'checkin_email' => false,
|
||||
'eula_text' => null,
|
||||
'use_default_eula' => 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('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_still_sent_when_user_has_no_email_address()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$user = User::factory()->create(['email' => null]);
|
||||
$asset = Asset::factory()->assignedToUser($user)->create();
|
||||
|
||||
$asset->model->category->update(['checkin_email' => true]);
|
||||
|
||||
$this->fireCheckInEvent($asset, $user);
|
||||
|
||||
Mail::assertSent(CheckinAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
private function fireCheckInEvent($asset, $user): void
|
||||
{
|
||||
event(new CheckoutableCheckedIn(
|
||||
+1
-39
@@ -13,7 +13,7 @@ use PHPUnit\Framework\Attributes\Group;
|
||||
use Tests\TestCase;
|
||||
|
||||
#[Group('notifications')]
|
||||
class EmailNotificationsUponCheckoutTest extends TestCase
|
||||
class EmailNotificationsToUserUponCheckoutTest extends TestCase
|
||||
{
|
||||
private Asset $asset;
|
||||
private AssetModel $assetModel;
|
||||
@@ -87,44 +87,6 @@ class EmailNotificationsUponCheckoutTest extends TestCase
|
||||
Mail::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_sends()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$this->category->update(['checkin_email' => true]);
|
||||
|
||||
$this->fireCheckoutEvent();
|
||||
|
||||
Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
|
||||
return $mail->hasCc('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_still_sent_when_category_is_not_set_to_send_email_to_user()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$this->fireCheckoutEvent();
|
||||
|
||||
Mail::assertSent(CheckoutAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_alert_email_still_sent_when_user_has_no_email_address()
|
||||
{
|
||||
$this->settings->enableAdminCC('cc@example.com');
|
||||
|
||||
$this->category->update(['checkin_email' => true]);
|
||||
$this->user->update(['email' => null]);
|
||||
|
||||
$this->fireCheckoutEvent();
|
||||
|
||||
Mail::assertSent(CheckoutAssetMail::class, function ($mail) {
|
||||
return $mail->hasTo('cc@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
private function fireCheckoutEvent(): void
|
||||
{
|
||||
event(new CheckoutableCheckedOut(
|
||||
@@ -18,7 +18,10 @@ class AlertsSettingTest extends TestCase
|
||||
public function testAdminCCEmailArrayCanBeSaved()
|
||||
{
|
||||
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||
->post(route('settings.alerts.save', ['alert_email' => 'me@example.com,you@example.com']))
|
||||
->post(route('settings.alerts.save', [
|
||||
'alert_email' => 'me@example.com,you@example.com',
|
||||
'admin_cc_always' => '1',
|
||||
]))
|
||||
->assertStatus(302)
|
||||
->assertValid('alert_email')
|
||||
->assertRedirect(route('settings.index'))
|
||||
@@ -26,4 +29,23 @@ class AlertsSettingTest extends TestCase
|
||||
$this->followRedirects($response)->assertSee('alert-success');
|
||||
}
|
||||
|
||||
public function test_can_update_admin_cc_always_to_true()
|
||||
{
|
||||
$this->settings->disableAdminCCAlways();
|
||||
|
||||
$this->actingAs(User::factory()->superuser()->create())
|
||||
->post(route('settings.alerts.save', ['admin_cc_always' => '1']));
|
||||
|
||||
$this->assertDatabaseHas('settings', ['admin_cc_always' => '1']);
|
||||
}
|
||||
|
||||
public function test_can_update_admin_cc_always_to_false()
|
||||
{
|
||||
$this->settings->enableAdminCC()->enableAdminCCAlways();
|
||||
|
||||
$this->actingAs(User::factory()->superuser()->create())
|
||||
->post(route('settings.alerts.save', ['admin_cc_always' => '0']));
|
||||
|
||||
$this->assertDatabaseHas('settings', ['admin_cc_always' => '0']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ class AssetsImportFileBuilder extends FileBuilder
|
||||
protected function getDictionary(): array
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'assigneeFullName' => 'Full Name',
|
||||
'assigneeEmail' => 'Email',
|
||||
'assigneeUsername' => 'Username',
|
||||
@@ -69,6 +70,7 @@ class AssetsImportFileBuilder extends FileBuilder
|
||||
$faker = fake();
|
||||
|
||||
return [
|
||||
'asset_tag' => Str::random(),
|
||||
'assigneeFullName' => $faker->name,
|
||||
'assigneeEmail' => $faker->email,
|
||||
'assigneeUsername' => $faker->userName,
|
||||
|
||||
@@ -60,6 +60,20 @@ class Settings
|
||||
]);
|
||||
}
|
||||
|
||||
public function enableAdminCCAlways(): Settings
|
||||
{
|
||||
return $this->update([
|
||||
'admin_cc_always' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
public function disableAdminCCAlways(): Settings
|
||||
{
|
||||
return $this->update([
|
||||
'admin_cc_always' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function enableMultipleFullCompanySupport(): Settings
|
||||
{
|
||||
return $this->update(['full_multiple_companies_support' => 1]);
|
||||
|
||||
Reference in New Issue
Block a user