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.
|
* meta. If there are no errors this is an empty array.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Http\Requests\Api\Application\Users\UpdateUserRequest $request
|
* @param \Pterodactyl\Http\Requests\Api\Application\Users\UpdateUserRequest $request
|
||||||
|
* @param \Pterodactyl\Models\User $user
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
* @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);
|
$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 = [];
|
$response = $this->fractal->item($user)
|
||||||
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'))
|
|
||||||
->transformWith($this->getTransformer(UserTransformer::class));
|
->transformWith($this->getTransformer(UserTransformer::class));
|
||||||
|
|
||||||
if (count($errors) > 0) {
|
|
||||||
$response->addMeta([
|
|
||||||
'revocation_errors' => $errors,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response->toArray();
|
return $response->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ class User extends Model implements
|
||||||
'name_last' => 'required|string|between:1,255',
|
'name_last' => 'required|string|between:1,255',
|
||||||
'password' => 'sometimes|nullable|string',
|
'password' => 'sometimes|nullable|string',
|
||||||
'root_admin' => 'boolean',
|
'root_admin' => 'boolean',
|
||||||
'language' => 'required|string',
|
'language' => 'string',
|
||||||
'use_totp' => 'boolean',
|
'use_totp' => 'boolean',
|
||||||
'totp_secret' => 'nullable|string',
|
'totp_secret' => 'nullable|string',
|
||||||
];
|
];
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
namespace Tests\Traits\Http;
|
namespace Tests\Traits\Http;
|
||||||
|
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Foundation\Testing\TestResponse;
|
use Illuminate\Testing\TestResponse;
|
||||||
|
|
||||||
trait IntegrationJsonRequestAssertions
|
trait IntegrationJsonRequestAssertions
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Make assertions about a 404 response on the API.
|
* 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)
|
public function assertNotFoundJson(TestResponse $response)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@ trait IntegrationJsonRequestAssertions
|
||||||
/**
|
/**
|
||||||
* Make assertions about a 403 error returned by the API.
|
* 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)
|
public function assertAccessDeniedJson(TestResponse $response)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue