Fix bad API behavior
This commit is contained in:
parent
d4d9eda57a
commit
2ec76d283b
|
@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa
|
||||||
|
|
||||||
This project follows [Semantic Versioning](http://semver.org) guidelines.
|
This project follows [Semantic Versioning](http://semver.org) guidelines.
|
||||||
|
|
||||||
|
## v0.7.0-rc.3 (Derelict Dermodactylus)
|
||||||
|
### Fixed
|
||||||
|
* `[rc.2]` — Fixes bad API behavior on `/user` routes.
|
||||||
|
|
||||||
## v0.7.0-rc.2 (Derelict Dermodactylus)
|
## v0.7.0-rc.2 (Derelict Dermodactylus)
|
||||||
### Fixed
|
### Fixed
|
||||||
* `[rc.1]` — Fixes exception thrown when revoking user sessions.
|
* `[rc.1]` — Fixes exception thrown when revoking user sessions.
|
||||||
|
|
|
@ -10,7 +10,6 @@ use Pterodactyl\Services\Users\UserCreationService;
|
||||||
use Pterodactyl\Services\Users\UserDeletionService;
|
use Pterodactyl\Services\Users\UserDeletionService;
|
||||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||||
use Pterodactyl\Transformers\Api\Application\UserTransformer;
|
use Pterodactyl\Transformers\Api\Application\UserTransformer;
|
||||||
use Pterodactyl\Http\Requests\Api\Application\Users\GetUserRequest;
|
|
||||||
use Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest;
|
use Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest;
|
||||||
use Pterodactyl\Http\Requests\Api\Application\Users\StoreUserRequest;
|
use Pterodactyl\Http\Requests\Api\Application\Users\StoreUserRequest;
|
||||||
use Pterodactyl\Http\Requests\Api\Application\Users\DeleteUserRequest;
|
use Pterodactyl\Http\Requests\Api\Application\Users\DeleteUserRequest;
|
||||||
|
@ -82,10 +81,10 @@ class UserController extends ApplicationApiController
|
||||||
* Handle a request to view a single user. Includes any relations that
|
* Handle a request to view a single user. Includes any relations that
|
||||||
* were defined in the request.
|
* were defined in the request.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Http\Requests\Api\Application\Users\GetUserRequest $request
|
* @param \Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest $request
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function view(GetUserRequest $request): array
|
public function view(GetUsersRequest $request): array
|
||||||
{
|
{
|
||||||
return $this->fractal->item($request->getModel(User::class))
|
return $this->fractal->item($request->getModel(User::class))
|
||||||
->transformWith($this->getTransformer(UserTransformer::class))
|
->transformWith($this->getTransformer(UserTransformer::class))
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Closure;
|
||||||
use Pterodactyl\Models\Egg;
|
use Pterodactyl\Models\Egg;
|
||||||
use Pterodactyl\Models\Nest;
|
use Pterodactyl\Models\Nest;
|
||||||
use Pterodactyl\Models\Node;
|
use Pterodactyl\Models\Node;
|
||||||
|
use Pterodactyl\Models\User;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Pterodactyl\Models\Database;
|
use Pterodactyl\Models\Database;
|
||||||
use Pterodactyl\Models\Location;
|
use Pterodactyl\Models\Location;
|
||||||
|
@ -28,6 +29,7 @@ class ApiSubstituteBindings extends SubstituteBindings
|
||||||
'nest' => Nest::class,
|
'nest' => Nest::class,
|
||||||
'node' => Node::class,
|
'node' => Node::class,
|
||||||
'server' => Server::class,
|
'server' => Server::class,
|
||||||
|
'user' => User::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,19 +6,6 @@ use Pterodactyl\Models\Node;
|
||||||
|
|
||||||
class UpdateNodeRequest extends StoreNodeRequest
|
class UpdateNodeRequest extends StoreNodeRequest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Determine if the node being requested for editing exists
|
|
||||||
* on the Panel before validating the data.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function resourceExists(): bool
|
|
||||||
{
|
|
||||||
$node = $this->route()->parameter('node');
|
|
||||||
|
|
||||||
return $node instanceof Node && $node->exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply validation rules to this request. Uses the parent class rules()
|
* Apply validation rules to this request. Uses the parent class rules()
|
||||||
* function but passes in the rules for updating rather than creating.
|
* function but passes in the rules for updating rather than creating.
|
||||||
|
@ -28,7 +15,7 @@ class UpdateNodeRequest extends StoreNodeRequest
|
||||||
*/
|
*/
|
||||||
public function rules(array $rules = null): array
|
public function rules(array $rules = null): array
|
||||||
{
|
{
|
||||||
$nodeId = $this->route()->parameter('node')->id;
|
$nodeId = $this->getModel(Node::class)->id;
|
||||||
|
|
||||||
return parent::rules(Node::getUpdateRulesForId($nodeId));
|
return parent::rules(Node::getUpdateRulesForId($nodeId));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
* Return the validation rules for this request.
|
||||||
*
|
*
|
||||||
|
* @param array|null $rules
|
||||||
* @return array
|
* @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',
|
'external_id',
|
||||||
'email',
|
'email',
|
||||||
'username',
|
'username',
|
||||||
'name_first',
|
|
||||||
'name_last',
|
|
||||||
'password',
|
'password',
|
||||||
'language',
|
'language',
|
||||||
'root_admin',
|
'root_admin',
|
||||||
])->toArray();
|
])->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
|
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.
|
* Return the validation rules for this request.
|
||||||
*
|
*
|
||||||
|
* @param array|null $rules
|
||||||
* @return array
|
* @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([
|
return parent::rules(User::getUpdateRulesForId($userId));
|
||||||
'external_id',
|
|
||||||
'email',
|
|
||||||
'username',
|
|
||||||
'name_first',
|
|
||||||
'name_last',
|
|
||||||
'password',
|
|
||||||
'language',
|
|
||||||
'root_admin',
|
|
||||||
])->toArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,14 +25,27 @@ class UserTransformer extends BaseTransformer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic transformed subuser array.
|
* Return a transformed User model that can be consumed by external services.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Models\User $user
|
* @param \Pterodactyl\Models\User $user
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function transform(User $user): array
|
public function transform(User $user): array
|
||||||
{
|
{
|
||||||
return $user->toArray();
|
return [
|
||||||
|
'id' => $user->id,
|
||||||
|
'external_id' => $user->external_id,
|
||||||
|
'uuid' => $user->uuid,
|
||||||
|
'username' => $user->username,
|
||||||
|
'email' => $user->email,
|
||||||
|
'first_name' => $user->name_first,
|
||||||
|
'last_name' => $user->name_last,
|
||||||
|
'language' => $user->language,
|
||||||
|
'root_admin' => (bool) $user->root_admin,
|
||||||
|
'2fa' => (bool) $user->use_totp,
|
||||||
|
'created_at' => $this->formatTimestamp($user->created_at),
|
||||||
|
'updated_at' => $this->formatTimestamp($user->updated_at),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class AllowTextInUserExternalId extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('external_id')->nullable()->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->unsignedInteger('external_id')->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,7 @@
|
||||||
*/
|
*/
|
||||||
Route::group(['prefix' => '/users'], function () {
|
Route::group(['prefix' => '/users'], function () {
|
||||||
Route::get('/', 'Users\UserController@index')->name('api.application.users');
|
Route::get('/', 'Users\UserController@index')->name('api.application.users');
|
||||||
Route::get('/{user}', 'Users\UserController@view')->name('api.applications.users.view');
|
Route::get('/{user}', 'Users\UserController@view')->name('api.application.users.view');
|
||||||
|
|
||||||
Route::post('/', 'Users\UserController@store');
|
Route::post('/', 'Users\UserController@store');
|
||||||
Route::patch('/{user}', 'Users\UserController@update');
|
Route::patch('/{user}', 'Users\UserController@update');
|
||||||
|
|
Loading…
Reference in New Issue