3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-05 01:45:48 +00:00

disallows checkout of expired or terminated licenses

This commit is contained in:
Godfrey M
2025-09-10 12:08:14 -07:00
parent a66bb95a81
commit e796c0da4a
4 changed files with 16 additions and 4 deletions

View File

@ -51,7 +51,7 @@ class LicenseSeatsTransformer
'reassignable' => (bool) $seat->license->reassignable,
'notes' => e($seat->notes),
'user_can_checkout' => (($seat->assigned_to == '') && ($seat->asset_id == '')),
'disabled' => $seat->unreassignable_seat,
'disabled' => $seat->unreassignable_seat || $seat->license->isInactive(),
];
$permissions_array['available_actions'] = [

View File

@ -54,11 +54,11 @@ class LicensesTransformer
'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),
'deleted_at' => Helper::getFormattedDateObject($license->deleted_at, 'datetime'),
'user_can_checkout' => (bool) ($license->free_seats_count > 0),
'disabled' => $license->isInactive(),
];
$permissions_array['available_actions'] = [
'checkout' => Gate::allows('checkout', License::class),
'checkout' => Gate::allows('checkout', $license),
'checkin' => Gate::allows('checkin', License::class),
'clone' => Gate::allows('create', License::class),
'update' => Gate::allows('update', License::class),

View File

@ -296,6 +296,18 @@ class License extends Depreciable
}
$this->attributes['termination_date'] = $value;
}
public function isInactive(): bool
{
$day = now()->startOfDay();
$expired = $this->expiration_date && $this->asDateTime($this->expiration_date)->startofDay()->lessThanOrEqualTo($day);
$terminated = $this->termination_date && $this->asDateTime($this->termination_date)->startofDay()->lessThanOrEqualTo($day);
return $expired || $terminated;
}
/**
* Sets free_seat_count attribute
*

View File

@ -202,7 +202,7 @@ class LicensePresenter extends Presenter
'switchable' => false,
'title' => trans('general.checkin').'/'.trans('general.checkout'),
'visible' => true,
'formatter' => 'licensesInOutFormatter',
'formatter' => 'licenseSeatInOutFormatter',
'printIgnore' => true,
];