Skip to content

A free open source IT asset/license management system

Get licenses working

Marcus Mooreff4819ac6854
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index 5a90f30632..46fbd1589b 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -12,6 +12,7 @@ use App\Mail\CheckoutConsumableMail;
use App\Mail\CheckoutLicenseMail;
use App\Models\Accessory;
use App\Models\Asset;
+use App\Models\Category;
use App\Models\CheckoutAcceptance;
use App\Models\Component;
use App\Models\Consumable;
@@ -236,8 +237,9 @@ class CheckoutableListener
$acceptance->checkoutable()->associate($event->checkoutable);
$acceptance->assignedTo()->associate($event->checkedOutTo);
- // @todo: adjust for other categories
- if (data_get($event, 'checkoutable.model.category.alert_on_response') || data_get($event, 'checkoutable.category.alert_on_response')) {
+ $category = $this->getCategoryFromCheckoutable($event->checkoutable);
+
+ if ($category?->alert_on_response) {
$acceptance->alert_on_response_id = auth()->id();
}
@@ -468,4 +470,14 @@ class CheckoutableListener
return array($to, $cc);
}
+
+ private function getCategoryFromCheckoutable(Model $checkoutable): ?Category
+ {
+ return match (true) {
+ $checkoutable instanceof Asset => $checkoutable->model->category,
+ $checkoutable instanceof Accessory,
+ $checkoutable instanceof Consumable => $checkoutable->category,
+ $checkoutable instanceof LicenseSeat => $checkoutable->license->category,
+ };
+ }
}
diff --git a/tests/Feature/Checkouts/General/SettingAlertOnResponseTest.php b/tests/Feature/Checkouts/General/SettingAlertOnResponseTest.php
index ac6a958104..182d23f87e 100644
--- a/tests/Feature/Checkouts/General/SettingAlertOnResponseTest.php
+++ b/tests/Feature/Checkouts/General/SettingAlertOnResponseTest.php
@@ -4,6 +4,8 @@ namespace Tests\Feature\Checkouts\General;
use App\Models\Accessory;
use App\Models\Asset;
+use App\Models\License;
+use App\Models\LicenseSeat;
use App\Models\Statuslabel;
use App\Models\User;
use Tests\TestCase;
@@ -95,12 +97,40 @@ class SettingAlertOnResponseTest extends TestCase
public function test_sets_alert_on_response_if_enabled_by_category_for_license()
{
- $this->markTestIncomplete();
+ $license = License::factory()->create();
+
+ $license->category->update([
+ 'require_acceptance' => true,
+ 'alert_on_response' => true,
+ ]);
+
+ $this->postLicenseCheckout($license);
+
+ $this->assertDatabaseHas('checkout_acceptances', [
+ 'checkoutable_type' => LicenseSeat::class,
+ 'checkoutable_id' => $license->id,
+ 'assigned_to_id' => $this->assignedUser->id,
+ 'alert_on_response_id' => $this->actor->id,
+ ]);
}
public function test_does_not_set_alert_on_response_if_disabled_by_category_for_license()
{
- $this->markTestIncomplete();
+ $license = License::factory()->create();
+
+ $license->category->update([
+ 'require_acceptance' => true,
+ 'alert_on_response' => false,
+ ]);
+
+ $this->postLicenseCheckout($license);
+
+ $this->assertDatabaseHas('checkout_acceptances', [
+ 'checkoutable_type' => LicenseSeat::class,
+ 'checkoutable_id' => $license->id,
+ 'assigned_to_id' => $this->assignedUser->id,
+ 'alert_on_response_id' => null,
+ ]);
}
private function postAssetCheckout(Asset $asset): void
@@ -123,4 +153,13 @@ class SettingAlertOnResponseTest extends TestCase
'checkout_qty' => 1,
]);
}
+
+ private function postLicenseCheckout(License $license): void
+ {
+ $this->actingAs($this->actor)
+ ->post("/licenses/{$license->id}/checkout/", [
+ 'checkout_to_type' => 'user',
+ 'assigned_to' => $this->assignedUser->id,
+ ]);
+ }
}