Fix error while updating user
This commit is contained in:
parent
f0e3f0e474
commit
8fb21a5048
3 changed files with 8 additions and 27 deletions
|
@ -100,39 +100,20 @@ class UserController extends ApplicationApiController
|
|||
* meta. If there are no errors this is an empty array.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Api\Application\Users\UpdateUserRequest $request
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function update(UpdateUserRequest $request): array
|
||||
public function update(UpdateUserRequest $request, User $user): array
|
||||
{
|
||||
$this->updateService->setUserLevel(User::USER_LEVEL_ADMIN);
|
||||
$collection = $this->updateService->handle($request->getModel(User::class), $request->validated());
|
||||
$user = $this->updateService->handle($user, $request->validated());
|
||||
|
||||
$errors = [];
|
||||
if (! empty($collection->get('exceptions'))) {
|
||||
foreach ($collection->get('exceptions') as $node => $exception) {
|
||||
/** @var \GuzzleHttp\Exception\RequestException $exception */
|
||||
/** @var \GuzzleHttp\Psr7\Response|null $response */
|
||||
$response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null;
|
||||
$message = trans('admin/server.exceptions.daemon_exception', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]);
|
||||
|
||||
$errors[] = ['message' => $message, 'node' => $node];
|
||||
}
|
||||
}
|
||||
|
||||
$response = $this->fractal->item($collection->get('model'))
|
||||
$response = $this->fractal->item($user)
|
||||
->transformWith($this->getTransformer(UserTransformer::class));
|
||||
|
||||
if (count($errors) > 0) {
|
||||
$response->addMeta([
|
||||
'revocation_errors' => $errors,
|
||||
]);
|
||||
}
|
||||
|
||||
return $response->toArray();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue