Fix bad API behavior
This commit is contained in:
parent
d4d9eda57a
commit
2ec76d283b
10 changed files with 86 additions and 68 deletions
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Api\Application\Users;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
|
||||
class GetUserRequest extends GetUsersRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested user exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$user = $this->route()->parameter('user');
|
||||
|
||||
return $user instanceof User && $user->exists;
|
||||
}
|
||||
}
|
|
@ -21,20 +21,41 @@ class StoreUserRequest extends ApplicationApiRequest
|
|||
/**
|
||||
* Return the validation rules for this request.
|
||||
*
|
||||
* @param array|null $rules
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return collect(User::getCreateRules())->only([
|
||||
$rules = $rules ?? User::getCreateRules();
|
||||
|
||||
$response = collect($rules)->only([
|
||||
'external_id',
|
||||
'email',
|
||||
'username',
|
||||
'name_first',
|
||||
'name_last',
|
||||
'password',
|
||||
'language',
|
||||
'root_admin',
|
||||
])->toArray();
|
||||
|
||||
$response['first_name'] = $rules['name_first'];
|
||||
$response['last_name'] = $rules['name_last'];
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function validated()
|
||||
{
|
||||
$data = parent::validated();
|
||||
|
||||
$data['name_first'] = $data['first_name'];
|
||||
$data['name_last'] = $data['last_name'];
|
||||
|
||||
unset($data['first_name'], $data['last_name']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,36 +6,16 @@ use Pterodactyl\Models\User;
|
|||
|
||||
class UpdateUserRequest extends StoreUserRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested user exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$user = $this->route()->parameter('user');
|
||||
|
||||
return $user instanceof User && $user->exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the validation rules for this request.
|
||||
*
|
||||
* @param array|null $rules
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
$userId = $this->route()->parameter('user')->id;
|
||||
$userId = $this->getModel(User::class)->id;
|
||||
|
||||
return collect(User::getUpdateRulesForId($userId))->only([
|
||||
'external_id',
|
||||
'email',
|
||||
'username',
|
||||
'name_first',
|
||||
'name_last',
|
||||
'password',
|
||||
'language',
|
||||
'root_admin',
|
||||
])->toArray();
|
||||
return parent::rules(User::getUpdateRulesForId($userId));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue