diff --git a/.all-contributorsrc b/.all-contributorsrc
index dd090262e..eb052687e 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -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"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 3a0d37998..040de8e93 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
 [](https://crowdin.com/project/snipe-it) [](https://hub.docker.com/r/snipe/snipe-it/) [](https://twitter.com/snipeitapp) [](https://www.codacy.com/app/snipe/snipe-it?utm_source=github.com&utm_medium=referral&utm_content=snipe/snipe-it&utm_campaign=Badge_Grade)
-[](#contributors) [](https://discord.gg/yZFtShAcKk) [](https://huntr.dev)
+[](#contributors) [](https://discord.gg/yZFtShAcKk) [](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
| [
Peace](https://github.com/julian-piehl)
[💻](https://github.com/snipe/snipe-it/commits?author=julian-piehl "Code") | [
Kyle Gordon](https://github.com/kylegordon)
[💻](https://github.com/snipe/snipe-it/commits?author=kylegordon "Code") | [
Katharina Drexel](http://www.bfh.ch)
[💻](https://github.com/snipe/snipe-it/commits?author=sunflowerbofh "Code") | [
David Sferruzza](https://david.sferruzza.fr/)
[💻](https://github.com/snipe/snipe-it/commits?author=dsferruzza "Code") | [
Rick Nelson](https://github.com/rnelsonee)
[💻](https://github.com/snipe/snipe-it/commits?author=rnelsonee "Code") | [
BasO12](https://github.com/BasO12)
[💻](https://github.com/snipe/snipe-it/commits?author=BasO12 "Code") | [
Vautia](https://github.com/Vautia)
[💻](https://github.com/snipe/snipe-it/commits?author=Vautia "Code") |
| [
Chris Hartjes](http://www.littlehart.net/atthekeyboard)
[💻](https://github.com/snipe/snipe-it/commits?author=chartjes "Code") | [
geo-chen](https://github.com/geo-chen)
[💻](https://github.com/snipe/snipe-it/commits?author=geo-chen "Code") | [
Phan Nguyen](https://github.com/nh314)
[💻](https://github.com/snipe/snipe-it/commits?author=nh314 "Code") | [
Iisakki Jaakkola](https://github.com/StarlessNights)
[💻](https://github.com/snipe/snipe-it/commits?author=StarlessNights "Code") | [
Ikko Ashimine](https://bandism.net/)
[💻](https://github.com/snipe/snipe-it/commits?author=eltociear "Code") | [
Lukas Fehling](https://github.com/lukasfehling)
[💻](https://github.com/snipe/snipe-it/commits?author=lukasfehling "Code") | [
Fernando Almeida](https://github.com/fernando-almeida)
[💻](https://github.com/snipe/snipe-it/commits?author=fernando-almeida "Code") |
| [
akemidx](https://github.com/akemidx)
[💻](https://github.com/snipe/snipe-it/commits?author=akemidx "Code") | [
Oguz Bilgic](http://oguz.site)
[💻](https://github.com/snipe/snipe-it/commits?author=oguzbilgic "Code") | [
Scooter Crawford](https://github.com/scoo73r)
[💻](https://github.com/snipe/snipe-it/commits?author=scoo73r "Code") | [
subdriven](https://github.com/subdriven)
[💻](https://github.com/snipe/snipe-it/commits?author=subdriven "Code") | [
Andrew Savinykh](https://github.com/AndrewSav)
[💻](https://github.com/snipe/snipe-it/commits?author=AndrewSav "Code") | [
Tadayuki Onishi](https://kenchan0130.github.io)
[💻](https://github.com/snipe/snipe-it/commits?author=kenchan0130 "Code") | [
Florian](https://github.com/floschoepfer)
[💻](https://github.com/snipe/snipe-it/commits?author=floschoepfer "Code") |
-| [
Spencer Long](http://spencerlong.com)
[💻](https://github.com/snipe/snipe-it/commits?author=spencerrlongg "Code") | [
Marcus Moore](https://github.com/marcusmoore)
[💻](https://github.com/snipe/snipe-it/commits?author=marcusmoore "Code") | [
Martin Meredith](https://github.com/Mezzle)
|
+| [
Spencer Long](http://spencerlong.com)
[💻](https://github.com/snipe/snipe-it/commits?author=spencerrlongg "Code") | [
Marcus Moore](https://github.com/marcusmoore)
[💻](https://github.com/snipe/snipe-it/commits?author=marcusmoore "Code") | [
Martin Meredith](https://github.com/Mezzle)
| [
dboth](http://dboth.de)
[💻](https://github.com/snipe/snipe-it/commits?author=dboth "Code") | [
Zachary Fleck](https://github.com/zacharyfleck)
[💻](https://github.com/snipe/snipe-it/commits?author=zacharyfleck "Code") |
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
diff --git a/app/Console/Commands/CheckoutLicenseToAllUsers.php b/app/Console/Commands/CheckoutLicenseToAllUsers.php
index c81408442..801b3d187 100644
--- a/app/Console/Commands/CheckoutLicenseToAllUsers.php
+++ b/app/Console/Commands/CheckoutLicenseToAllUsers.php
@@ -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. ');
diff --git a/app/Http/Controllers/Accessories/AccessoriesController.php b/app/Http/Controllers/Accessories/AccessoriesController.php
index 7d4e697b9..111cbb3c8 100755
--- a/app/Http/Controllers/Accessories/AccessoriesController.php
+++ b/app/Http/Controllers/Accessories/AccessoriesController.php
@@ -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');
diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php
index 7e8ecdb11..ab5635ec3 100644
--- a/app/Http/Controllers/Api/AssetMaintenancesController.php
+++ b/app/Http/Controllers/Api/AssetMaintenancesController.php
@@ -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'));
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php
index 343593a03..1816fc9f6 100644
--- a/app/Http/Controllers/Api/AssetsController.php
+++ b/app/Http/Controllers/Api/AssetsController.php
@@ -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.
diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php
index 5f3221d05..dc6bc8434 100644
--- a/app/Http/Controllers/AssetMaintenancesController.php
+++ b/app/Http/Controllers/AssetMaintenancesController.php
@@ -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'));
diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php
index 3b2ff4623..2a9384550 100755
--- a/app/Http/Controllers/Assets/AssetsController.php
+++ b/app/Http/Controllers/Assets/AssetsController.php
@@ -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);
diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php
index 6caf1593a..80d17f1b3 100644
--- a/app/Http/Controllers/Assets/BulkAssetsController.php
+++ b/app/Http/Controllers/Assets/BulkAssetsController.php
@@ -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')) {
diff --git a/app/Http/Controllers/Components/ComponentsController.php b/app/Http/Controllers/Components/ComponentsController.php
index 2ada97361..34c9aed16 100644
--- a/app/Http/Controllers/Components/ComponentsController.php
+++ b/app/Http/Controllers/Components/ComponentsController.php
@@ -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');
diff --git a/app/Http/Controllers/Consumables/ConsumablesController.php b/app/Http/Controllers/Consumables/ConsumablesController.php
index 0a40c0bb3..b33e6e07a 100644
--- a/app/Http/Controllers/Consumables/ConsumablesController.php
+++ b/app/Http/Controllers/Consumables/ConsumablesController.php
@@ -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');
diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.php
index 7acceb378..26cba3328 100755
--- a/app/Http/Controllers/Licenses/LicensesController.php
+++ b/app/Http/Controllers/Licenses/LicensesController.php
@@ -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);
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index 9d6cd942b..09cb3ae8f 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -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;
+ }
}
diff --git a/app/Models/AssetMaintenance.php b/app/Models/AssetMaintenance.php
index 41ab80257..292e52957 100644
--- a/app/Models/AssetMaintenance.php
+++ b/app/Models/AssetMaintenance.php
@@ -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;
diff --git a/app/Models/LicenseSeat.php b/app/Models/LicenseSeat.php
index 2207edd02..d2a99d3c5 100755
--- a/app/Models/LicenseSeat.php
+++ b/app/Models/LicenseSeat.php
@@ -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;
diff --git a/app/Models/SnipeModel.php b/app/Models/SnipeModel.php
index e5a039a4e..af12c3d29 100644
--- a/app/Models/SnipeModel.php
+++ b/app/Models/SnipeModel.php
@@ -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;
diff --git a/app/Models/User.php b/app/Models/User.php
index 44bffe156..36e1c8ac4 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -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
diff --git a/database/factories/LicenseSeatFactory.php b/database/factories/LicenseSeatFactory.php
new file mode 100644
index 000000000..3c6cc4246
--- /dev/null
+++ b/database/factories/LicenseSeatFactory.php
@@ -0,0 +1,16 @@
+ License::factory(),
+ ];
+ }
+}
diff --git a/tests/Feature/Notifications/AccessoryWebhookTest.php b/tests/Feature/Notifications/AccessoryWebhookTest.php
new file mode 100644
index 000000000..a1db59b98
--- /dev/null
+++ b/tests/Feature/Notifications/AccessoryWebhookTest.php
@@ -0,0 +1,96 @@
+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);
+ }
+}
diff --git a/tests/Feature/Notifications/AssetWebhookTest.php b/tests/Feature/Notifications/AssetWebhookTest.php
new file mode 100644
index 000000000..ae45a4caa
--- /dev/null
+++ b/tests/Feature/Notifications/AssetWebhookTest.php
@@ -0,0 +1,115 @@
+ [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();
+ }
+}
diff --git a/tests/Feature/Notifications/ComponentWebhookTest.php b/tests/Feature/Notifications/ComponentWebhookTest.php
new file mode 100644
index 000000000..8f3a51b15
--- /dev/null
+++ b/tests/Feature/Notifications/ComponentWebhookTest.php
@@ -0,0 +1,50 @@
+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();
+ }
+}
diff --git a/tests/Feature/Notifications/ConsumableWebhookTest.php b/tests/Feature/Notifications/ConsumableWebhookTest.php
new file mode 100644
index 000000000..854fdf534
--- /dev/null
+++ b/tests/Feature/Notifications/ConsumableWebhookTest.php
@@ -0,0 +1,56 @@
+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);
+ }
+}
diff --git a/tests/Feature/Notifications/LicenseWebhookTest.php b/tests/Feature/Notifications/LicenseWebhookTest.php
new file mode 100644
index 000000000..4313ff69d
--- /dev/null
+++ b/tests/Feature/Notifications/LicenseWebhookTest.php
@@ -0,0 +1,109 @@
+ [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);
+ }
+}
diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php
index ccf50c3ce..9d4209da7 100644
--- a/tests/Support/Settings.php
+++ b/tests/Support/Settings.php
@@ -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.
*/