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:
@ -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'] = [
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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
|
||||
*
|
||||
|
||||
@ -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,
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user