Skip to content

A free open source IT asset/license management system

Moves license checkout stuff to the license seat

Till Deeke6b05106dcbaa
diff --git a/app/Events/LicenseCheckedIn.php b/app/Events/LicenseSeatCheckedIn.php
similarity index 74%
rename from app/Events/LicenseCheckedIn.php
rename to app/Events/LicenseSeatCheckedIn.php
index 36562296b7..80e7ecbaf4 100644
--- a/app/Events/LicenseCheckedIn.php
+++ b/app/Events/LicenseSeatCheckedIn.php
@@ -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;
diff --git a/app/Events/LicenseCheckedOut.php b/app/Events/LicenseSeatCheckedOut.php
similarity index 70%
rename from app/Events/LicenseCheckedOut.php
rename to app/Events/LicenseSeatCheckedOut.php
index a04b20b7bb..6b057be43e 100644
--- a/app/Events/LicenseCheckedOut.php
+++ b/app/Events/LicenseSeatCheckedOut.php
@@ -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;
diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.php
index 1dd8935f68..a1a02c823b 100644
--- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php
+++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php
@@ -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;
}
diff --git a/app/Listeners/SendingCheckInNotificationsListener.php b/app/Listeners/SendingCheckInNotificationsListener.php
index 8a84c42fad..aa176e19fd 100644
--- a/app/Listeners/SendingCheckInNotificationsListener.php
+++ b/app/Listeners/SendingCheckInNotificationsListener.php
@@ -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'
);
}
diff --git a/app/Models/LicenseSeat.php b/app/Models/LicenseSeat.php
index c2abc20ea9..5e387930ec 100755
--- a/app/Models/LicenseSeat.php
+++ b/app/Models/LicenseSeat.php
@@ -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
*
diff --git a/app/Notifications/CheckinLicenseNotification.php b/app/Notifications/CheckinLicenseSeatNotification.php
similarity index 93%
rename from app/Notifications/CheckinLicenseNotification.php
rename to app/Notifications/CheckinLicenseSeatNotification.php
index 3ff06d2ca3..69554d493b 100644
--- a/app/Notifications/CheckinLicenseNotification.php
+++ b/app/Notifications/CheckinLicenseSeatNotification.php
@@ -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();
diff --git a/app/Notifications/CheckoutLicenseNotification.php b/app/Notifications/CheckoutLicenseSeatNotification.php
similarity index 90%
rename from app/Notifications/CheckoutLicenseNotification.php
rename to app/Notifications/CheckoutLicenseSeatNotification.php
index e5c697b2a0..74df6e2f46 100644
--- a/app/Notifications/CheckoutLicenseNotification.php
+++ b/app/Notifications/CheckoutLicenseSeatNotification.php
@@ -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'));
diff --git a/app/Presenters/LicenseSeatPresenter.php b/app/Presenters/LicenseSeatPresenter.php
new file mode 100644
index 0000000000..5267aa7290
--- /dev/null
+++ b/app/Presenters/LicenseSeatPresenter.php
@@ -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;
+ }
+}