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:
Till Deeke 2018-07-28 12:43:09 +02:00
parent 43437aac14
commit 6b05106dcb
8 changed files with 57 additions and 23 deletions

View file

@ -4,6 +4,7 @@ namespace App\Events;
use App\Models\Actionlog; use App\Models\Actionlog;
use App\Models\License; use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\User; use App\Models\User;
use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\Channel;
use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Foundation\Events\Dispatchable;
@ -13,7 +14,7 @@ class LicenseCheckedIn
{ {
use Dispatchable, SerializesModels; use Dispatchable, SerializesModels;
public $license; public $licenseSeat;
public $checkedOutTo; public $checkedOutTo;
public $checkedInBy; public $checkedInBy;
public $note; public $note;
@ -23,9 +24,9 @@ class LicenseCheckedIn
* *
* @return void * @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->checkedOutTo = $checkedOutTo;
$this->checkedInBy = $checkedInBy; $this->checkedInBy = $checkedInBy;
$this->note = $note; $this->note = $note;

View file

@ -4,16 +4,17 @@ namespace App\Events;
use App\Models\Actionlog; use App\Models\Actionlog;
use App\Models\License; use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\User; use App\Models\User;
use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\Channel;
use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class LicenseCheckedOut class LicenseSeatCheckedOut
{ {
use Dispatchable, SerializesModels; use Dispatchable, SerializesModels;
public $license; public $licenseSeat;
public $checkedOutTo; public $checkedOutTo;
public $logEntry; public $logEntry;
@ -22,9 +23,9 @@ class LicenseCheckedOut
* *
* @return void * @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->checkedOutTo = $checkedOutTo;
$this->checkedOutBy = $checkedOutBy; $this->checkedOutBy = $checkedOutBy;
$this->note = $note; $this->note = $note;

View file

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Licenses; namespace App\Http\Controllers\Licenses;
use App\Events\LicenseCheckedOut; use App\Events\LicenseCheckedOut;
use App\Events\LicenseSeatCheckedOut;
use App\Http\Requests\LicenseCheckoutRequest; use App\Http\Requests\LicenseCheckoutRequest;
use App\Models\Asset; use App\Models\Asset;
use App\Models\License; use App\Models\License;
@ -105,7 +106,7 @@ class LicenseCheckoutController extends Controller
} }
if ($licenseSeat->save()) { if ($licenseSeat->save()) {
event(new LicenseCheckedOut($licenseSeat->license, $target, Auth::user(), request('note'))); event(new LicenseSeatCheckedOut($licenseSeat, $target, Auth::user(), request('note')));
return true; return true;
} }
@ -122,7 +123,7 @@ class LicenseCheckoutController extends Controller
if ($licenseSeat->save()) { if ($licenseSeat->save()) {
event(new LicenseCheckedOut($licenseSeat->license, $target, Auth::user(), request('note'))); event(new LicenseSeatCheckedOut($licenseSeat, $target, Auth::user(), request('note')));
return true; return true;
} }

View file

@ -53,7 +53,7 @@ class SendingCheckInNotificationsListener
/** /**
* Notify the user about the checked in license * 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 * When the item wasn't checked out to a user, we can't send notifications
*/ */
@ -63,7 +63,7 @@ class SendingCheckInNotificationsListener
Notification::send( Notification::send(
$this->getNotifiables($event), $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( $events->listen(
'App\Events\LicenseCheckedIn', 'App\Events\LicenseSeatCheckedIn',
'App\Listeners\SendingCheckInNotificationsListener@onLicenseCheckedIn' 'App\Listeners\SendingCheckInNotificationsListener@onLicenseSeatCheckedIn'
); );
} }

View file

@ -2,17 +2,21 @@
namespace App\Models; namespace App\Models;
use App\Models\Loggable; 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\Model;
use Illuminate\Database\Eloquent\SoftDeletes; 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 CompanyableChildTrait;
use SoftDeletes; use SoftDeletes;
use Loggable; use Loggable;
protected $presenter = 'App\Presenters\LicenseSeatPresenter';
use Presentable;
protected $dates = ['deleted_at']; protected $dates = ['deleted_at'];
protected $guarded = 'id'; protected $guarded = 'id';
protected $table = 'license_seats'; protected $table = 'license_seats';
@ -22,6 +26,10 @@ class LicenseSeat extends Model implements ICompanyableChild
return ['asset', 'license']; return ['asset', 'license'];
} }
public function getEula() {
return $this->license->getEula();
}
/** /**
* Establishes the seat -> license relationship * Establishes the seat -> license relationship
* *

View file

@ -3,6 +3,7 @@
namespace App\Notifications; namespace App\Notifications;
use App\Models\License; use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\Setting; use App\Models\Setting;
use App\Models\SnipeModel; use App\Models\SnipeModel;
use App\Models\User; use App\Models\User;
@ -13,7 +14,7 @@ use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification; use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
class CheckinLicenseNotification extends Notification class CheckinLicenseSeatNotification extends Notification
{ {
use Queueable; use Queueable;
/** /**
@ -26,10 +27,10 @@ class CheckinLicenseNotification extends Notification
* *
* @param $params * @param $params
*/ */
public function __construct(License $license, $checkedOutTo, User $checkedInBy, $note) public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedInBy, $note)
{ {
$this->target = $checkedOutTo; $this->target = $checkedOutTo;
$this->item = $license; $this->item = $licenseSeat->license;
$this->admin = $checkedInBy; $this->admin = $checkedInBy;
$this->note = $note; $this->note = $note;
$this->settings = Setting::getSettings(); $this->settings = Setting::getSettings();

View file

@ -3,6 +3,7 @@
namespace App\Notifications; namespace App\Notifications;
use App\Models\License; use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\Setting; use App\Models\Setting;
use App\Models\SnipeModel; use App\Models\SnipeModel;
use App\Models\User; use App\Models\User;
@ -13,7 +14,7 @@ use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification; use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
class CheckoutLicenseNotification extends Notification class CheckoutLicenseSeatNotification extends Notification
{ {
use Queueable; use Queueable;
/** /**
@ -26,12 +27,13 @@ class CheckoutLicenseNotification extends Notification
* *
* @param $params * @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->admin = $checkedOutBy;
$this->note = $note; $this->note = $note;
$this->target = $checkedOutTo; $this->target = $checkedOutTo;
$this->acceptance = $acceptance;
$this->settings = Setting::getSettings(); $this->settings = Setting::getSettings();
} }
@ -117,6 +119,8 @@ class CheckoutLicenseNotification extends Notification
$eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : ''; $eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : '';
$req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0; $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', return (new MailMessage)->markdown('notifications.markdown.checkout-license',
[ [
'item' => $this->item, 'item' => $this->item,
@ -125,7 +129,7 @@ class CheckoutLicenseNotification extends Notification
'target' => $this->target, 'target' => $this->target,
'eula' => $eula, 'eula' => $eula,
'req_accept' => $req_accept, 'req_accept' => $req_accept,
'accept_url' => route('account.accept.item', ['license', $this->item->id]), 'accept_url' => $accept_url,
]) ])
->subject(trans('mail.Confirm_license_delivery')); ->subject(trans('mail.Confirm_license_delivery'));

View 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;
}
}