Skip to content

A free open source IT asset/license management system

Begin experimenting with context

Marcus Moorea40e4d7d0457
diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php
index cb4fa5fa5b..30047438e1 100644
--- a/app/Http/Controllers/Assets/BulkAssetsController.php
+++ b/app/Http/Controllers/Assets/BulkAssetsController.php
@@ -12,6 +12,7 @@ use App\Models\Setting;
use App\View\Label;
use Carbon\Carbon;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Context;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
@@ -631,6 +632,8 @@ class BulkAssetsController extends Controller
*/
public function storeCheckout(AssetCheckoutRequest $request) : RedirectResponse | ModelNotFoundException
{
+ Context::add('action', 'bulk_asset_checkout');
+
$this->authorize('checkout', Asset::class);
try {
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index 908dd58dfd..a2052dce37 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -33,6 +33,7 @@ use App\Notifications\CheckoutConsumableNotification;
use App\Notifications\CheckoutLicenseSeatNotification;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\Context;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Exception;
@@ -428,12 +429,17 @@ class CheckoutableListener
private function shouldSendCheckoutEmailToUser(Model $checkoutable): bool
{
/**
- * Send an email if any of the following conditions are met:
+ * Send an email if we didn't get here from a bulk checkout
+ * and any of the following conditions are met:
* 1. The asset requires acceptance
* 2. The item has a EULA
* 3. The item should send an email at check-in/check-out
*/
+ if (Context::get('action') === 'bulk_asset_checkout') {
+ return false;
+ }
+
if ($checkoutable->requireAcceptance()) {
return true;
}