Style changes requested

This commit is contained in:
snipe
2026-06-12 16:10:17 +01:00
parent 6a0ec69451
commit a27c551f64
9 changed files with 73 additions and 39 deletions
@@ -69,11 +69,14 @@ class AccessoryCheckoutController extends Controller
if (Setting::getSettings()->full_multiple_companies_support == '1' && $accessory->company_id) {
if ($target instanceof User) {
// Users may belong to multiple companies; canReceiveFromCompany() checks the pivot.
$mismatch = ! $target->canReceiveFromCompany($accessory->company_id);
} elseif (is_null($target->company_id)) {
// Target has no company — only a mismatch when floater mode is off.
$mismatch = ! Setting::getSettings()->null_company_is_floater;
} else {
$mismatch = is_null($target->company_id)
? ! Setting::getSettings()->null_company_is_floater
: (int) $target->company_id !== (int) $accessory->company_id;
// Both sides have a company; require an exact match.
$mismatch = (int) $target->company_id !== (int) $accessory->company_id;
}
if ($mismatch) {
@@ -927,9 +927,13 @@ class AssetsController extends Controller
return null;
}
$nonUserMismatch = is_null($target->company_id)
? ! Setting::getSettings()->null_company_is_floater
: (int) $asset->company_id !== (int) $target->company_id;
if (is_null($target->company_id)) {
// Target has no company — only a mismatch when floater mode is off.
$nonUserMismatch = ! Setting::getSettings()->null_company_is_floater;
} else {
// Both sides have a company; require an exact match.
$nonUserMismatch = (int) $asset->company_id !== (int) $target->company_id;
}
if ($nonUserMismatch) {
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.error_user_company')));
@@ -215,7 +215,8 @@ class LocationsController extends Controller
if (Setting::getSettings()->scope_locations_fmcs) {
$location->company_id = Company::getIdForCurrentUser($request->input('company_id'));
// check if parent is set and has a different company
if ($location->parent_id && ($parent = Location::find($location->parent_id)) && $parent->company_id != $location->company_id) {
$parent = $location->parent_id ? Location::find($location->parent_id) : null;
if ($parent && $parent->company_id != $location->company_id) {
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.error_location_parent_company', [
'parent' => $parent->name,
'parent_company' => $parent->company?->name ?? trans('general.unassigned'),
@@ -321,7 +322,8 @@ class LocationsController extends Controller
])));
}
// check if parent is set and has a different company
if ($location->parent_id && ($parent = Location::find($location->parent_id)) && $parent->company_id != $location->company_id) {
$parent = $location->parent_id ? Location::find($location->parent_id) : null;
if ($parent && $parent->company_id != $location->company_id) {
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.error_location_parent_company', [
'parent' => $parent->name,
'parent_company' => $parent->company?->name ?? trans('general.unassigned'),
+1 -10
View File
@@ -404,16 +404,7 @@ class UsersController extends Controller
if ((Setting::getSettings()->full_multiple_companies_support == '1') && $request->filled('companyId')) {
$companyIds = array_values(array_filter(array_map('intval', explode(',', $request->input('companyId')))));
if (! empty($companyIds)) {
if (Setting::getSettings()->null_company_is_floater) {
// Floater mode: users with no company associations can receive items from
// any company, so include them alongside exact-company matches.
$users->where(function ($q) use ($companyIds) {
$q->whereHas('companies', fn ($q2) => $q2->whereIn('companies.id', $companyIds))
->orWhereDoesntHave('companies');
});
} else {
$users->whereHas('companies', fn ($q) => $q->whereIn('companies.id', $companyIds));
}
$users = Company::scopeUsersByCompanyIds($users, $companyIds);
}
}
@@ -124,11 +124,16 @@ class AssetCheckoutController extends Controller
// Locations have no company, so we only enforce FMCS when both sides have a company_id.
// For users with multiple companies, check all their associated companies via the pivot.
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)
? ! $settings->null_company_is_floater
: (int) $target->company_id !== (int) $asset->company_id);
if ($target instanceof User) {
// Users may belong to multiple companies; canReceiveFromCompany() checks the pivot.
$mismatch = ! $target->canReceiveFromCompany((int) $asset->company_id);
} elseif (is_null($target->company_id)) {
// Target has no company — only a mismatch when floater mode is off.
$mismatch = ! $settings->null_company_is_floater;
} else {
// Both sides have a company; require an exact match.
$mismatch = (int) $target->company_id !== (int) $asset->company_id;
}
if ($mismatch) {
$targetType = match (class_basename($target)) {
@@ -138,7 +143,7 @@ class AssetCheckoutController extends Controller
};
return redirect()->route('hardware.checkout.create', $asset)->with('error', trans('general.error_checkout_company_mismatch', [
'item' => trans('general.asset').' "'.($asset->name ?? $asset->asset_tag).'"',
'item' => trans('general.asset').' "'.$asset->display_name.'"',
'item_company' => $asset->company?->name ?? trans('general.unassigned'),
'target' => $targetType.' "'.($target->name ?? $target->username ?? $target->id).'"',
]));
@@ -696,12 +696,19 @@ class BulkAssetsController extends Controller
if ($company_ids->isNotEmpty()) {
$assetCompanyId = (int) $company_ids->first();
$mismatch = $company_ids->count() > 1
|| ($target instanceof User
? ! $target->canReceiveFromCompany($assetCompanyId)
: (is_null($target->company_id)
? ! Setting::getSettings()->null_company_is_floater
: (int) $target->company_id !== $assetCompanyId));
if ($company_ids->count() > 1) {
// Selected assets span multiple companies; bulk checkout can't satisfy all of them.
$mismatch = true;
} elseif ($target instanceof User) {
// Users may belong to multiple companies; canReceiveFromCompany() checks the pivot.
$mismatch = ! $target->canReceiveFromCompany($assetCompanyId);
} elseif (is_null($target->company_id)) {
// Target has no company — only a mismatch when floater mode is off.
$mismatch = ! Setting::getSettings()->null_company_is_floater;
} else {
// Both sides have a company; require an exact match.
$mismatch = (int) $target->company_id !== $assetCompanyId;
}
if ($mismatch) {
$request->session()->flashInput(['selected_assets' => $asset_ids]);
@@ -100,9 +100,13 @@ class LicenseCheckoutController extends Controller
if ($request->filled('asset_id')) {
$fmcsTarget = Asset::find($request->input('asset_id'));
if ($fmcsTarget && $license->company_id) {
$mismatch = is_null($fmcsTarget->company_id)
? ! Setting::getSettings()->null_company_is_floater
: ($license->company_id !== $fmcsTarget->company_id);
if (is_null($fmcsTarget->company_id)) {
// Target asset has no company — only a mismatch when floater mode is off.
$mismatch = ! Setting::getSettings()->null_company_is_floater;
} else {
// Both sides have a company; require an exact match.
$mismatch = $license->company_id !== $fmcsTarget->company_id;
}
if ($mismatch) {
return redirect()->route('licenses.index')->with('error', trans('general.error_checkout_company_mismatch', [
'item' => trans('general.license').' "'.$license->name.'"',
+4 -2
View File
@@ -95,7 +95,8 @@ class LocationsController extends Controller
if (Setting::getSettings()->scope_locations_fmcs) {
$location->company_id = Company::getIdForCurrentUser($request->input('company_id'));
// check if parent is set and has a different company
if ($location->parent_id && ($parent = Location::find($location->parent_id)) && $parent->company_id != $location->company_id) {
$parent = $location->parent_id ? Location::find($location->parent_id) : null;
if ($parent && $parent->company_id != $location->company_id) {
return redirect()->back()->withInput()->with('error', trans('general.error_location_parent_company', [
'parent' => $parent->name,
'parent_company' => $parent->company?->name ?? trans('general.unassigned'),
@@ -189,7 +190,8 @@ class LocationsController extends Controller
]));
}
// check if parent is set and has a different company
if ($location->parent_id && ($parent = Location::find($location->parent_id)) && $parent->company_id != $location->company_id) {
$parent = $location->parent_id ? Location::find($location->parent_id) : null;
if ($parent && $parent->company_id != $location->company_id) {
return redirect()->back()->withInput()->with('error', trans('general.error_location_parent_company', [
'parent' => $parent->name,
'parent_company' => $parent->company?->name ?? trans('general.unassigned'),
+20 -4
View File
@@ -416,14 +416,12 @@ final class Company extends SnipeModel
});
}
// Floater: also include users with no company associations (they float).
// Floater: also include users with no company associations (they float). They all float down here, Georgie.).
if ($floater) {
return $query->where(function ($q) use ($companyIds) {
$q->whereIn('users.id', function ($sub) use ($companyIds) {
$sub->select('user_id')->from('company_user')->whereIn('company_id', $companyIds);
})->orWhereNotIn('users.id', function ($sub) {
$sub->select('user_id')->from('company_user');
});
})->orWhereDoesntHave('companies');
});
}
@@ -467,6 +465,24 @@ final class Company extends SnipeModel
}
}
/**
* Scope a users query to those belonging to the given company IDs, respecting floater mode.
*
* Extracted from controller-level inline logic so the same rule is enforced consistently
* everywhere users are filtered by a specific set of company IDs (e.g. select2 dropdowns).
*/
public static function scopeUsersByCompanyIds($query, array $companyIds): mixed
{
if (Setting::getSettings()->null_company_is_floater) {
return $query->where(function ($q) use ($companyIds) {
$q->whereHas('companies', fn($q2) => $q2->whereIn('companies.id', $companyIds))
->orWhereDoesntHave('companies');
});
}
return $query->whereHas('companies', fn($q) => $q->whereIn('companies.id', $companyIds));
}
/**
* I legit do not know what this method does, but we can't remove it (yet).
*