set up api controller for route/model binding

This commit is contained in:
spencerrlongg 2024-08-14 16:09:15 -05:00
parent 20ec420ba3
commit f031309f8f
2 changed files with 1 additions and 18 deletions

View file

@ -431,9 +431,6 @@ class UsersController extends Controller
{ {
$this->authorize('update', User::class); $this->authorize('update', User::class);
if ($user = User::find($id)) {
$this->authorize('update', $user); $this->authorize('update', $user);
/** /**
@ -443,12 +440,10 @@ class UsersController extends Controller
* *
*/ */
if ((($user->id == 1) || ($user->id == 2)) && (config('app.lock_passwords'))) {
if ((($id == 1) || ($id == 2)) && (config('app.lock_passwords'))) {
return response()->json(Helper::formatStandardApiResponse('error', null, 'Permission denied. You cannot update user information via API on the demo.')); return response()->json(Helper::formatStandardApiResponse('error', null, 'Permission denied. You cannot update user information via API on the demo.'));
} }
$user->fill($request->all()); $user->fill($request->all());
if ($user->id == $request->input('manager_id')) { if ($user->id == $request->input('manager_id')) {
@ -473,16 +468,13 @@ class UsersController extends Controller
$user->permissions = $permissions_array; $user->permissions = $permissions_array;
} }
// Update the location of any assets checked out to this user // Update the location of any assets checked out to this user
Asset::where('assigned_type', User::class) Asset::where('assigned_type', User::class)
->where('assigned_to', $user->id)->update(['location_id' => $request->input('location_id', null)]); ->where('assigned_to', $user->id)->update(['location_id' => $request->input('location_id', null)]);
app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar'); app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar');
if ($user->save()) { if ($user->save()) {
// Check if the request has groups passed and has a value, AND that the user us a superuser // Check if the request has groups passed and has a value, AND that the user us a superuser
if (($request->has('groups')) && (auth()->user()->isSuperUser())) { if (($request->has('groups')) && (auth()->user()->isSuperUser())) {
@ -496,18 +488,10 @@ class UsersController extends Controller
// Sync the groups since the user is a superuser and the groups pass validation // Sync the groups since the user is a superuser and the groups pass validation
$user->groups()->sync($request->input('groups')); $user->groups()->sync($request->input('groups'));
} }
return response()->json(Helper::formatStandardApiResponse('success', (new UsersTransformer)->transformUser($user), trans('admin/users/message.success.update'))); return response()->json(Helper::formatStandardApiResponse('success', (new UsersTransformer)->transformUser($user), trans('admin/users/message.success.update')));
} }
return response()->json(Helper::formatStandardApiResponse('error', null, $user->getErrors())); return response()->json(Helper::formatStandardApiResponse('error', null, $user->getErrors()));
}
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id'))));
} }
/** /**

View file

@ -38,7 +38,6 @@ class SaveUserRequest extends FormRequest
'company_id' => [ 'company_id' => [
// determines if the user is being moved between companies and checks to see if they have any items assigned // determines if the user is being moved between companies and checks to see if they have any items assigned
function ($attribute, $value, $fail) { function ($attribute, $value, $fail) {
dd($this->user);
if (($this->has('company_id')) && ($this->user->allAssignedCount() > 0) && (Setting::getSettings()->full_multiple_companies_support)) { if (($this->has('company_id')) && ($this->user->allAssignedCount() > 0) && (Setting::getSettings()->full_multiple_companies_support)) {
$fail(trans('admin/users/message.error.multi_company_items_assigned')); $fail(trans('admin/users/message.error.multi_company_items_assigned'));
} }