mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Moves license checkout stuff to the license seat
Since we are really checking out a license seat instead of the whole license, we operate the checkin/checkout on the license seat instance.
This commit is contained in:
parent
43437aac14
commit
6b05106dcb
|
@ -4,6 +4,7 @@ namespace App\Events;
|
|||
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\License;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
|
@ -13,7 +14,7 @@ class LicenseCheckedIn
|
|||
{
|
||||
use Dispatchable, SerializesModels;
|
||||
|
||||
public $license;
|
||||
public $licenseSeat;
|
||||
public $checkedOutTo;
|
||||
public $checkedInBy;
|
||||
public $note;
|
||||
|
@ -23,9 +24,9 @@ class LicenseCheckedIn
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(License $license, $checkedOutTo, User $checkedInBy, $note)
|
||||
public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedInBy, $note)
|
||||
{
|
||||
$this->license = $license;
|
||||
$this->licenseSeat = $licenseSeat;
|
||||
$this->checkedOutTo = $checkedOutTo;
|
||||
$this->checkedInBy = $checkedInBy;
|
||||
$this->note = $note;
|
|
@ -4,16 +4,17 @@ namespace App\Events;
|
|||
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\License;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class LicenseCheckedOut
|
||||
class LicenseSeatCheckedOut
|
||||
{
|
||||
use Dispatchable, SerializesModels;
|
||||
|
||||
public $license;
|
||||
public $licenseSeat;
|
||||
public $checkedOutTo;
|
||||
public $logEntry;
|
||||
|
||||
|
@ -22,9 +23,9 @@ class LicenseCheckedOut
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(License $license, $checkedOutTo, User $checkedOutBy, $note)
|
||||
public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedOutBy, $note)
|
||||
{
|
||||
$this->license = $license;
|
||||
$this->licenseSeat = $licenseSeat;
|
||||
$this->checkedOutTo = $checkedOutTo;
|
||||
$this->checkedOutBy = $checkedOutBy;
|
||||
$this->note = $note;
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers\Licenses;
|
||||
|
||||
use App\Events\LicenseCheckedOut;
|
||||
use App\Events\LicenseSeatCheckedOut;
|
||||
use App\Http\Requests\LicenseCheckoutRequest;
|
||||
use App\Models\Asset;
|
||||
use App\Models\License;
|
||||
|
@ -105,7 +106,7 @@ class LicenseCheckoutController extends Controller
|
|||
}
|
||||
if ($licenseSeat->save()) {
|
||||
|
||||
event(new LicenseCheckedOut($licenseSeat->license, $target, Auth::user(), request('note')));
|
||||
event(new LicenseSeatCheckedOut($licenseSeat, $target, Auth::user(), request('note')));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -122,7 +123,7 @@ class LicenseCheckoutController extends Controller
|
|||
|
||||
if ($licenseSeat->save()) {
|
||||
|
||||
event(new LicenseCheckedOut($licenseSeat->license, $target, Auth::user(), request('note')));
|
||||
event(new LicenseSeatCheckedOut($licenseSeat, $target, Auth::user(), request('note')));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ class SendingCheckInNotificationsListener
|
|||
/**
|
||||
* Notify the user about the checked in license
|
||||
*/
|
||||
public function onLicenseCheckedIn($event) {
|
||||
public function onLicenseSeatCheckedIn($event) {
|
||||
/**
|
||||
* When the item wasn't checked out to a user, we can't send notifications
|
||||
*/
|
||||
|
@ -63,7 +63,7 @@ class SendingCheckInNotificationsListener
|
|||
|
||||
Notification::send(
|
||||
$this->getNotifiables($event),
|
||||
new CheckinLicenseNotification($event->license, $event->checkedOutTo, $event->checkedInBy, $event->note)
|
||||
new CheckinLicenseSeatNotification($event->licenseSeat, $event->checkedOutTo, $event->checkedInBy, $event->note)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -109,8 +109,8 @@ class SendingCheckInNotificationsListener
|
|||
);
|
||||
|
||||
$events->listen(
|
||||
'App\Events\LicenseCheckedIn',
|
||||
'App\Listeners\SendingCheckInNotificationsListener@onLicenseCheckedIn'
|
||||
'App\Events\LicenseSeatCheckedIn',
|
||||
'App\Listeners\SendingCheckInNotificationsListener@onLicenseSeatCheckedIn'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,17 +2,21 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\Models\Loggable;
|
||||
use App\Notifications\CheckinLicenseNotification;
|
||||
use App\Notifications\CheckoutLicenseNotification;
|
||||
use App\Presenters\Presentable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Notifications\CheckoutLicenseNotification;
|
||||
use App\Notifications\CheckinLicenseNotification;
|
||||
|
||||
class LicenseSeat extends Model implements ICompanyableChild
|
||||
class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||
{
|
||||
use CompanyableChildTrait;
|
||||
use SoftDeletes;
|
||||
use Loggable;
|
||||
|
||||
protected $presenter = 'App\Presenters\LicenseSeatPresenter';
|
||||
use Presentable;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
protected $guarded = 'id';
|
||||
protected $table = 'license_seats';
|
||||
|
@ -22,6 +26,10 @@ class LicenseSeat extends Model implements ICompanyableChild
|
|||
return ['asset', 'license'];
|
||||
}
|
||||
|
||||
public function getEula() {
|
||||
return $this->license->getEula();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the seat -> license relationship
|
||||
*
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Notifications;
|
||||
|
||||
use App\Models\License;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\Setting;
|
||||
use App\Models\SnipeModel;
|
||||
use App\Models\User;
|
||||
|
@ -13,7 +14,7 @@ use Illuminate\Notifications\Messages\SlackMessage;
|
|||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class CheckinLicenseNotification extends Notification
|
||||
class CheckinLicenseSeatNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
/**
|
||||
|
@ -26,10 +27,10 @@ class CheckinLicenseNotification extends Notification
|
|||
*
|
||||
* @param $params
|
||||
*/
|
||||
public function __construct(License $license, $checkedOutTo, User $checkedInBy, $note)
|
||||
public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedInBy, $note)
|
||||
{
|
||||
$this->target = $checkedOutTo;
|
||||
$this->item = $license;
|
||||
$this->item = $licenseSeat->license;
|
||||
$this->admin = $checkedInBy;
|
||||
$this->note = $note;
|
||||
$this->settings = Setting::getSettings();
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Notifications;
|
||||
|
||||
use App\Models\License;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\Setting;
|
||||
use App\Models\SnipeModel;
|
||||
use App\Models\User;
|
||||
|
@ -13,7 +14,7 @@ use Illuminate\Notifications\Messages\SlackMessage;
|
|||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class CheckoutLicenseNotification extends Notification
|
||||
class CheckoutLicenseSeatNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
/**
|
||||
|
@ -26,12 +27,13 @@ class CheckoutLicenseNotification extends Notification
|
|||
*
|
||||
* @param $params
|
||||
*/
|
||||
public function __construct(License $license, $checkedOutTo, User $checkedOutBy, $note)
|
||||
public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
|
||||
{
|
||||
$this->item = $license;
|
||||
$this->item = $licenseSeat->license;
|
||||
$this->admin = $checkedOutBy;
|
||||
$this->note = $note;
|
||||
$this->target = $checkedOutTo;
|
||||
$this->acceptance = $acceptance;
|
||||
|
||||
$this->settings = Setting::getSettings();
|
||||
}
|
||||
|
@ -117,6 +119,8 @@ class CheckoutLicenseNotification extends Notification
|
|||
$eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : '';
|
||||
$req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
|
||||
|
||||
$accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
|
||||
|
||||
return (new MailMessage)->markdown('notifications.markdown.checkout-license',
|
||||
[
|
||||
'item' => $this->item,
|
||||
|
@ -125,7 +129,7 @@ class CheckoutLicenseNotification extends Notification
|
|||
'target' => $this->target,
|
||||
'eula' => $eula,
|
||||
'req_accept' => $req_accept,
|
||||
'accept_url' => route('account.accept.item', ['license', $this->item->id]),
|
||||
'accept_url' => $accept_url,
|
||||
])
|
||||
->subject(trans('mail.Confirm_license_delivery'));
|
||||
|
18
app/Presenters/LicenseSeatPresenter.php
Normal file
18
app/Presenters/LicenseSeatPresenter.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Presenters;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
/**
|
||||
* Class LicensePresenter
|
||||
* @package App\Presenters
|
||||
*/
|
||||
class LicenseSeatPresenter extends Presenter
|
||||
{
|
||||
public function name()
|
||||
{
|
||||
return $this->model->license->name;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue