FMCS+location scoping - Fixed scope boundaries
This commit is contained in:
@@ -211,10 +211,12 @@ class LocationsController extends Controller
|
||||
$location->fill($request->all());
|
||||
$location = $request->handleImages($location);
|
||||
|
||||
// Only scope location if the setting is enabled
|
||||
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
|
||||
}
|
||||
|
||||
// Parent company check applies whenever FMCS is on, independent of scope_locations_fmcs.
|
||||
if (Setting::getSettings()->full_multiple_companies_support) {
|
||||
$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', [
|
||||
@@ -308,7 +310,6 @@ class LocationsController extends Controller
|
||||
$location = $request->handleImages($location);
|
||||
|
||||
if ($request->filled('company_id')) {
|
||||
// Only scope location if the setting is enabled
|
||||
if (Setting::getSettings()->scope_locations_fmcs) {
|
||||
$location->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
||||
// check if there are related objects with different company
|
||||
@@ -321,20 +322,24 @@ class LocationsController extends Controller
|
||||
'item_company' => $first[5] ?? trans('general.unassigned'),
|
||||
])));
|
||||
}
|
||||
// check if parent is set and has a different company
|
||||
$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'),
|
||||
'location_company' => $location->company?->name ?? trans('general.unassigned'),
|
||||
])));
|
||||
}
|
||||
} else {
|
||||
$location->company_id = $request->input('company_id');
|
||||
}
|
||||
}
|
||||
|
||||
// Parent company check applies whenever FMCS is on, independent of scope_locations_fmcs.
|
||||
// Runs outside the company_id gate so a parent_id-only update is also validated.
|
||||
if (Setting::getSettings()->full_multiple_companies_support) {
|
||||
$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'),
|
||||
'location_company' => $location->company?->name ?? trans('general.unassigned'),
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
||||
if ($location->isValid()) {
|
||||
|
||||
$location->save();
|
||||
|
||||
@@ -89,12 +89,14 @@ class LocationsController extends Controller
|
||||
$location->fax = request('fax');
|
||||
$location->tag_color = $request->input('tag_color');
|
||||
$location->notes = $request->input('notes');
|
||||
$location->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
||||
|
||||
// Only scope the location if the setting is enabled
|
||||
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
|
||||
} else {
|
||||
$location->company_id = $request->input('company_id');
|
||||
}
|
||||
|
||||
// Parent company check applies whenever FMCS is on, independent of scope_locations_fmcs.
|
||||
if (Setting::getSettings()->full_multiple_companies_support) {
|
||||
$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', [
|
||||
@@ -103,8 +105,6 @@ class LocationsController extends Controller
|
||||
'location_company' => $location->company?->name ?? trans('general.unassigned'),
|
||||
]));
|
||||
}
|
||||
} else {
|
||||
$location->company_id = $request->input('company_id');
|
||||
}
|
||||
|
||||
if ($request->has('use_cloned_image')) {
|
||||
@@ -176,7 +176,6 @@ class LocationsController extends Controller
|
||||
$location->tag_color = $request->input('tag_color');
|
||||
$location->notes = $request->input('notes');
|
||||
|
||||
// Only scope the location if the setting is enabled
|
||||
if (Setting::getSettings()->scope_locations_fmcs) {
|
||||
$location->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
||||
// check if there are related objects with different company
|
||||
@@ -189,7 +188,12 @@ class LocationsController extends Controller
|
||||
'item_company' => $first[5] ?? trans('general.unassigned'),
|
||||
]));
|
||||
}
|
||||
// check if parent is set and has a different company
|
||||
} else {
|
||||
$location->company_id = $request->input('company_id');
|
||||
}
|
||||
|
||||
// Parent company check applies whenever FMCS is on, independent of scope_locations_fmcs.
|
||||
if (Setting::getSettings()->full_multiple_companies_support) {
|
||||
$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', [
|
||||
@@ -198,8 +202,6 @@ class LocationsController extends Controller
|
||||
'location_company' => $location->company?->name ?? trans('general.unassigned'),
|
||||
]));
|
||||
}
|
||||
} else {
|
||||
$location->company_id = $request->input('company_id');
|
||||
}
|
||||
|
||||
$location = $request->handleImages($location);
|
||||
|
||||
Reference in New Issue
Block a user