1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-22 09:02:28 +01:00

Fix error while updating user

This commit is contained in:
Dane Everitt 2020-06-25 21:42:21 -07:00
parent f0e3f0e474
commit 8fb21a5048
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 8 additions and 27 deletions

View File

@ -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();
}

View File

@ -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',
];

View File

@ -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)
{