Merge pull request #5913 from tilldeeke/refactore-checkout-checkin-notification-sending

Refactor: Decouple checkin/checkout notifications from logging
This commit is contained in:
Brady Wetherington
2018-09-21 18:18:27 -07:00
committed by GitHub
41 changed files with 1154 additions and 374 deletions
+20 -19
View File
@@ -1,10 +1,14 @@
<?php
namespace App\Models;
use App\Events\AssetCheckedOut;
use App\Events\CheckoutableCheckedOut;
use App\Exceptions\CheckoutNotAllowed;
use App\Http\Traits\UniqueSerialTrait;
use App\Http\Traits\UniqueUndeletedTrait;
use App\Models\Traits\Acceptable;
use App\Models\Traits\Searchable;
use App\Models\User;
use App\Presenters\Presentable;
use AssetPresenter;
use Auth;
@@ -17,7 +21,6 @@ use Watson\Validating\ValidatingTrait;
use DB;
use App\Notifications\CheckinAssetNotification;
use App\Notifications\CheckoutAssetNotification;
/**
* Model for Assets.
*
@@ -32,12 +35,20 @@ class Asset extends Depreciable
const ASSET = 'asset';
const USER = 'user';
const ACCEPTANCE_PENDING = 'pending';
use Acceptable;
/**
* Set static properties to determine which checkout/checkin handlers we should use
*/
public static $checkoutClass = CheckoutAssetNotification::class;
public static $checkinClass = CheckinAssetNotification::class;
* Run after the checkout acceptance was declined by the user
*
* @param User $acceptedBy
* @param string $signature
*/
public function declinedCheckout(User $declinedBy, $signature) {
$this->assigned_to = null;
$this->assigned_type = null;
$this->accepted = null;
$this->save();
}
/**
@@ -252,21 +263,11 @@ class Asset extends Depreciable
$this->location_id = $target->id;
}
}
/**
* Does the user have to confirm that they accept the asset?
*
* If so, set the acceptance-status to "pending".
* This value is used in the unaccepted assets reports, for example
*
* @see https://github.com/snipe/snipe-it/issues/5772
*/
if ($this->requireAcceptance() && $target instanceof User) {
$this->accepted = self::ACCEPTANCE_PENDING;
}
if ($this->save()) {
$this->logCheckout($note, $target);
event(new CheckoutableCheckedOut($this, $target, Auth::user(), $note));
$this->increment('checkout_counter', 1);
return true;
}