Skip to content

A free open source IT asset/license management system

FMCS: Extended checks to accessories, bulk controllers, etc

snipe0f6367bb1715
diff --git a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php b/app/Http/Controllers/Accessories/AccessoryCheckoutController.php
index a00e072cb7..0159481824 100644
--- a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php
+++ b/app/Http/Controllers/Accessories/AccessoryCheckoutController.php
@@ -67,13 +67,18 @@ class AccessoryCheckoutController extends Controller
$target = $this->determineCheckoutTarget();
session()->put(['checkout_to_type' => $target]);
- if (
- Setting::getSettings()->full_multiple_companies_support == '1'
- && $accessory->company_id
- && $target instanceof User
- && ! $target->canReceiveFromCompany($accessory->company_id)
- ) {
- return redirect()->back()->with('error', trans('general.error_user_company'));
+ if (Setting::getSettings()->full_multiple_companies_support == '1' && $accessory->company_id) {
+ if ($target instanceof User) {
+ $mismatch = ! $target->canReceiveFromCompany($accessory->company_id);
+ } else {
+ $mismatch = is_null($target->company_id)
+ ? ! Setting::getSettings()->null_company_is_floater
+ : (int) $target->company_id !== (int) $accessory->company_id;
+ }
+
+ if ($mismatch) {
+ return redirect()->back()->with('error', trans('general.error_user_company'));
+ }
}
$accessory->checkout_qty = $request->input('checkout_qty', 1);
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php
index 0581847bf0..550bd29074 100644
--- a/app/Http/Controllers/Api/AssetsController.php
+++ b/app/Http/Controllers/Api/AssetsController.php
@@ -927,7 +927,11 @@ class AssetsController extends Controller
return null;
}
- if (! is_null($target->company_id) && (int) $asset->company_id !== (int) $target->company_id) {
+ $nonUserMismatch = is_null($target->company_id)
+ ? ! Setting::getSettings()->null_company_is_floater
+ : (int) $asset->company_id !== (int) $target->company_id;
+
+ if ($nonUserMismatch) {
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.error_user_company')));
}
diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php
index 9c0221984a..2400467276 100644
--- a/app/Http/Controllers/Assets/AssetCheckoutController.php
+++ b/app/Http/Controllers/Assets/AssetCheckoutController.php
@@ -126,7 +126,9 @@ class AssetCheckoutController extends Controller
if ($settings->full_multiple_companies_support && ! is_null($asset->company_id)) {
$mismatch = $target instanceof User
? ! $target->canReceiveFromCompany((int) $asset->company_id)
- : (! is_null($target->company_id) && (int) $target->company_id !== (int) $asset->company_id);
+ : (is_null($target->company_id)
+ ? ! $settings->null_company_is_floater
+ : (int) $target->company_id !== (int) $asset->company_id);
if ($mismatch) {
return redirect()->route('hardware.checkout.create', $asset)->with('error', trans('general.error_user_company'));
diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php
index 7bca83d2ec..889ed68891 100644
--- a/app/Http/Controllers/Assets/BulkAssetsController.php
+++ b/app/Http/Controllers/Assets/BulkAssetsController.php
@@ -699,7 +699,9 @@ class BulkAssetsController extends Controller
$mismatch = $company_ids->count() > 1
|| ($target instanceof User
? ! $target->canReceiveFromCompany($assetCompanyId)
- : (! is_null($target->company_id) && (int) $target->company_id !== $assetCompanyId));
+ : (is_null($target->company_id)
+ ? ! Setting::getSettings()->null_company_is_floater
+ : (int) $target->company_id !== $assetCompanyId));
if ($mismatch) {
$request->session()->flashInput(['selected_assets' => $asset_ids]);
diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.php
index f30acbf2a7..afc209a936 100644
--- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php
+++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php
@@ -99,8 +99,13 @@ class LicenseCheckoutController extends Controller
if (Setting::getSettings()->full_multiple_companies_support == '1') {
if ($request->filled('asset_id')) {
$fmcsTarget = Asset::find($request->input('asset_id'));
- if ($fmcsTarget && $license->company_id && $license->company_id !== $fmcsTarget->company_id) {
- return redirect()->route('licenses.index')->with('error', trans('general.error_user_company'));
+ if ($fmcsTarget && $license->company_id) {
+ $mismatch = is_null($fmcsTarget->company_id)
+ ? ! Setting::getSettings()->null_company_is_floater
+ : ($license->company_id !== $fmcsTarget->company_id);
+ if ($mismatch) {
+ return redirect()->route('licenses.index')->with('error', trans('general.error_user_company'));
+ }
}
} elseif ($request->filled('assigned_to')) {
$fmcsTarget = User::find($request->input('assigned_to'));
diff --git a/tests/Feature/Accessories/Ui/CheckoutAccessoryTest.php b/tests/Feature/Accessories/Ui/CheckoutAccessoryTest.php
index 132e57375a..a46ffe1bce 100644
--- a/tests/Feature/Accessories/Ui/CheckoutAccessoryTest.php
+++ b/tests/Feature/Accessories/Ui/CheckoutAccessoryTest.php
@@ -170,7 +170,7 @@ class CheckoutAccessoryTest extends TestCase
$accessory = Accessory::factory()->for($companyA)->create(['qty' => 5]);
$location = Location::factory()->create();
- $this->settings->enableMultipleFullCompanySupport();
+ $this->settings->enableFloaterMode();
$actor = User::factory()->superuser()->create();