diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index bc111fb31f..fad3be7693 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -402,7 +402,9 @@ class UsersController extends Controller } app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar'); - + + $user->customFill($request,Auth::user()); + if ($user->save()) { if ($request->filled('groups')) { $user->groups()->sync($request->input('groups')); @@ -502,7 +504,9 @@ class UsersController extends Controller app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar'); - + + $user->customFill($request,Auth::user()); + if ($user->save()) { // Check if the request has groups passed and has a value, AND that the user us a superuser diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 8df5842929..bd6fc89793 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -130,6 +130,9 @@ class UsersController extends Controller // we have to invoke the app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar'); + \Log::info("About to call customFill, in the 'store' controller!!!"); + $user->customFill($request, Auth::user()); + if ($user->save()) { if ($request->filled('groups')) { $user->groups()->sync($request->input('groups')); @@ -321,7 +324,31 @@ class UsersController extends Controller } - return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', compact('id'))); + $permissions_array = $request->input('permission'); + + // Strip out the superuser permission if the user isn't a superadmin + if (!Auth::user()->isSuperUser()) { + unset($permissions_array['superuser']); + $permissions_array['superuser'] = $orig_superuser; + } + + $user->permissions = json_encode($permissions_array); + + // Handle uploaded avatar + app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar'); + + \Log::debug("calling custom fill from the UPDATE method!"); + $user->customFill($request, Auth::user()); + //\Log::debug(print_r($user, true)); + + // Was the user updated? + if ($user->save()) { + // Redirect to the user page + return redirect()->route('users.index') + ->with('success', trans('admin/users/message.success.update')); + } + + return redirect()->back()->withInput()->withErrors($user->getErrors()); } /** diff --git a/app/Models/Traits/HasCustomFields.php b/app/Models/Traits/HasCustomFields.php index b3f8b52977..8dcfe3cffd 100644 --- a/app/Models/Traits/HasCustomFields.php +++ b/app/Models/Traits/HasCustomFields.php @@ -42,7 +42,7 @@ trait HasCustomFields public function getFieldset(): ?CustomFieldset { $pivot = $this->getFieldsetKey(); if(is_int($pivot)) { //why does this look just like the other thing? (below, look for is_int() - return Fieldset::find($pivot); + return CustomFieldset::find($pivot); } return $pivot->fieldset; } @@ -113,7 +113,6 @@ trait HasCustomFields } public function customFill(Request $request, User $user, bool $shouldSetDefaults = false) { - $this->_filled = true; if ($this->getFieldset()) { foreach ($this->getFieldset()->fields as $field) { if (is_array($request->input($field->db_column))) { diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php index a83197763e..713c0da8ab 100755 --- a/resources/views/hardware/edit.blade.php +++ b/resources/views/hardware/edit.blade.php @@ -75,20 +75,17 @@