Get licenses working

This commit is contained in:
Marcus Moore
2025-06-17 12:34:16 -07:00
parent 58af133853
commit ff4819ac68
2 changed files with 55 additions and 4 deletions

View File

@@ -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,
};
}
}

View File

@@ -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,
]);
}
}