Skip to content

Commit 8fb21a5

Browse files
committed
Fix error while updating user
1 parent f0e3f0e commit 8fb21a5

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

app/Http/Controllers/Api/Application/Users/UserController.php

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,19 @@ public function view(GetUsersRequest $request): array
100100
* meta. If there are no errors this is an empty array.
101101
*
102102
* @param \Pterodactyl\Http\Requests\Api\Application\Users\UpdateUserRequest $request
103+
* @param \Pterodactyl\Models\User $user
103104
* @return array
104105
*
105106
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
106107
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
107108
*/
108-
public function update(UpdateUserRequest $request): array
109+
public function update(UpdateUserRequest $request, User $user): array
109110
{
110111
$this->updateService->setUserLevel(User::USER_LEVEL_ADMIN);
111-
$collection = $this->updateService->handle($request->getModel(User::class), $request->validated());
112-
113-
$errors = [];
114-
if (! empty($collection->get('exceptions'))) {
115-
foreach ($collection->get('exceptions') as $node => $exception) {
116-
/** @var \GuzzleHttp\Exception\RequestException $exception */
117-
/** @var \GuzzleHttp\Psr7\Response|null $response */
118-
$response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null;
119-
$message = trans('admin/server.exceptions.daemon_exception', [
120-
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
121-
]);
122-
123-
$errors[] = ['message' => $message, 'node' => $node];
124-
}
125-
}
126-
127-
$response = $this->fractal->item($collection->get('model'))
128-
->transformWith($this->getTransformer(UserTransformer::class));
112+
$user = $this->updateService->handle($user, $request->validated());
129113

130-
if (count($errors) > 0) {
131-
$response->addMeta([
132-
'revocation_errors' => $errors,
133-
]);
134-
}
114+
$response = $this->fractal->item($user)
115+
->transformWith($this->getTransformer(UserTransformer::class));
135116

136117
return $response->toArray();
137118
}

app/Models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class User extends Model implements
164164
'name_last' => 'required|string|between:1,255',
165165
'password' => 'sometimes|nullable|string',
166166
'root_admin' => 'boolean',
167-
'language' => 'required|string',
167+
'language' => 'string',
168168
'use_totp' => 'boolean',
169169
'totp_secret' => 'nullable|string',
170170
];

tests/Traits/Http/IntegrationJsonRequestAssertions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Tests\Traits\Http;
44

55
use Illuminate\Http\Response;
6-
use Illuminate\Foundation\Testing\TestResponse;
6+
use Illuminate\Testing\TestResponse;
77

88
trait IntegrationJsonRequestAssertions
99
{
1010
/**
1111
* Make assertions about a 404 response on the API.
1212
*
13-
* @param \Illuminate\Foundation\Testing\TestResponse $response
13+
* @param \Illuminate\Testing\TestResponse $response
1414
*/
1515
public function assertNotFoundJson(TestResponse $response)
1616
{
@@ -31,7 +31,7 @@ public function assertNotFoundJson(TestResponse $response)
3131
/**
3232
* Make assertions about a 403 error returned by the API.
3333
*
34-
* @param \Illuminate\Foundation\Testing\TestResponse $response
34+
* @param \Illuminate\Testing\TestResponse $response
3535
*/
3636
public function assertAccessDeniedJson(TestResponse $response)
3737
{

0 commit comments

Comments
 (0)