From 8fb21a5048b3411d6ffdaf6d5965d2213de4d1d7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 25 Jun 2020 21:42:21 -0700 Subject: [PATCH] Fix error while updating user --- .../Api/Application/Users/UserController.php | 27 +++---------------- app/Models/User.php | 2 +- .../Http/IntegrationJsonRequestAssertions.php | 6 ++--- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/app/Http/Controllers/Api/Application/Users/UserController.php b/app/Http/Controllers/Api/Application/Users/UserController.php index d067bab10..522cef8f4 100644 --- a/app/Http/Controllers/Api/Application/Users/UserController.php +++ b/app/Http/Controllers/Api/Application/Users/UserController.php @@ -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(); } diff --git a/app/Models/User.php b/app/Models/User.php index c8efc7bd6..c93fae6dd 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -164,7 +164,7 @@ class User extends Model implements 'name_last' => 'required|string|between:1,255', 'password' => 'sometimes|nullable|string', 'root_admin' => 'boolean', - 'language' => 'required|string', + 'language' => 'string', 'use_totp' => 'boolean', 'totp_secret' => 'nullable|string', ]; diff --git a/tests/Traits/Http/IntegrationJsonRequestAssertions.php b/tests/Traits/Http/IntegrationJsonRequestAssertions.php index 471085db0..c7cce5248 100644 --- a/tests/Traits/Http/IntegrationJsonRequestAssertions.php +++ b/tests/Traits/Http/IntegrationJsonRequestAssertions.php @@ -3,14 +3,14 @@ namespace Tests\Traits\Http; use Illuminate\Http\Response; -use Illuminate\Foundation\Testing\TestResponse; +use Illuminate\Testing\TestResponse; trait IntegrationJsonRequestAssertions { /** * Make assertions about a 404 response on the API. * - * @param \Illuminate\Foundation\Testing\TestResponse $response + * @param \Illuminate\Testing\TestResponse $response */ public function assertNotFoundJson(TestResponse $response) { @@ -31,7 +31,7 @@ trait IntegrationJsonRequestAssertions /** * Make assertions about a 403 error returned by the API. * - * @param \Illuminate\Foundation\Testing\TestResponse $response + * @param \Illuminate\Testing\TestResponse $response */ public function assertAccessDeniedJson(TestResponse $response) {