mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
12cc576b52
|
@ -2889,6 +2889,24 @@
|
|||
"avatar_url": "https://avatars.githubusercontent.com/u/570639?v=4",
|
||||
"profile": "https://github.com/Mezzle",
|
||||
"contributions": []
|
||||
},
|
||||
{
|
||||
"login": "dboth",
|
||||
"name": "dboth",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/5731963?v=4",
|
||||
"profile": "http://dboth.de",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "zacharyfleck",
|
||||
"name": "Zachary Fleck",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/87536651?v=4",
|
||||
"profile": "https://github.com/zacharyfleck",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
![Build Status](https://app.chipperci.com/projects/0e5f8979-31eb-4ee6-9abf-050b76ab0383/status/master) [![Crowdin](https://d322cqt584bo4o.cloudfront.net/snipe-it/localized.svg)](https://crowdin.com/project/snipe-it) [![Docker Pulls](https://img.shields.io/docker/pulls/snipe/snipe-it.svg)](https://hub.docker.com/r/snipe/snipe-it/) [![Twitter Follow](https://img.shields.io/twitter/follow/snipeitapp.svg?style=social)](https://twitter.com/snipeitapp) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/553ce52037fc43ea99149785afcfe641)](https://www.codacy.com/app/snipe/snipe-it?utm_source=github.com&utm_medium=referral&utm_content=snipe/snipe-it&utm_campaign=Badge_Grade)
|
||||
[![All Contributors](https://img.shields.io/badge/all_contributors-318-orange.svg?style=flat-square)](#contributors) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/yZFtShAcKk) [![huntr](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev)
|
||||
[![All Contributors](https://img.shields.io/badge/all_contributors-320-orange.svg?style=flat-square)](#contributors) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/yZFtShAcKk) [![huntr](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev)
|
||||
|
||||
## Snipe-IT - Open Source Asset Management System
|
||||
|
||||
|
@ -144,7 +144,7 @@ Thanks goes to all of these wonderful people ([emoji key](https://github.com/ken
|
|||
| [<img src="https://avatars.githubusercontent.com/u/32363424?v=4" width="110px;"/><br /><sub>Peace</sub>](https://github.com/julian-piehl)<br />[💻](https://github.com/snipe/snipe-it/commits?author=julian-piehl "Code") | [<img src="https://avatars.githubusercontent.com/u/231528?v=4" width="110px;"/><br /><sub>Kyle Gordon</sub>](https://github.com/kylegordon)<br />[💻](https://github.com/snipe/snipe-it/commits?author=kylegordon "Code") | [<img src="https://avatars.githubusercontent.com/u/53009155?v=4" width="110px;"/><br /><sub>Katharina Drexel</sub>](http://www.bfh.ch)<br />[💻](https://github.com/snipe/snipe-it/commits?author=sunflowerbofh "Code") | [<img src="https://avatars.githubusercontent.com/u/1931963?v=4" width="110px;"/><br /><sub>David Sferruzza</sub>](https://david.sferruzza.fr/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=dsferruzza "Code") | [<img src="https://avatars.githubusercontent.com/u/19511639?v=4" width="110px;"/><br /><sub>Rick Nelson</sub>](https://github.com/rnelsonee)<br />[💻](https://github.com/snipe/snipe-it/commits?author=rnelsonee "Code") | [<img src="https://avatars.githubusercontent.com/u/94169344?v=4" width="110px;"/><br /><sub>BasO12</sub>](https://github.com/BasO12)<br />[💻](https://github.com/snipe/snipe-it/commits?author=BasO12 "Code") | [<img src="https://avatars.githubusercontent.com/u/111710123?v=4" width="110px;"/><br /><sub>Vautia</sub>](https://github.com/Vautia)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Vautia "Code") |
|
||||
| [<img src="https://avatars.githubusercontent.com/u/28321?v=4" width="110px;"/><br /><sub>Chris Hartjes</sub>](http://www.littlehart.net/atthekeyboard)<br />[💻](https://github.com/snipe/snipe-it/commits?author=chartjes "Code") | [<img src="https://avatars.githubusercontent.com/u/2404584?v=4" width="110px;"/><br /><sub>geo-chen</sub>](https://github.com/geo-chen)<br />[💻](https://github.com/snipe/snipe-it/commits?author=geo-chen "Code") | [<img src="https://avatars.githubusercontent.com/u/6006620?v=4" width="110px;"/><br /><sub>Phan Nguyen</sub>](https://github.com/nh314)<br />[💻](https://github.com/snipe/snipe-it/commits?author=nh314 "Code") | [<img src="https://avatars.githubusercontent.com/u/115993812?v=4" width="110px;"/><br /><sub>Iisakki Jaakkola</sub>](https://github.com/StarlessNights)<br />[💻](https://github.com/snipe/snipe-it/commits?author=StarlessNights "Code") | [<img src="https://avatars.githubusercontent.com/u/22633385?v=4" width="110px;"/><br /><sub>Ikko Ashimine</sub>](https://bandism.net/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=eltociear "Code") | [<img src="https://avatars.githubusercontent.com/u/56871540?v=4" width="110px;"/><br /><sub>Lukas Fehling</sub>](https://github.com/lukasfehling)<br />[💻](https://github.com/snipe/snipe-it/commits?author=lukasfehling "Code") | [<img src="https://avatars.githubusercontent.com/u/1975990?v=4" width="110px;"/><br /><sub>Fernando Almeida</sub>](https://github.com/fernando-almeida)<br />[💻](https://github.com/snipe/snipe-it/commits?author=fernando-almeida "Code") |
|
||||
| [<img src="https://avatars.githubusercontent.com/u/116301219?v=4" width="110px;"/><br /><sub>akemidx</sub>](https://github.com/akemidx)<br />[💻](https://github.com/snipe/snipe-it/commits?author=akemidx "Code") | [<img src="https://avatars.githubusercontent.com/u/144778?v=4" width="110px;"/><br /><sub>Oguz Bilgic</sub>](http://oguz.site)<br />[💻](https://github.com/snipe/snipe-it/commits?author=oguzbilgic "Code") | [<img src="https://avatars.githubusercontent.com/u/9262438?v=4" width="110px;"/><br /><sub>Scooter Crawford</sub>](https://github.com/scoo73r)<br />[💻](https://github.com/snipe/snipe-it/commits?author=scoo73r "Code") | [<img src="https://avatars.githubusercontent.com/u/5957345?v=4" width="110px;"/><br /><sub>subdriven</sub>](https://github.com/subdriven)<br />[💻](https://github.com/snipe/snipe-it/commits?author=subdriven "Code") | [<img src="https://avatars.githubusercontent.com/u/658865?v=4" width="110px;"/><br /><sub>Andrew Savinykh</sub>](https://github.com/AndrewSav)<br />[💻](https://github.com/snipe/snipe-it/commits?author=AndrewSav "Code") | [<img src="https://avatars.githubusercontent.com/u/1155067?v=4" width="110px;"/><br /><sub>Tadayuki Onishi</sub>](https://kenchan0130.github.io)<br />[💻](https://github.com/snipe/snipe-it/commits?author=kenchan0130 "Code") | [<img src="https://avatars.githubusercontent.com/u/112496896?v=4" width="110px;"/><br /><sub>Florian</sub>](https://github.com/floschoepfer)<br />[💻](https://github.com/snipe/snipe-it/commits?author=floschoepfer "Code") |
|
||||
| [<img src="https://avatars.githubusercontent.com/u/7305753?v=4" width="110px;"/><br /><sub>Spencer Long</sub>](http://spencerlong.com)<br />[💻](https://github.com/snipe/snipe-it/commits?author=spencerrlongg "Code") | [<img src="https://avatars.githubusercontent.com/u/1141514?v=4" width="110px;"/><br /><sub>Marcus Moore</sub>](https://github.com/marcusmoore)<br />[💻](https://github.com/snipe/snipe-it/commits?author=marcusmoore "Code") | [<img src="https://avatars.githubusercontent.com/u/570639?v=4" width="110px;"/><br /><sub>Martin Meredith</sub>](https://github.com/Mezzle)<br /> |
|
||||
| [<img src="https://avatars.githubusercontent.com/u/7305753?v=4" width="110px;"/><br /><sub>Spencer Long</sub>](http://spencerlong.com)<br />[💻](https://github.com/snipe/snipe-it/commits?author=spencerrlongg "Code") | [<img src="https://avatars.githubusercontent.com/u/1141514?v=4" width="110px;"/><br /><sub>Marcus Moore</sub>](https://github.com/marcusmoore)<br />[💻](https://github.com/snipe/snipe-it/commits?author=marcusmoore "Code") | [<img src="https://avatars.githubusercontent.com/u/570639?v=4" width="110px;"/><br /><sub>Martin Meredith</sub>](https://github.com/Mezzle)<br /> | [<img src="https://avatars.githubusercontent.com/u/5731963?v=4" width="110px;"/><br /><sub>dboth</sub>](http://dboth.de)<br />[💻](https://github.com/snipe/snipe-it/commits?author=dboth "Code") | [<img src="https://avatars.githubusercontent.com/u/87536651?v=4" width="110px;"/><br /><sub>Zachary Fleck</sub>](https://github.com/zacharyfleck)<br />[💻](https://github.com/snipe/snipe-it/commits?author=zacharyfleck "Code") |
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
|
||||
|
|
|
@ -56,7 +56,7 @@ class CheckoutLicenseToAllUsers extends Command
|
|||
return false;
|
||||
}
|
||||
|
||||
$users = User::whereNull('deleted_at')->where('autoassign_licenses', '==', 1)->with('licenses')->get();
|
||||
$users = User::whereNull('deleted_at')->where('autoassign_licenses', '=', 1)->with('licenses')->get();
|
||||
|
||||
if ($users->count() > $license->getAvailSeatsCountAttribute()) {
|
||||
$this->info('You do not have enough free seats to complete this task, so we will check out as many as we can. ');
|
||||
|
|
|
@ -77,7 +77,7 @@ class AccessoriesController extends Controller
|
|||
$accessory->manufacturer_id = request('manufacturer_id');
|
||||
$accessory->model_number = request('model_number');
|
||||
$accessory->purchase_date = request('purchase_date');
|
||||
$accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost'));
|
||||
$accessory->purchase_cost = request('purchase_cost');
|
||||
$accessory->qty = request('qty');
|
||||
$accessory->user_id = Auth::user()->id;
|
||||
$accessory->supplier_id = request('supplier_id');
|
||||
|
@ -180,7 +180,7 @@ class AccessoriesController extends Controller
|
|||
$accessory->order_number = request('order_number');
|
||||
$accessory->model_number = request('model_number');
|
||||
$accessory->purchase_date = request('purchase_date');
|
||||
$accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost'));
|
||||
$accessory->purchase_cost = request('purchase_cost');
|
||||
$accessory->qty = request('qty');
|
||||
$accessory->supplier_id = request('supplier_id');
|
||||
$accessory->notes = request('notes');
|
||||
|
|
|
@ -118,7 +118,7 @@ class AssetMaintenancesController extends Controller
|
|||
$assetMaintenance = new AssetMaintenance();
|
||||
$assetMaintenance->supplier_id = $request->input('supplier_id');
|
||||
$assetMaintenance->is_warranty = $request->input('is_warranty');
|
||||
$assetMaintenance->cost = Helper::ParseCurrency($request->input('cost'));
|
||||
$assetMaintenance->cost = $request->input('cost');
|
||||
$assetMaintenance->notes = e($request->input('notes'));
|
||||
$asset = Asset::find(e($request->input('asset_id')));
|
||||
|
||||
|
@ -175,7 +175,7 @@ class AssetMaintenancesController extends Controller
|
|||
|
||||
$assetMaintenance->supplier_id = e($request->input('supplier_id'));
|
||||
$assetMaintenance->is_warranty = e($request->input('is_warranty'));
|
||||
$assetMaintenance->cost = Helper::ParseCurrency($request->input('cost'));
|
||||
$assetMaintenance->cost = $request->input('cost');
|
||||
$assetMaintenance->notes = e($request->input('notes'));
|
||||
|
||||
$asset = Asset::find(request('asset_id'));
|
||||
|
|
|
@ -550,7 +550,8 @@ class AssetsController extends Controller
|
|||
$asset->depreciate = '0';
|
||||
$asset->status_id = $request->get('status_id', 0);
|
||||
$asset->warranty_months = $request->get('warranty_months', null);
|
||||
$asset->purchase_cost = Helper::ParseCurrency($request->get('purchase_cost')); // this is the API's store method, so I don't know that I want to do this? Confusing. FIXME (or not?!)
|
||||
$asset->purchase_cost = $request->get('purchase_cost');
|
||||
$asset->asset_eol_date = $request->get('asset_eol_date', $asset->present()->eol_date());
|
||||
$asset->purchase_date = $request->get('purchase_date', null);
|
||||
$asset->assigned_to = $request->get('assigned_to', null);
|
||||
$asset->supplier_id = $request->get('supplier_id');
|
||||
|
@ -558,6 +559,7 @@ class AssetsController extends Controller
|
|||
$asset->rtd_location_id = $request->get('rtd_location_id', null);
|
||||
$asset->location_id = $request->get('rtd_location_id', null);
|
||||
|
||||
|
||||
/**
|
||||
* this is here just legacy reasons. Api\AssetController
|
||||
* used image_source once to allow encoded image uploads.
|
||||
|
|
|
@ -101,7 +101,7 @@ class AssetMaintenancesController extends Controller
|
|||
$assetMaintenance = new AssetMaintenance();
|
||||
$assetMaintenance->supplier_id = $request->input('supplier_id');
|
||||
$assetMaintenance->is_warranty = $request->input('is_warranty');
|
||||
$assetMaintenance->cost = Helper::ParseCurrency($request->input('cost'));
|
||||
$assetMaintenance->cost = $request->input('cost');
|
||||
$assetMaintenance->notes = $request->input('notes');
|
||||
$asset = Asset::find($request->input('asset_id'));
|
||||
|
||||
|
@ -211,7 +211,7 @@ class AssetMaintenancesController extends Controller
|
|||
|
||||
$assetMaintenance->supplier_id = $request->input('supplier_id');
|
||||
$assetMaintenance->is_warranty = $request->input('is_warranty');
|
||||
$assetMaintenance->cost = Helper::ParseCurrency($request->input('cost'));
|
||||
$assetMaintenance->cost = $request->input('cost');
|
||||
$assetMaintenance->notes = $request->input('notes');
|
||||
|
||||
$asset = Asset::find(request('asset_id'));
|
||||
|
|
|
@ -140,9 +140,9 @@ class AssetsController extends Controller
|
|||
$asset->depreciate = '0';
|
||||
$asset->status_id = request('status_id');
|
||||
$asset->warranty_months = request('warranty_months', null);
|
||||
$asset->purchase_cost = Helper::ParseCurrency($request->get('purchase_cost'));
|
||||
$asset->purchase_cost = request('purchase_cost');
|
||||
$asset->purchase_date = request('purchase_date', null);
|
||||
$asset->asset_eol_date = request('asset_eol_date', null);
|
||||
$asset->asset_eol_date = request('asset_eol_date', $asset->present()->eol_date());
|
||||
$asset->assigned_to = request('assigned_to', null);
|
||||
$asset->supplier_id = request('supplier_id', null);
|
||||
$asset->requestable = request('requestable', 0);
|
||||
|
@ -312,7 +312,7 @@ class AssetsController extends Controller
|
|||
|
||||
$asset->status_id = $request->input('status_id', null);
|
||||
$asset->warranty_months = $request->input('warranty_months', null);
|
||||
$asset->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost', null));
|
||||
$asset->purchase_cost = $request->input('purchase_cost', null);
|
||||
$asset->asset_eol_date = request('asset_eol_date', null);
|
||||
|
||||
$asset->purchase_date = $request->input('purchase_date', null);
|
||||
|
|
|
@ -149,7 +149,7 @@ class BulkAssetsController extends Controller
|
|||
}
|
||||
|
||||
if ($request->filled('purchase_cost')) {
|
||||
$this->update_array['purchase_cost'] = Helper::ParseCurrency($request->input('purchase_cost'));
|
||||
$this->update_array['purchase_cost'] = $request->input('purchase_cost');
|
||||
}
|
||||
|
||||
if ($request->filled('company_id')) {
|
||||
|
|
|
@ -78,7 +78,7 @@ class ComponentsController extends Controller
|
|||
$component->min_amt = $request->input('min_amt', null);
|
||||
$component->serial = $request->input('serial', null);
|
||||
$component->purchase_date = $request->input('purchase_date', null);
|
||||
$component->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost', null));
|
||||
$component->purchase_cost = $request->input('purchase_cost', null);
|
||||
$component->qty = $request->input('qty');
|
||||
$component->user_id = Auth::id();
|
||||
$component->notes = $request->input('notes');
|
||||
|
@ -153,7 +153,7 @@ class ComponentsController extends Controller
|
|||
$component->min_amt = $request->input('min_amt');
|
||||
$component->serial = $request->input('serial');
|
||||
$component->purchase_date = $request->input('purchase_date');
|
||||
$component->purchase_cost = Helper::ParseCurrency(request('purchase_cost'));
|
||||
$component->purchase_cost = request('purchase_cost');
|
||||
$component->qty = $request->input('qty');
|
||||
$component->notes = $request->input('notes');
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ class ConsumablesController extends Controller
|
|||
$consumable->model_number = $request->input('model_number');
|
||||
$consumable->item_no = $request->input('item_no');
|
||||
$consumable->purchase_date = $request->input('purchase_date');
|
||||
$consumable->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost'));
|
||||
$consumable->purchase_cost = $request->input('purchase_cost');
|
||||
$consumable->qty = $request->input('qty');
|
||||
$consumable->user_id = Auth::id();
|
||||
$consumable->notes = $request->input('notes');
|
||||
|
@ -154,7 +154,7 @@ class ConsumablesController extends Controller
|
|||
$consumable->model_number = $request->input('model_number');
|
||||
$consumable->item_no = $request->input('item_no');
|
||||
$consumable->purchase_date = $request->input('purchase_date');
|
||||
$consumable->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost'));
|
||||
$consumable->purchase_cost = $request->input('purchase_cost');
|
||||
$consumable->qty = Helper::ParseFloat($request->input('qty'));
|
||||
$consumable->notes = $request->input('notes');
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ class LicensesController extends Controller
|
|||
$license->name = $request->input('name');
|
||||
$license->notes = $request->input('notes');
|
||||
$license->order_number = $request->input('order_number');
|
||||
$license->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost'));
|
||||
$license->purchase_cost = $request->input('purchase_cost');
|
||||
$license->purchase_date = $request->input('purchase_date');
|
||||
$license->purchase_order = $request->input('purchase_order');
|
||||
$license->purchase_order = $request->input('purchase_order');
|
||||
|
@ -166,7 +166,7 @@ class LicensesController extends Controller
|
|||
$license->name = $request->input('name');
|
||||
$license->notes = $request->input('notes');
|
||||
$license->order_number = $request->input('order_number');
|
||||
$license->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost'));
|
||||
$license->purchase_cost = $request->input('purchase_cost');
|
||||
$license->purchase_date = $request->input('purchase_date');
|
||||
$license->purchase_order = $request->input('purchase_order');
|
||||
$license->reassignable = $request->input('reassignable', 0);
|
||||
|
|
|
@ -2,22 +2,21 @@
|
|||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Asset;
|
||||
use App\Models\CheckoutAcceptance;
|
||||
use App\Models\Component;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\Recipients\AdminRecipient;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckinAccessoryNotification;
|
||||
use App\Notifications\CheckinAssetNotification;
|
||||
use App\Notifications\CheckinLicenseNotification;
|
||||
use App\Notifications\CheckinLicenseSeatNotification;
|
||||
use App\Notifications\CheckoutAccessoryNotification;
|
||||
use App\Notifications\CheckoutAssetNotification;
|
||||
use App\Notifications\CheckoutConsumableNotification;
|
||||
use App\Notifications\CheckoutLicenseNotification;
|
||||
use App\Notifications\CheckoutLicenseSeatNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Exception;
|
||||
|
@ -25,18 +24,17 @@ use Log;
|
|||
|
||||
class CheckoutableListener
|
||||
{
|
||||
private array $skipNotificationsFor = [
|
||||
Component::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Notify the user about the checked out checkoutable and add a record to the
|
||||
* checkout_requests table.
|
||||
* Notify the user and post to webhook about the checked out checkoutable
|
||||
* and add a record to the checkout_requests table.
|
||||
*/
|
||||
public function onCheckedOut($event)
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* When the item wasn't checked out to a user, we can't send notifications
|
||||
*/
|
||||
if (! $event->checkedOutTo instanceof User) {
|
||||
if ($this->shouldNotSendAnyNotifications($event->checkoutable)){
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -46,6 +44,11 @@ class CheckoutableListener
|
|||
$acceptance = $this->getCheckoutAcceptance($event);
|
||||
|
||||
try {
|
||||
if ($this->shouldSendWebhookNotification()) {
|
||||
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
||||
->notify($this->getCheckoutNotification($event));
|
||||
}
|
||||
|
||||
if (! $event->checkedOutTo->locale) {
|
||||
Notification::locale(Setting::getSettings()->locale)->send(
|
||||
$this->getNotifiables($event),
|
||||
|
@ -63,16 +66,13 @@ class CheckoutableListener
|
|||
}
|
||||
|
||||
/**
|
||||
* Notify the user about the checked in checkoutable
|
||||
* Notify the user and post to webhook about the checked in checkoutable
|
||||
*/
|
||||
public function onCheckedIn($event)
|
||||
{
|
||||
\Log::debug('onCheckedIn in the Checkoutable listener fired');
|
||||
|
||||
/**
|
||||
* When the item wasn't checked out to a user, we can't send notifications
|
||||
*/
|
||||
if (! $event->checkedOutTo instanceof User) {
|
||||
if ($this->shouldNotSendAnyNotifications($event->checkoutable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,11 @@ class CheckoutableListener
|
|||
}
|
||||
|
||||
try {
|
||||
if ($this->shouldSendWebhookNotification()) {
|
||||
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
||||
->notify($this->getCheckinNotification($event));
|
||||
}
|
||||
|
||||
// Use default locale
|
||||
if (! $event->checkedOutTo->locale) {
|
||||
Notification::locale(Setting::getSettings()->locale)->send(
|
||||
|
@ -182,11 +187,11 @@ class CheckoutableListener
|
|||
/**
|
||||
* Get the appropriate notification for the event
|
||||
*
|
||||
* @param CheckoutableCheckedIn $event
|
||||
* @param CheckoutAcceptance $acceptance
|
||||
* @param CheckoutableCheckedOut $event
|
||||
* @param CheckoutAcceptance|null $acceptance
|
||||
* @return Notification
|
||||
*/
|
||||
private function getCheckoutNotification($event, $acceptance)
|
||||
private function getCheckoutNotification($event, $acceptance = null)
|
||||
{
|
||||
$notificationClass = null;
|
||||
|
||||
|
@ -225,4 +230,14 @@ class CheckoutableListener
|
|||
'App\Listeners\CheckoutableListener@onCheckedOut'
|
||||
);
|
||||
}
|
||||
|
||||
private function shouldNotSendAnyNotifications($checkoutable): bool
|
||||
{
|
||||
return in_array(get_class($checkoutable), $this->skipNotificationsFor);
|
||||
}
|
||||
|
||||
private function shouldSendWebhookNotification(): bool
|
||||
{
|
||||
return Setting::getSettings() && Setting::getSettings()->webhook_endpoint;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,8 +95,8 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
|||
*/
|
||||
public function setCostAttribute($value)
|
||||
{
|
||||
$value = Helper::ParseFloat($value);
|
||||
if ($value == '0.0') {
|
||||
$value = Helper::ParseCurrency($value);
|
||||
if ($value == 0) {
|
||||
$value = null;
|
||||
}
|
||||
$this->attributes['cost'] = $value;
|
||||
|
|
|
@ -6,13 +6,15 @@ use App\Models\Traits\Acceptable;
|
|||
use App\Notifications\CheckinLicenseNotification;
|
||||
use App\Notifications\CheckoutLicenseNotification;
|
||||
use App\Presenters\Presentable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||
{
|
||||
use CompanyableChildTrait;
|
||||
use SoftDeletes;
|
||||
use HasFactory;
|
||||
use Loggable;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $presenter = \App\Presenters\LicenseSeatPresenter::class;
|
||||
use Presentable;
|
||||
|
|
|
@ -21,9 +21,9 @@ class SnipeModel extends Model
|
|||
*/
|
||||
public function setPurchaseCostAttribute($value)
|
||||
{
|
||||
$value = Helper::ParseFloat($value);
|
||||
$value = Helper::ParseCurrency($value);
|
||||
|
||||
if ($value == '0.0') {
|
||||
if ($value == 0) {
|
||||
$value = null;
|
||||
}
|
||||
$this->attributes['purchase_cost'] = $value;
|
||||
|
|
|
@ -259,20 +259,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
|||
return $this->last_name.', '.$this->first_name.' ('.$this->username.')';
|
||||
}
|
||||
|
||||
/**
|
||||
* The url for slack notifications.
|
||||
* Used by Notifiable trait.
|
||||
* @return mixed
|
||||
*/
|
||||
public function routeNotificationForSlack()
|
||||
{
|
||||
// At this point the endpoint is the same for everything.
|
||||
// In the future this may want to be adapted for individual notifications.
|
||||
$this->endpoint = \App\Models\Setting::getSettings()->webhook_endpoint;
|
||||
|
||||
return $this->endpoint;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Establishes the user -> assets relationship
|
||||
|
|
16
database/factories/LicenseSeatFactory.php
Normal file
16
database/factories/LicenseSeatFactory.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\License;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class LicenseSeatFactory extends Factory
|
||||
{
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'license_id' => License::factory(),
|
||||
];
|
||||
}
|
||||
}
|
96
tests/Feature/Notifications/AccessoryWebhookTest.php
Normal file
96
tests/Feature/Notifications/AccessoryWebhookTest.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Notifications;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckinAccessoryNotification;
|
||||
use App\Notifications\CheckoutAccessoryNotification;
|
||||
use Illuminate\Notifications\AnonymousNotifiable;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AccessoryWebhookTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testAccessoryCheckoutSendsWebhookNotificationWhenSettingEnabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
Accessory::factory()->appleBtKeyboard()->create(),
|
||||
User::factory()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertSentTo(
|
||||
new AnonymousNotifiable,
|
||||
CheckoutAccessoryNotification::class,
|
||||
function ($notification, $channels, $notifiable) {
|
||||
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function testAccessoryCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->disableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
Accessory::factory()->appleBtKeyboard()->create(),
|
||||
User::factory()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAccessoryNotification::class);
|
||||
}
|
||||
|
||||
public function testAccessoryCheckinSendsWebhookNotificationWhenSettingEnabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedIn(
|
||||
Accessory::factory()->appleBtKeyboard()->create(),
|
||||
User::factory()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertSentTo(
|
||||
new AnonymousNotifiable,
|
||||
CheckinAccessoryNotification::class,
|
||||
function ($notification, $channels, $notifiable) {
|
||||
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function testAccessoryCheckinDoesNotSendWebhookNotificationWhenSettingDisabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->disableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedIn(
|
||||
Accessory::factory()->appleBtKeyboard()->create(),
|
||||
User::factory()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAccessoryNotification::class);
|
||||
}
|
||||
}
|
115
tests/Feature/Notifications/AssetWebhookTest.php
Normal file
115
tests/Feature/Notifications/AssetWebhookTest.php
Normal file
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Notifications;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Location;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckinAssetNotification;
|
||||
use App\Notifications\CheckoutAssetNotification;
|
||||
use Illuminate\Notifications\AnonymousNotifiable;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssetWebhookTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function targets(): array
|
||||
{
|
||||
return [
|
||||
'Asset checked out to user' => [fn() => User::factory()->create()],
|
||||
'Asset checked out to asset' => [fn() => $this->createAsset()],
|
||||
'Asset checked out to location' => [fn() => Location::factory()->create()],
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider targets */
|
||||
public function testAssetCheckoutSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
$this->createAsset(),
|
||||
$checkoutTarget(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertSentTo(
|
||||
new AnonymousNotifiable,
|
||||
CheckoutAssetNotification::class,
|
||||
function ($notification, $channels, $notifiable) {
|
||||
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/** @dataProvider targets */
|
||||
public function testAssetCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->disableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
$this->createAsset(),
|
||||
$checkoutTarget(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutAssetNotification::class);
|
||||
}
|
||||
|
||||
/** @dataProvider targets */
|
||||
public function testAssetCheckinSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedIn(
|
||||
$this->createAsset(),
|
||||
$checkoutTarget(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertSentTo(
|
||||
new AnonymousNotifiable,
|
||||
CheckinAssetNotification::class,
|
||||
function ($notification, $channels, $notifiable) {
|
||||
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/** @dataProvider targets */
|
||||
public function testAssetCheckinDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->disableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedIn(
|
||||
$this->createAsset(),
|
||||
$checkoutTarget(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinAssetNotification::class);
|
||||
}
|
||||
|
||||
private function createAsset()
|
||||
{
|
||||
return Asset::factory()->laptopMbp()->create();
|
||||
}
|
||||
}
|
50
tests/Feature/Notifications/ComponentWebhookTest.php
Normal file
50
tests/Feature/Notifications/ComponentWebhookTest.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Notifications;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Component;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ComponentWebhookTest extends TestCase
|
||||
{
|
||||
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testComponentCheckoutDoesNotSendWebhookNotification()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
Component::factory()->ramCrucial8()->create(),
|
||||
Asset::factory()->laptopMbp()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
public function testComponentCheckinDoesNotSendWebhookNotification()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedIn(
|
||||
Component::factory()->ramCrucial8()->create(),
|
||||
Asset::factory()->laptopMbp()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
}
|
56
tests/Feature/Notifications/ConsumableWebhookTest.php
Normal file
56
tests/Feature/Notifications/ConsumableWebhookTest.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Notifications;
|
||||
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckoutConsumableNotification;
|
||||
use Illuminate\Notifications\AnonymousNotifiable;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ConsumableWebhookTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function testConsumableCheckoutSendsWebhookNotificationWhenSettingEnabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
Consumable::factory()->cardstock()->create(),
|
||||
User::factory()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertSentTo(
|
||||
new AnonymousNotifiable,
|
||||
CheckoutConsumableNotification::class,
|
||||
function ($notification, $channels, $notifiable) {
|
||||
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function testConsumableCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->disableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
Consumable::factory()->cardstock()->create(),
|
||||
User::factory()->create(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutConsumableNotification::class);
|
||||
}
|
||||
}
|
109
tests/Feature/Notifications/LicenseWebhookTest.php
Normal file
109
tests/Feature/Notifications/LicenseWebhookTest.php
Normal file
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Notifications;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Models\Asset;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckinLicenseSeatNotification;
|
||||
use App\Notifications\CheckoutLicenseSeatNotification;
|
||||
use Illuminate\Notifications\AnonymousNotifiable;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LicenseWebhookTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
||||
public function targets(): array
|
||||
{
|
||||
return [
|
||||
'License checked out to user' => [fn() => User::factory()->create()],
|
||||
'License checked out to asset' => [fn() => Asset::factory()->laptopMbp()->create()],
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider targets */
|
||||
public function testLicenseCheckoutSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
LicenseSeat::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertSentTo(
|
||||
new AnonymousNotifiable,
|
||||
CheckoutLicenseSeatNotification::class,
|
||||
function ($notification, $channels, $notifiable) {
|
||||
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/** @dataProvider targets */
|
||||
public function testLicenseCheckoutDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->disableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedOut(
|
||||
LicenseSeat::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckoutLicenseSeatNotification::class);
|
||||
}
|
||||
|
||||
/** @dataProvider targets */
|
||||
public function testLicenseCheckinSendsWebhookNotificationWhenSettingEnabled($checkoutTarget)
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->enableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedIn(
|
||||
LicenseSeat::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertSentTo(
|
||||
new AnonymousNotifiable,
|
||||
CheckinLicenseSeatNotification::class,
|
||||
function ($notification, $channels, $notifiable) {
|
||||
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/** @dataProvider targets */
|
||||
public function testLicenseCheckinDoesNotSendWebhookNotificationWhenSettingDisabled($checkoutTarget)
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$this->settings->disableWebhook();
|
||||
|
||||
event(new CheckoutableCheckedIn(
|
||||
LicenseSeat::factory()->create(),
|
||||
$checkoutTarget(),
|
||||
User::factory()->superuser()->create(),
|
||||
''
|
||||
));
|
||||
|
||||
Notification::assertNotSentTo(new AnonymousNotifiable, CheckinLicenseSeatNotification::class);
|
||||
}
|
||||
}
|
|
@ -23,6 +23,24 @@ class Settings
|
|||
return $this->update(['full_multiple_companies_support' => 1]);
|
||||
}
|
||||
|
||||
public function enableWebhook(): Settings
|
||||
{
|
||||
return $this->update([
|
||||
'webhook_botname' => 'SnipeBot5000',
|
||||
'webhook_endpoint' => 'https://hooks.slack.com/services/NZ59/Q446/672N',
|
||||
'webhook_channel' => '#it',
|
||||
]);
|
||||
}
|
||||
|
||||
public function disableWebhook(): Settings
|
||||
{
|
||||
return $this->update([
|
||||
'webhook_botname' => '',
|
||||
'webhook_endpoint' => '',
|
||||
'webhook_channel' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attributes Attributes to modify in the application's settings.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue