Make server listing and single server view API endpoints work

This commit is contained in:
Dane Everitt 2018-01-19 21:47:06 -06:00
parent 74bdbea6a4
commit a497a3d153
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
39 changed files with 367 additions and 176 deletions

View file

@ -0,0 +1,44 @@
<?php
namespace Pterodactyl\Extensions\Spatie\Fractalistic;
use Illuminate\Database\Eloquent\Model;
use League\Fractal\Serializer\JsonApiSerializer;
use Spatie\Fractalistic\Fractal as SpatieFractal;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
class Fractal extends SpatieFractal
{
/**
* Create fractal data.
*
* @return \League\Fractal\Scope
*
* @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
* @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified
*/
public function createData()
{
// Set the serializer by default.
if (is_null($this->serializer)) {
$this->serializer = new JsonApiSerializer;
}
// Automatically set the paginator on the response object if the
// data being provided implements a paginator.
if (is_null($this->paginator) && $this->data instanceof LengthAwarePaginator) {
$this->paginator = new IlluminatePaginatorAdapter($this->data);
}
// Automatically set the resource name if the response data is a model
// and the resource name is available on the model.
if (is_null($this->resourceName) && $this->data instanceof Model) {
if (defined(get_class($this->data) . '::RESOURCE_NAME')) {
$this->resourceName = constant(get_class($this->data) . '::RESOURCE_NAME');
}
}
return parent::createData();
}
}

View file

@ -14,7 +14,7 @@ use Pterodactyl\Services\Api\KeyCreationService;
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
use Pterodactyl\Http\Requests\Admin\Api\StoreApplicationApiKeyRequest;
class ApplicationApiController extends Controller
class ApiController extends Controller
{
/**
* @var \Prologue\Alerts\AlertsMessageBag

View file

@ -11,8 +11,8 @@ use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use Pterodactyl\Services\Locations\LocationUpdateService;
use Pterodactyl\Services\Locations\LocationCreationService;
use Pterodactyl\Services\Locations\LocationDeletionService;
use Pterodactyl\Transformers\Api\Admin\LocationTransformer;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\LocationTransformer;
use Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationsRequest;
use Pterodactyl\Http\Requests\Api\Application\Locations\DeleteLocationRequest;
use Pterodactyl\Http\Requests\Api\Application\Locations\UpdateLocationRequest;

View file

@ -8,11 +8,11 @@ use Illuminate\Http\Response;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Http\Controllers\Controller;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use Pterodactyl\Transformers\Api\Admin\AllocationTransformer;
use Pterodactyl\Services\Allocations\AllocationDeletionService;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\AllocationTransformer;
use Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest;
use Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequest;
use Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequestApplication;
class AllocationController extends Controller
{
@ -66,14 +66,14 @@ class AllocationController extends Controller
/**
* Delete a specific allocation from the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequest $request
* @param \Pterodactyl\Models\Node $node
* @param \Pterodactyl\Models\Allocation $allocation
* @param \Pterodactyl\Http\Requests\Api\Application\Allocations\DeleteAllocationRequestApplication $request
* @param \Pterodactyl\Models\Node $node
* @param \Pterodactyl\Models\Allocation $allocation
* @return \Illuminate\Http\Response
*
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
*/
public function delete(DeleteAllocationRequest $request, Node $node, Allocation $allocation): Response
public function delete(DeleteAllocationRequestApplication $request, Node $node, Allocation $allocation): Response
{
$this->deletionService->handle($allocation);

View file

@ -10,9 +10,9 @@ use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Nodes\NodeUpdateService;
use Pterodactyl\Services\Nodes\NodeCreationService;
use Pterodactyl\Services\Nodes\NodeDeletionService;
use Pterodactyl\Transformers\Api\Admin\NodeTransformer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\NodeTransformer;
use Pterodactyl\Http\Requests\Api\Application\Nodes\GetNodeRequest;
use Pterodactyl\Http\Requests\Api\Application\Nodes\GetNodesRequest;
use Pterodactyl\Http\Requests\Api\Application\Nodes\StoreNodeRequest;

View file

@ -1,20 +1,18 @@
<?php
namespace Pterodactyl\Http\Controllers\Api\Admin;
namespace Pterodactyl\Http\Controllers\Api\Application\Servers;
use Spatie\Fractal\Fractal;
use Illuminate\Http\Request;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Transformers\Api\Admin\ServerTransformer;
use Pterodactyl\Models\Server;
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
use Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest;
use Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
class ServerController extends Controller
class ServerController extends ApplicationApiController
{
/**
* @var \Spatie\Fractal\Fractal
*/
private $fractal;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
@ -23,22 +21,43 @@ class ServerController extends Controller
/**
* ServerController constructor.
*
* @param \Spatie\Fractal\Fractal $fractal
* @param \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal $fractal
* @param \Illuminate\Http\Request $request
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
*/
public function __construct(Fractal $fractal, ServerRepositoryInterface $repository)
public function __construct(Fractal $fractal, Request $request, ServerRepositoryInterface $repository)
{
$this->fractal = $fractal;
parent::__construct($fractal, $request);
$this->repository = $repository;
}
public function index(Request $request): array
/**
* Return all of the servers that currently exist on the Panel.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest $request
* @return array
*/
public function index(GetServersRequest $request): array
{
$servers = $this->repository->paginated(50);
$servers = $this->repository->setSearchTerm($request->input('search'))->paginated(50);
return $this->fractal->collection($servers)
->transformWith((new ServerTransformer)->setKey())
->withResourceName('server')
->transformWith($this->getTransformer(ServerTransformer::class))
->toArray();
}
/**
* Show a single server transformed for the application API.
*
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest $request
* @param \Pterodactyl\Models\Server $server
* @return array
*/
public function view(GetServerRequest $request, Server $server): array
{
return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class))
->toArray();
}
}

View file

@ -11,9 +11,9 @@ use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Services\Users\UserUpdateService;
use Pterodactyl\Services\Users\UserCreationService;
use Pterodactyl\Services\Users\UserDeletionService;
use Pterodactyl\Transformers\Api\Admin\UserTransformer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
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\StoreUserRequest;

View file

@ -5,9 +5,9 @@ namespace Pterodactyl\Http\Requests\Api\Application\Allocations;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class DeleteAllocationRequest extends ApiAdminRequest
class DeleteAllocationRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -4,9 +4,9 @@ namespace Pterodactyl\Http\Requests\Api\Application\Allocations;
use Pterodactyl\Models\Node;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class GetAllocationsRequest extends ApiAdminRequest
class GetAllocationsRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -8,7 +8,7 @@ use Illuminate\Foundation\Http\FormRequest;
use Pterodactyl\Exceptions\PterodactylException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
abstract class ApiAdminRequest extends FormRequest
abstract class ApplicationApiRequest extends FormRequest
{
/**
* The resource that should be checked when performing the authorization

View file

@ -4,9 +4,9 @@ namespace Pterodactyl\Http\Requests\Api\Application\Locations;
use Pterodactyl\Models\Location;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class DeleteLocationRequest extends ApiAdminRequest
class DeleteLocationRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -3,9 +3,9 @@
namespace Pterodactyl\Http\Requests\Api\Application\Locations;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class GetLocationsRequest extends ApiAdminRequest
class GetLocationsRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -4,9 +4,9 @@ namespace Pterodactyl\Http\Controllers\Api\Application\Locations;
use Pterodactyl\Models\Location;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class StoreLocationRequest extends ApiAdminRequest
class StoreLocationRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -4,9 +4,9 @@ namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
use Pterodactyl\Models\Node;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class DeleteNodeRequest extends ApiAdminRequest
class DeleteNodeRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -3,9 +3,8 @@
namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
use Pterodactyl\Models\Node;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
class GetNodeRequest extends ApiAdminRequest
class GetNodeRequest extends GetNodesRequest
{
/**
* Determine if the requested node exists on the Panel.

View file

@ -3,9 +3,9 @@
namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class GetNodesRequest extends ApiAdminRequest
class GetNodesRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -4,9 +4,9 @@ namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
use Pterodactyl\Models\Node;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class StoreNodeRequest extends ApiAdminRequest
class StoreNodeRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -0,0 +1,32 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Application\Servers;
use Pterodactyl\Models\Server;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class GetServerRequest extends ApplicationApiRequest
{
/**
* @var string
*/
protected $resource = AdminAcl::RESOURCE_SERVERS;
/**
* @var int
*/
protected $permission = AdminAcl::READ;
/**
* Determine if the requested server exists on the Panel.
*
* @return bool
*/
public function resourceExists(): bool
{
$server = $this->route()->parameter('server');
return $server instanceof Server && $server->exists;
}
}

View file

@ -0,0 +1,29 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Application\Servers;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class GetServersRequest extends ApplicationApiRequest
{
/**
* @var string
*/
protected $resource = AdminAcl::RESOURCE_SERVERS;
/**
* @var int
*/
protected $permission = AdminAcl::READ;
/**
* @return array
*/
public function rules(): array
{
return [
'search' => 'string|max:100',
];
}
}

View file

@ -4,9 +4,9 @@ namespace Pterodactyl\Http\Requests\Api\Application\Users;
use Pterodactyl\Models\User;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class DeleteUserRequest extends ApiAdminRequest
class DeleteUserRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -3,9 +3,9 @@
namespace Pterodactyl\Http\Requests\Api\Application\Users;
use Pterodactyl\Services\Acl\Api\AdminAcl as Acl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class GetUsersRequest extends ApiAdminRequest
class GetUsersRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -4,9 +4,9 @@ namespace Pterodactyl\Http\Requests\Api\Application\Users;
use Pterodactyl\Models\User;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApiAdminRequest;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class StoreUserRequest extends ApiAdminRequest
class StoreUserRequest extends ApplicationApiRequest
{
/**
* @var string

View file

@ -22,6 +22,12 @@ class Server extends Model implements CleansAttributes, ValidableContract
{
use BelongsToThrough, Eloquence, Notifiable, Validable;
/**
* The resource name for this model when it is transformed into an
* API representation using fractal.
*/
const RESOURCE_NAME = 'server';
/**
* The table associated with the model.
*

View file

@ -1,69 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Transformers\Admin;
use Illuminate\Http\Request;
use Pterodactyl\Models\ServerVariable;
use League\Fractal\TransformerAbstract;
class ServerVariableTransformer extends TransformerAbstract
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = ['parent'];
/**
* The Illuminate Request object if provided.
*
* @var \Illuminate\Http\Request|bool
*/
protected $request;
/**
* Setup request object for transformer.
*
* @param \Illuminate\Http\Request|bool $request
*/
public function __construct($request = false)
{
if (! $request instanceof Request && $request !== false) {
throw new DisplayException('Request passed to constructor must be of type Request or false.');
}
$this->request = $request;
}
/**
* Return a generic transformed server variable array.
*
* @return array
*/
public function transform(ServerVariable $variable)
{
return $variable->toArray();
}
/**
* Return the parent service variable data.
*
* @return \Leauge\Fractal\Resource\Item
*/
public function includeParent(ServerVariable $variable)
{
if ($this->request && ! $this->request->apiKeyHasPermission('option-view')) {
return;
}
return $this->item($variable->variable, new ServiceVariableTransformer($this->request), 'variable');
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Pterodactyl\Transformers\Api\Admin;
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Services\Acl\Api\AdminAcl;

View file

@ -1,6 +1,6 @@
<?php
namespace Pterodactyl\Transformers\Api\Admin;
namespace Pterodactyl\Transformers\Api\Application;
use Cake\Chronos\Chronos;
use Pterodactyl\Models\ApiKey;
@ -17,6 +17,17 @@ abstract class BaseTransformer extends TransformerAbstract
*/
private $key;
/**
* BaseTransformer constructor.
*/
public function __construct()
{
// Transformers allow for dependency injection on the handle method.
if (method_exists($this, 'handle')) {
Container::getInstance()->call([$this, 'handle']);
}
}
/**
* Set the HTTP request class being used for this request.
*
@ -59,11 +70,11 @@ abstract class BaseTransformer extends TransformerAbstract
*
* @param string $abstract
* @param array $parameters
* @return \Pterodactyl\Transformers\Api\Admin\BaseTransformer
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
*/
protected function makeTransformer(string $abstract, array $parameters = []): self
{
/** @var \Pterodactyl\Transformers\Api\Admin\BaseTransformer $transformer */
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
$transformer = Container::getInstance()->makeWith($abstract, $parameters);
$transformer->setKey($this->getKey());

View file

@ -0,0 +1,13 @@
<?php
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\EggVariable;
class EggVariableTransformer extends BaseTransformer
{
public function transform(EggVariable $model)
{
return $model->toArray();
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Pterodactyl\Transformers\Api\Admin;
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\Location;
use Pterodactyl\Services\Acl\Api\AdminAcl;

View file

@ -1,6 +1,6 @@
<?php
namespace Pterodactyl\Transformers\Api\Admin;
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\Node;
use Pterodactyl\Services\Acl\Api\AdminAcl;

View file

@ -1,14 +1,19 @@
<?php
namespace Pterodactyl\Transformers\Api\Admin;
namespace Pterodactyl\Transformers\Api\Application;
use Cake\Chronos\Chronos;
use Pterodactyl\Models\Server;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Transformers\Admin\PackTransformer;
use Pterodactyl\Transformers\Admin\ServerVariableTransformer;
use Pterodactyl\Services\Servers\EnvironmentService;
class ServerTransformer extends BaseTransformer
{
/**
* @var \Pterodactyl\Services\Servers\EnvironmentService
*/
private $environmentService;
/**
* List of resources that can be included.
*
@ -26,15 +31,55 @@ class ServerTransformer extends BaseTransformer
'node',
];
/**
* Perform dependency injection.
*
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
*/
public function handle(EnvironmentService $environmentService)
{
$this->environmentService = $environmentService;
}
/**
* Return a generic transformed server array.
*
* @param \Pterodactyl\Models\Server $server
* @return array
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function transform(Server $server): array
{
return collect($server->toArray())->only($server->getTableColumns())->toArray();
return [
'id' => $server->getKey(),
'uuid' => $server->uuid,
'identifier' => $server->uuidShort,
'name' => $server->name,
'description' => $server->description,
'suspended' => (bool) $server->suspended,
'limits' => [
'memory' => $server->memory,
'swap' => $server->swap,
'disk' => $server->disk,
'io' => $server->io,
'cpu' => $server->cpu,
],
'user' => $server->owner_id,
'node' => $server->node_id,
'allocation' => $server->allocation_id,
'nest' => $server->nest_id,
'egg' => $server->egg_id,
'pack' => $server->pack_id,
'container' => [
'startup_command' => $server->startup,
'image' => $server->image,
'installed' => (int) $server->installed === 1,
'environment' => $this->environmentService->handle($server),
],
'created_at' => Chronos::createFromFormat(Chronos::DEFAULT_TO_STRING_FORMAT, $server->created_at)->setTimezone('UTC')->toIso8601String(),
'updated_at' => Chronos::createFromFormat(Chronos::DEFAULT_TO_STRING_FORMAT, $server->updated_at)->setTimezone('UTC')->toIso8601String(),
];
}
/**
@ -94,16 +139,16 @@ class ServerTransformer extends BaseTransformer
* @param \Pterodactyl\Models\Server $server
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*/
public function includePack(Server $server)
{
if (! $this->authorize(AdminAcl::RESOURCE_PACKS)) {
return $this->null();
}
$server->loadMissing('pack');
return $this->item($server->getRelation('pack'), $this->makeTransformer(PackTransformer::class), 'pack');
}
// public function includePack(Server $server)
// {
// if (! $this->authorize(AdminAcl::RESOURCE_PACKS)) {
// return $this->null();
// }
//
// $server->loadMissing('pack');
//
// return $this->item($server->getRelation('pack'), $this->makeTransformer(PackTransformer::class), 'pack');
// }
/**
* Return a generic array with nest information for this server.
@ -111,16 +156,16 @@ class ServerTransformer extends BaseTransformer
* @param \Pterodactyl\Models\Server $server
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*/
public function includeNest(Server $server)
{
if (! $this->authorize(AdminAcl::RESOURCE_NESTS)) {
return $this->null();
}
$server->loadMissing('nest');
return $this->item($server->getRelation('nest'), $this->makeTransformer(NestTransformer::class), 'nest');
}
// public function includeNest(Server $server)
// {
// if (! $this->authorize(AdminAcl::RESOURCE_NESTS)) {
// return $this->null();
// }
//
// $server->loadMissing('nest');
//
// return $this->item($server->getRelation('nest'), $this->makeTransformer(NestTransformer::class), 'nest');
// }
/**
* Return a generic array with service option information for this server.
@ -136,14 +181,14 @@ class ServerTransformer extends BaseTransformer
$server->loadMissing('egg');
return $this->item($server->getRelation('egg'), $this->makeTransformer(EggTransformer::class), 'egg');
return $this->item($server->getRelation('egg'), $this->makeTransformer(EggVariableTransformer::class), 'egg');
}
/**
* Return a generic array of data about subusers for this server.
*
* @param \Pterodactyl\Models\Server $server
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
*/
public function includeVariables(Server $server)
{
@ -153,7 +198,7 @@ class ServerTransformer extends BaseTransformer
$server->loadMissing('variables');
return $this->item($server->getRelation('variables'), $this->makeTransformer(ServerVariableTransformer::class), 'server_variable');
return $this->collection($server->getRelation('variables'), $this->makeTransformer(ServerVariableTransformer::class), 'server_variable');
}
/**

View file

@ -0,0 +1,44 @@
<?php
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\ServerVariable;
use Pterodactyl\Services\Acl\Api\AdminAcl;
class ServerVariableTransformer extends BaseTransformer
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = ['parent'];
/**
* Return a generic transformed server variable array.
*
* @param \Pterodactyl\Models\ServerVariable $variable
* @return array
*/
public function transform(ServerVariable $variable)
{
return $variable->toArray();
}
/**
* Return the parent service variable data.
*
* @param \Pterodactyl\Models\ServerVariable $variable
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
*/
public function includeParent(ServerVariable $variable)
{
if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) {
return $this->null();
}
$variable->loadMissing('variable');
return $this->item($variable->getRelation('variable'), $this->makeTransformer(EggVariableTransformer::class), 'variable');
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Pterodactyl\Transformers\Api\Admin;
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\User;
use Pterodactyl\Services\Acl\Api\AdminAcl;

View file

@ -11,12 +11,12 @@ Route::get('/', 'BaseController@index')->name('admin.index');
|
*/
Route::group(['prefix' => 'api'], function () {
Route::get('/', 'ApplicationApiController@index')->name('admin.api.index');
Route::get('/new', 'ApplicationApiController@create')->name('admin.api.new');
Route::get('/', 'ApiController@index')->name('admin.api.index');
Route::get('/new', 'ApiController@create')->name('admin.api.new');
Route::post('/new', 'ApplicationApiController@store');
Route::post('/new', 'ApiController@store');
Route::delete('/revoke/{identifier}', 'ApplicationApiController@delete')->name('admin.api.delete');
Route::delete('/revoke/{identifier}', 'ApiController@delete')->name('admin.api.delete');
});
/*

View file

@ -2,6 +2,7 @@
use Pterodactyl\Models\Node;
use Pterodactyl\Models\User;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Location;
use Pterodactyl\Models\Allocation;
@ -18,13 +19,13 @@ Route::group(['prefix' => '/users'], function () {
return User::find($value) ?? new User;
});
Route::get('/', 'Users\UserController@index')->name('api.admin.user.list');
Route::get('/{user}', 'Users\UserController@view')->name('api.admin.user.view');
Route::get('/', 'Users\UserController@index')->name('api.application.users');
Route::get('/{user}', 'Users\UserController@view')->name('api.applications.users.view');
Route::post('/', 'Users\UserController@store')->name('api.admin.user.store');
Route::patch('/{user}', 'Users\UserController@update')->name('api.admin.user.update');
Route::post('/', 'Users\UserController@store');
Route::patch('/{user}', 'Users\UserController@update');
Route::delete('/{user}', 'Users\UserController@delete')->name('api.admin.user.delete');
Route::delete('/{user}', 'Users\UserController@delete');
});
/*
@ -40,22 +41,22 @@ Route::group(['prefix' => '/nodes'], function () {
return Node::find($value) ?? new Node;
});
Route::get('/', 'Nodes\NodeController@index')->name('api.admin.node.list');
Route::get('/{node}', 'Nodes\NodeController@view')->name('api.admin.node.view');
Route::get('/', 'Nodes\NodeController@index')->name('api.application.nodes');
Route::get('/{node}', 'Nodes\NodeController@view')->name('api.application.nodes.view');
Route::post('/', 'Nodes\NodeController@store')->name('api.admin.node.store');
Route::patch('/{node}', 'Nodes\NodeController@update')->name('api.admin.node.update');
Route::post('/', 'Nodes\NodeController@store');
Route::patch('/{node}', 'Nodes\NodeController@update');
Route::delete('/{node}', 'Nodes\NodeController@delete')->name('api.admin.node.delete');
Route::delete('/{node}', 'Nodes\NodeController@delete');
Route::group(['prefix' => '/{node}/allocations'], function () {
Route::bind('allocation', function ($value) {
return Allocation::find($value) ?? new Allocation;
});
Route::get('/', 'Nodes\AllocationController@index')->name('api.admin.node.allocations.list');
Route::get('/', 'Nodes\AllocationController@index')->name('api.application.allocations');
Route::delete('/{allocation}', 'Nodes\AllocationController@delete')->name('api.admin.node.allocations.delete');
Route::delete('/{allocation}', 'Nodes\AllocationController@delete')->name('api.application.allocations.view');
});
});
@ -72,11 +73,28 @@ Route::group(['prefix' => '/locations'], function () {
return Location::find($value) ?? new Location;
});
Route::get('/', 'Locations\LocationController@index')->name('api.admin.location.list');
Route::get('/{location}', 'Locations\LocationController@view')->name('api.admin.location.view');
Route::get('/', 'Locations\LocationController@index')->name('api.applications.locations');
Route::get('/{location}', 'Locations\LocationController@view')->name('api.application.locations.view');
Route::post('/', 'Locations\LocationController@store')->name('api.admin.location.store');
Route::patch('/{location}', 'Locations\LocationController@update')->name('api.admin.location.update');
Route::post('/', 'Locations\LocationController@store');
Route::patch('/{location}', 'Locations\LocationController@update');
Route::delete('/{location}', 'Locations\LocationController@delete')->name('api.admin.location.delete');
Route::delete('/{location}', 'Locations\LocationController@delete');
});
/*
|--------------------------------------------------------------------------
| Location Controller Routes
|--------------------------------------------------------------------------
|
| Endpoint: /api/application/servers
|
*/
Route::group(['prefix' => '/servers'], function () {
Route::bind('location', function ($value) {
return Server::find($value) ?? new Location;
});
Route::get('/', 'Servers\ServerController@index')->name('api.application.servers');
Route::get('/{server}', 'Servers\ServerController@view')->name('api.application.servers');
});