Skip to content

Commit

Permalink
Merge pull request #15676 from Toreg87/fixes/api_create_user_fmcs
Browse files Browse the repository at this point in the history
Fix user creation with FullMultipleCompanySupport enabled over API
  • Loading branch information
snipe authored Oct 22, 2024
2 parents 58a3d09 + fdcc17c commit 147fcfb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\Accessory;
use App\Models\Company;
use App\Models\Consumable;
use App\Models\License;
use App\Models\User;
Expand Down Expand Up @@ -371,6 +372,7 @@ public function store(SaveUserRequest $request) : JsonResponse

$user = new User;
$user->fill($request->all());
$user->company_id = Company::getIdForCurrentUser($request->input('company_id'));
$user->created_by = auth()->id();

if ($request->has('permissions')) {
Expand Down Expand Up @@ -452,6 +454,10 @@ public function update(SaveUserRequest $request, User $user): JsonResponse

$user->fill($request->all());

if ($request->filled('company_id')) {
$user->company_id = Company::getIdForCurrentUser($request->input('company_id'));
}

if ($user->id == $request->input('manager_id')) {
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot be your own manager'));
}
Expand Down

0 comments on commit 147fcfb

Please sign in to comment.