FMCS: Extended checks to accessories, bulk controllers, etc

This commit is contained in:
snipe
2026-06-10 11:47:54 +01:00
parent e3190c3922
commit 0f6367bb17
6 changed files with 31 additions and 13 deletions
@@ -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);
@@ -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')));
}
@@ -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'));
@@ -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]);
@@ -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'));
@@ -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();