Remove old application API base transformer
This commit is contained in:
parent
cf500a1a54
commit
5c81f820d8
19 changed files with 101 additions and 468 deletions
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Pterodactyl\Exceptions\Transformer;
|
|
||||||
|
|
||||||
use Pterodactyl\Exceptions\PterodactylException;
|
|
||||||
|
|
||||||
class InvalidTransformerLevelException extends PterodactylException
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -3,17 +3,16 @@
|
||||||
namespace Pterodactyl\Http\Controllers\Api\Application;
|
namespace Pterodactyl\Http\Controllers\Api\Application;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Webmozart\Assert\Assert;
|
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Container\Container;
|
use Illuminate\Container\Container;
|
||||||
use Pterodactyl\Http\Controllers\Controller;
|
use Pterodactyl\Http\Controllers\Controller;
|
||||||
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
|
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
|
||||||
use Pterodactyl\Transformers\Api\Application\BaseTransformer;
|
|
||||||
|
|
||||||
abstract class ApplicationApiController extends Controller
|
abstract class ApplicationApiController extends Controller
|
||||||
{
|
{
|
||||||
protected Request $request;
|
protected Request $request;
|
||||||
|
|
||||||
protected Fractal $fractal;
|
protected Fractal $fractal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +47,7 @@ abstract class ApplicationApiController extends Controller
|
||||||
/**
|
/**
|
||||||
* Return an instance of an application transformer.
|
* Return an instance of an application transformer.
|
||||||
*
|
*
|
||||||
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
|
* @return \Pterodactyl\Transformers\Api\Transformer
|
||||||
*
|
*
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||||
*
|
*
|
||||||
|
@ -56,12 +55,7 @@ abstract class ApplicationApiController extends Controller
|
||||||
*/
|
*/
|
||||||
public function getTransformer(string $abstract)
|
public function getTransformer(string $abstract)
|
||||||
{
|
{
|
||||||
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
|
return new $abstract;
|
||||||
$transformer = Container::getInstance()->make($abstract);
|
|
||||||
|
|
||||||
Assert::isInstanceOf($transformer, BaseTransformer::class);
|
|
||||||
|
|
||||||
return $transformer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,25 +3,15 @@
|
||||||
namespace Pterodactyl\Transformers\Api\Application;
|
namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\AdminRole;
|
use Pterodactyl\Models\AdminRole;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class AdminRoleTransformer extends BaseTransformer
|
class AdminRoleTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return AdminRole::RESOURCE_NAME;
|
return AdminRole::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a transformed AdminRole model that can be consumed by external services.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Models\AdminRole $model
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function transform(AdminRole $model): array
|
public function transform(AdminRole $model): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Transformers\Api\Application;
|
namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Node;
|
|
||||||
use Pterodactyl\Models\Server;
|
|
||||||
use Pterodactyl\Models\Allocation;
|
use Pterodactyl\Models\Allocation;
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class AllocationTransformer extends BaseTransformer
|
class AllocationTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Relationships that can be loaded onto allocation transformations.
|
* Relationships that can be loaded onto allocation transformations.
|
||||||
|
@ -16,24 +15,12 @@ class AllocationTransformer extends BaseTransformer
|
||||||
*/
|
*/
|
||||||
protected $availableIncludes = ['node', 'server'];
|
protected $availableIncludes = ['node', 'server'];
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Allocation::RESOURCE_NAME;
|
return Allocation::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function transform(Allocation $model): array
|
||||||
* Return a generic transformed allocation array.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Models\Allocation $model
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function transform(Allocation $model)
|
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $model->id,
|
'id' => $model->id,
|
||||||
|
@ -41,7 +28,7 @@ class AllocationTransformer extends BaseTransformer
|
||||||
'alias' => $model->ip_alias,
|
'alias' => $model->ip_alias,
|
||||||
'port' => $model->port,
|
'port' => $model->port,
|
||||||
'notes' => $model->notes,
|
'notes' => $model->notes,
|
||||||
'assigned' => ! is_null($model->server_id),
|
'assigned' => !is_null($model->server_id),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,18 +38,14 @@ class AllocationTransformer extends BaseTransformer
|
||||||
* @param \Pterodactyl\Models\Allocation $allocation
|
* @param \Pterodactyl\Models\Allocation $allocation
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
*/
|
*/
|
||||||
public function includeNode(Allocation $allocation)
|
public function includeNode(Allocation $allocation)
|
||||||
{
|
{
|
||||||
if (! $this->authorize(AdminAcl::RESOURCE_NODES)) {
|
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->item(
|
return $this->item($allocation->node, new NodeTransformer());
|
||||||
$allocation->node, $this->makeTransformer(NodeTransformer::class), Node::RESOURCE_NAME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,17 +54,13 @@ class AllocationTransformer extends BaseTransformer
|
||||||
* @param \Pterodactyl\Models\Allocation $allocation
|
* @param \Pterodactyl\Models\Allocation $allocation
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
*/
|
*/
|
||||||
public function includeServer(Allocation $allocation)
|
public function includeServer(Allocation $allocation)
|
||||||
{
|
{
|
||||||
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS) || ! $allocation->server) {
|
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS) || !$allocation->server) {
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->item(
|
return $this->item($allocation->server, new ServerTransformer());
|
||||||
$allocation->server, $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Pterodactyl\Transformers\Api\Application;
|
|
||||||
|
|
||||||
use Illuminate\Container\Container;
|
|
||||||
use Pterodactyl\Transformers\Api\Transformer;
|
|
||||||
use Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException;
|
|
||||||
|
|
||||||
abstract class BaseTransformer extends Transformer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create a new instance of the transformer and pass along the currently
|
|
||||||
* set API key.
|
|
||||||
*
|
|
||||||
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
|
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
|
||||||
protected function makeTransformer(string $abstract, array $parameters = [])
|
|
||||||
{
|
|
||||||
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
|
|
||||||
$transformer = Container::getInstance()->makeWith($abstract, $parameters);
|
|
||||||
|
|
||||||
if (!$transformer instanceof self) {
|
|
||||||
throw new InvalidTransformerLevelException('Calls to ' . __METHOD__ . ' must return a transformer that is an instance of ' . __CLASS__);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $transformer;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Transformers\Api\Application;
|
namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Database;
|
|
||||||
use Pterodactyl\Models\DatabaseHost;
|
use Pterodactyl\Models\DatabaseHost;
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class DatabaseHostTransformer extends BaseTransformer
|
class DatabaseHostTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -15,23 +15,12 @@ class DatabaseHostTransformer extends BaseTransformer
|
||||||
'databases',
|
'databases',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return DatabaseHost::RESOURCE_NAME;
|
return DatabaseHost::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function transform(DatabaseHost $model): array
|
||||||
* Transform database host into a representation for the application API.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Models\DatabaseHost $model
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function transform(DatabaseHost $model)
|
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $model->id,
|
'id' => $model->id,
|
||||||
|
@ -40,8 +29,8 @@ class DatabaseHostTransformer extends BaseTransformer
|
||||||
'port' => $model->port,
|
'port' => $model->port,
|
||||||
'username' => $model->username,
|
'username' => $model->username,
|
||||||
'node' => $model->node_id,
|
'node' => $model->node_id,
|
||||||
'created_at' => $model->created_at->toIso8601String(),
|
'created_at' => self::formatTimestamp($model->created_at),
|
||||||
'updated_at' => $model->updated_at->toIso8601String(),
|
'updated_at' => self::formatTimestamp($model->updated_at),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +38,6 @@ class DatabaseHostTransformer extends BaseTransformer
|
||||||
* Include the databases associated with this host.
|
* Include the databases associated with this host.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeDatabases(DatabaseHost $model)
|
public function includeDatabases(DatabaseHost $model)
|
||||||
{
|
{
|
||||||
|
@ -59,8 +45,6 @@ class DatabaseHostTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->loadMissing('databases');
|
return $this->collection($model->databases, new ServerDatabaseTransformer());
|
||||||
|
|
||||||
return $this->collection($model->getRelation('databases'), $this->makeTransformer(ServerDatabaseTransformer::class), Database::RESOURCE_NAME);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
namespace Pterodactyl\Transformers\Api\Application;
|
namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Egg;
|
use Pterodactyl\Models\Egg;
|
||||||
use Pterodactyl\Models\Nest;
|
|
||||||
use Pterodactyl\Models\Server;
|
|
||||||
use Pterodactyl\Models\EggVariable;
|
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class EggTransformer extends BaseTransformer
|
class EggTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Relationships that can be loaded onto this transformation.
|
* Relationships that can be loaded onto this transformation.
|
||||||
|
@ -23,21 +21,12 @@ class EggTransformer extends BaseTransformer
|
||||||
'variables',
|
'variables',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Egg::RESOURCE_NAME;
|
return Egg::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function transform(Egg $model): array
|
||||||
* Transform an Egg model into a representation that can be consumed by
|
|
||||||
* the application api.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function transform(Egg $model)
|
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $model->id,
|
'id' => $model->id,
|
||||||
|
@ -67,8 +56,8 @@ class EggTransformer extends BaseTransformer
|
||||||
'container' => $model->script_container,
|
'container' => $model->script_container,
|
||||||
'extends' => $model->copy_script_from,
|
'extends' => $model->copy_script_from,
|
||||||
],
|
],
|
||||||
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
|
'created_at' => self::formatTimestamp($model->created_at),
|
||||||
$model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at),
|
'updated_at' => self::formatTimestamp($model->updated_at),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,8 +65,6 @@ class EggTransformer extends BaseTransformer
|
||||||
* Include the Nest relationship for the given Egg in the transformation.
|
* Include the Nest relationship for the given Egg in the transformation.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeNest(Egg $model)
|
public function includeNest(Egg $model)
|
||||||
{
|
{
|
||||||
|
@ -85,17 +72,13 @@ class EggTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->loadMissing('nest');
|
return $this->item($model->nest, new NestTransformer());
|
||||||
|
|
||||||
return $this->item($model->getRelation('nest'), $this->makeTransformer(NestTransformer::class), Nest::RESOURCE_NAME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include the Servers relationship for the given Egg in the transformation.
|
* Include the Servers relationship for the given Egg in the transformation.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeServers(Egg $model)
|
public function includeServers(Egg $model)
|
||||||
{
|
{
|
||||||
|
@ -103,9 +86,7 @@ class EggTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->loadMissing('servers');
|
return $this->collection($model->servers, new ServerTransformer());
|
||||||
|
|
||||||
return $this->collection($model->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,8 +101,6 @@ class EggTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->loadMissing('configFrom');
|
|
||||||
|
|
||||||
return $this->item($model, function (Egg $model) {
|
return $this->item($model, function (Egg $model) {
|
||||||
return [
|
return [
|
||||||
'files' => json_decode($model->inherit_config_files),
|
'files' => json_decode($model->inherit_config_files),
|
||||||
|
@ -144,8 +123,6 @@ class EggTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->loadMissing('scriptFrom');
|
|
||||||
|
|
||||||
return $this->item($model, function (Egg $model) {
|
return $this->item($model, function (Egg $model) {
|
||||||
return [
|
return [
|
||||||
'privileged' => $model->script_is_privileged,
|
'privileged' => $model->script_is_privileged,
|
||||||
|
@ -160,8 +137,6 @@ class EggTransformer extends BaseTransformer
|
||||||
* Include the variables that are defined for this Egg.
|
* Include the variables that are defined for this Egg.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeVariables(Egg $model)
|
public function includeVariables(Egg $model)
|
||||||
{
|
{
|
||||||
|
@ -169,12 +144,6 @@ class EggTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->loadMissing('variables');
|
return $this->collection($model->variables, new EggVariableTransformer());
|
||||||
|
|
||||||
return $this->collection(
|
|
||||||
$model->getRelation('variables'),
|
|
||||||
$this->makeTransformer(EggVariableTransformer::class),
|
|
||||||
EggVariable::RESOURCE_NAME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,18 +4,16 @@ namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Egg;
|
use Pterodactyl\Models\Egg;
|
||||||
use Pterodactyl\Models\EggVariable;
|
use Pterodactyl\Models\EggVariable;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class EggVariableTransformer extends BaseTransformer
|
class EggVariableTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Egg::RESOURCE_NAME;
|
return Egg::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transform(EggVariable $model)
|
public function transform(EggVariable $model): array
|
||||||
{
|
{
|
||||||
return $model->toArray();
|
return $model->toArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,9 @@ namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Location;
|
use Pterodactyl\Models\Location;
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class LocationTransformer extends BaseTransformer
|
class LocationTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* List of resources that can be included.
|
* List of resources that can be included.
|
||||||
|
@ -14,17 +15,11 @@ class LocationTransformer extends BaseTransformer
|
||||||
*/
|
*/
|
||||||
protected $availableIncludes = ['nodes', 'servers'];
|
protected $availableIncludes = ['nodes', 'servers'];
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Location::RESOURCE_NAME;
|
return Location::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a generic transformed location array.
|
|
||||||
*/
|
|
||||||
public function transform(Location $model): array
|
public function transform(Location $model): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -40,9 +35,6 @@ class LocationTransformer extends BaseTransformer
|
||||||
* Return the servers associated with this location.
|
* Return the servers associated with this location.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeServers(Location $location)
|
public function includeServers(Location $location)
|
||||||
{
|
{
|
||||||
|
@ -50,18 +42,13 @@ class LocationTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$location->loadMissing('servers');
|
return $this->collection($location->servers, new ServerTransformer());
|
||||||
|
|
||||||
return $this->collection($location->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the nodes associated with this location.
|
* Return the nodes associated with this location.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeNodes(Location $location)
|
public function includeNodes(Location $location)
|
||||||
{
|
{
|
||||||
|
@ -69,8 +56,6 @@ class LocationTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$location->loadMissing('nodes');
|
return $this->collection($location->nodes, new NodeTransformer());
|
||||||
|
|
||||||
return $this->collection($location->getRelation('nodes'), $this->makeTransformer(NodeTransformer::class), 'node');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,11 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Transformers\Api\Application;
|
namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Egg;
|
|
||||||
use Pterodactyl\Models\Node;
|
|
||||||
use Pterodactyl\Models\Mount;
|
use Pterodactyl\Models\Mount;
|
||||||
use Pterodactyl\Models\Server;
|
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class MountTransformer extends BaseTransformer
|
class MountTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* List of resources that can be included.
|
* List of resources that can be included.
|
||||||
|
@ -17,22 +15,11 @@ class MountTransformer extends BaseTransformer
|
||||||
*/
|
*/
|
||||||
protected $availableIncludes = ['eggs', 'nodes', 'servers'];
|
protected $availableIncludes = ['eggs', 'nodes', 'servers'];
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Mount::RESOURCE_NAME;
|
return Mount::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a transformed Mount model that can be consumed by external services.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Models\Mount $model
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function transform(Mount $model): array
|
public function transform(Mount $model): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -50,72 +37,42 @@ class MountTransformer extends BaseTransformer
|
||||||
/**
|
/**
|
||||||
* Return the eggs associated with this mount.
|
* Return the eggs associated with this mount.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Models\Mount $mount
|
|
||||||
*
|
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
*/
|
*/
|
||||||
public function includeEggs(Mount $mount)
|
public function includeEggs(Mount $mount)
|
||||||
{
|
{
|
||||||
if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$mount->loadMissing('eggs');
|
return $this->collection($mount->eggs, new EggTransformer());
|
||||||
|
|
||||||
return $this->collection(
|
|
||||||
$mount->getRelation('eggs'),
|
|
||||||
$this->makeTransformer(EggTransformer::class),
|
|
||||||
Egg::RESOURCE_NAME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the nodes associated with this mount.
|
* Return the nodes associated with this mount.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Models\Mount $mount
|
|
||||||
*
|
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
*/
|
*/
|
||||||
public function includeNodes(Mount $mount)
|
public function includeNodes(Mount $mount)
|
||||||
{
|
{
|
||||||
if (! $this->authorize(AdminAcl::RESOURCE_NODES)) {
|
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$mount->loadMissing('nodes');
|
return $this->collection($mount->nodes, new NodeTransformer());
|
||||||
|
|
||||||
return $this->collection(
|
|
||||||
$mount->getRelation('nodes'),
|
|
||||||
$this->makeTransformer(NodeTransformer::class),
|
|
||||||
Node::RESOURCE_NAME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the servers associated with this mount.
|
* Return the servers associated with this mount.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Models\Mount $mount
|
|
||||||
*
|
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
*/
|
*/
|
||||||
public function includeServers(Mount $mount)
|
public function includeServers(Mount $mount)
|
||||||
{
|
{
|
||||||
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$mount->loadMissing('servers');
|
return $this->collection($mount->servers, new ServerTransformer());
|
||||||
|
|
||||||
return $this->collection(
|
|
||||||
$mount->getRelation('servers'),
|
|
||||||
$this->makeTransformer(ServerTransformer::class),
|
|
||||||
Server::RESOURCE_NAME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Transformers\Api\Application;
|
namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Egg;
|
|
||||||
use Pterodactyl\Models\Nest;
|
use Pterodactyl\Models\Nest;
|
||||||
use Pterodactyl\Models\Server;
|
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class NestTransformer extends BaseTransformer
|
class NestTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Relationships that can be loaded onto this transformation.
|
* Relationships that can be loaded onto this transformation.
|
||||||
|
@ -15,29 +14,21 @@ class NestTransformer extends BaseTransformer
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $availableIncludes = [
|
protected $availableIncludes = [
|
||||||
'eggs', 'servers',
|
'eggs',
|
||||||
|
'servers',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Nest::RESOURCE_NAME;
|
return Nest::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function transform(Nest $model): array
|
||||||
* Transform a Nest model into a representation that can be consumed by the
|
|
||||||
* application API.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function transform(Nest $model)
|
|
||||||
{
|
{
|
||||||
$response = $model->toArray();
|
$response = $model->toArray();
|
||||||
|
|
||||||
$response[$model->getUpdatedAtColumn()] = $this->formatTimestamp($model->updated_at);
|
$response[$model->getUpdatedAtColumn()] = self::formatTimestamp($model->updated_at);
|
||||||
$response[$model->getCreatedAtColumn()] = $this->formatTimestamp($model->created_at);
|
$response[$model->getCreatedAtColumn()] = self::formatTimestamp($model->created_at);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
@ -46,8 +37,6 @@ class NestTransformer extends BaseTransformer
|
||||||
* Include the Eggs relationship on the given Nest model transformation.
|
* Include the Eggs relationship on the given Nest model transformation.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeEggs(Nest $model)
|
public function includeEggs(Nest $model)
|
||||||
{
|
{
|
||||||
|
@ -55,17 +44,13 @@ class NestTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->loadMissing('eggs');
|
return $this->collection($model->eggs, new EggTransformer());
|
||||||
|
|
||||||
return $this->collection($model->getRelation('eggs'), $this->makeTransformer(EggTransformer::class), Egg::RESOURCE_NAME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include the servers relationship on the given Nest model.
|
* Include the servers relationship on the given Nest model.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeServers(Nest $model)
|
public function includeServers(Nest $model)
|
||||||
{
|
{
|
||||||
|
@ -73,8 +58,6 @@ class NestTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->loadMissing('servers');
|
return $this->collection($model->servers, new ServerTransformer());
|
||||||
|
|
||||||
return $this->collection($model->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
namespace Pterodactyl\Transformers\Api\Application;
|
namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Node;
|
use Pterodactyl\Models\Node;
|
||||||
use League\Fractal\Resource\NullResource;
|
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class NodeTransformer extends BaseTransformer
|
class NodeTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* List of resources that can be included.
|
* List of resources that can be included.
|
||||||
|
@ -15,18 +15,11 @@ class NodeTransformer extends BaseTransformer
|
||||||
*/
|
*/
|
||||||
protected $availableIncludes = ['allocations', 'database_host', 'location', 'mounts', 'servers'];
|
protected $availableIncludes = ['allocations', 'database_host', 'location', 'mounts', 'servers'];
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Node::RESOURCE_NAME;
|
return Node::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a node transformed into a format that can be consumed by the
|
|
||||||
* external administrative API.
|
|
||||||
*/
|
|
||||||
public function transform(Node $model): array
|
public function transform(Node $model): array
|
||||||
{
|
{
|
||||||
$response = $model->toArray();
|
$response = $model->toArray();
|
||||||
|
@ -48,9 +41,6 @@ class NodeTransformer extends BaseTransformer
|
||||||
* Return the allocations associated with this node.
|
* Return the allocations associated with this node.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeAllocations(Node $node)
|
public function includeAllocations(Node $node)
|
||||||
{
|
{
|
||||||
|
@ -58,50 +48,27 @@ class NodeTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$node->loadMissing('allocations');
|
return $this->collection($node->allocations, new AllocationTransformer());
|
||||||
|
|
||||||
return $this->collection(
|
|
||||||
$node->getRelation('allocations'),
|
|
||||||
$this->makeTransformer(AllocationTransformer::class),
|
|
||||||
'allocation'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the database host associated with this node.
|
* Return the database host associated with this node.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeDatabaseHost(Node $node)
|
public function includeDatabaseHost(Node $node)
|
||||||
{
|
{
|
||||||
if (!$this->authorize(AdminAcl::RESOURCE_DATABASE_HOSTS)) {
|
if (!$this->authorize(AdminAcl::RESOURCE_DATABASE_HOSTS) || is_null($node->databaseHost)) {
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$node->loadMissing('databaseHost');
|
return $this->item($node->databaseHost, new DatabaseHostTransformer());
|
||||||
|
|
||||||
$databaseHost = $node->getRelation('databaseHost');
|
|
||||||
if (is_null($databaseHost)) {
|
|
||||||
return new NullResource();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->item(
|
|
||||||
$node->getRelation('databaseHost'),
|
|
||||||
$this->makeTransformer(DatabaseHostTransformer::class),
|
|
||||||
'databaseHost'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the location associated with this node.
|
* Return the location associated with this node.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeLocation(Node $node)
|
public function includeLocation(Node $node)
|
||||||
{
|
{
|
||||||
|
@ -109,22 +76,13 @@ class NodeTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$node->loadMissing('location');
|
return $this->item($node->location, new LocationTransformer());
|
||||||
|
|
||||||
return $this->item(
|
|
||||||
$node->getRelation('location'),
|
|
||||||
$this->makeTransformer(LocationTransformer::class),
|
|
||||||
'location'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the mounts associated with this node.
|
* Return the mounts associated with this node.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeMounts(Node $node)
|
public function includeMounts(Node $node)
|
||||||
{
|
{
|
||||||
|
@ -132,22 +90,13 @@ class NodeTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$node->loadMissing('mounts');
|
return $this->collection($node->mounts, new MountTransformer());
|
||||||
|
|
||||||
return $this->collection(
|
|
||||||
$node->getRelation('mounts'),
|
|
||||||
$this->makeTransformer(MountTransformer::class),
|
|
||||||
'mount'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the servers associated with this node.
|
* Return the servers associated with this node.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeServers(Node $node)
|
public function includeServers(Node $node)
|
||||||
{
|
{
|
||||||
|
@ -155,12 +104,6 @@ class NodeTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$node->loadMissing('servers');
|
return $this->collection($node->servers, new ServerTransformer());
|
||||||
|
|
||||||
return $this->collection(
|
|
||||||
$node->getRelation('servers'),
|
|
||||||
$this->makeTransformer(ServerTransformer::class),
|
|
||||||
'server'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,39 +5,28 @@ namespace Pterodactyl\Transformers\Api\Application;
|
||||||
use Pterodactyl\Models\Database;
|
use Pterodactyl\Models\Database;
|
||||||
use Pterodactyl\Models\DatabaseHost;
|
use Pterodactyl\Models\DatabaseHost;
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
use Illuminate\Contracts\Encryption\Encrypter;
|
use Illuminate\Contracts\Encryption\Encrypter;
|
||||||
|
|
||||||
class ServerDatabaseTransformer extends BaseTransformer
|
class ServerDatabaseTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $availableIncludes = ['password', 'host'];
|
protected $availableIncludes = ['password', 'host'];
|
||||||
|
|
||||||
/**
|
protected Encrypter $encrypter;
|
||||||
* @var Encrypter
|
|
||||||
*/
|
|
||||||
private $encrypter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform dependency injection.
|
|
||||||
*/
|
|
||||||
public function handle(Encrypter $encrypter)
|
public function handle(Encrypter $encrypter)
|
||||||
{
|
{
|
||||||
$this->encrypter = $encrypter;
|
$this->encrypter = $encrypter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Database::RESOURCE_NAME;
|
return Database::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform a database model in a representation for the application API.
|
|
||||||
*/
|
|
||||||
public function transform(Database $model): array
|
public function transform(Database $model): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -48,8 +37,8 @@ class ServerDatabaseTransformer extends BaseTransformer
|
||||||
'username' => $model->username,
|
'username' => $model->username,
|
||||||
'remote' => $model->remote,
|
'remote' => $model->remote,
|
||||||
'max_connections' => $model->max_connections,
|
'max_connections' => $model->max_connections,
|
||||||
'created_at' => $model->created_at->toIso8601String(),
|
'created_at' => self::formatTimestamp($model->created_at),
|
||||||
'updated_at' => $model->updated_at->toIso8601String(),
|
'updated_at' => self::formatTimestamp($model->updated_at),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +60,6 @@ class ServerDatabaseTransformer extends BaseTransformer
|
||||||
* Return the database host relationship for this server database.
|
* Return the database host relationship for this server database.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeHost(Database $model)
|
public function includeHost(Database $model)
|
||||||
{
|
{
|
||||||
|
@ -80,12 +67,6 @@ class ServerDatabaseTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->loadMissing('host');
|
return $this->item($model->host, new DatabaseHostTransformer());
|
||||||
|
|
||||||
return $this->item(
|
|
||||||
$model->getRelation('host'),
|
|
||||||
$this->makeTransformer(DatabaseHostTransformer::class),
|
|
||||||
DatabaseHost::RESOURCE_NAME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,12 @@ namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
use Pterodactyl\Services\Servers\EnvironmentService;
|
use Pterodactyl\Services\Servers\EnvironmentService;
|
||||||
|
|
||||||
class ServerTransformer extends BaseTransformer
|
class ServerTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
protected EnvironmentService $environmentService;
|
||||||
* @var \Pterodactyl\Services\Servers\EnvironmentService
|
|
||||||
*/
|
|
||||||
private $environmentService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of resources that can be included.
|
* List of resources that can be included.
|
||||||
|
@ -31,25 +29,16 @@ class ServerTransformer extends BaseTransformer
|
||||||
'transfer',
|
'transfer',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform dependency injection.
|
|
||||||
*/
|
|
||||||
public function handle(EnvironmentService $environmentService)
|
public function handle(EnvironmentService $environmentService)
|
||||||
{
|
{
|
||||||
$this->environmentService = $environmentService;
|
$this->environmentService = $environmentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Server::RESOURCE_NAME;
|
return Server::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a generic transformed server array.
|
|
||||||
*/
|
|
||||||
public function transform(Server $model): array
|
public function transform(Server $model): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -83,8 +72,8 @@ class ServerTransformer extends BaseTransformer
|
||||||
'image' => $model->image,
|
'image' => $model->image,
|
||||||
'environment' => $this->environmentService->handle($model),
|
'environment' => $this->environmentService->handle($model),
|
||||||
],
|
],
|
||||||
$model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at),
|
'updated_at' => self::formatTimestamp($model->updated_at),
|
||||||
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
|
'created_at' => self::formatTimestamp($model->created_at),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +81,6 @@ class ServerTransformer extends BaseTransformer
|
||||||
* Return a generic array of allocations for this server.
|
* Return a generic array of allocations for this server.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeAllocations(Server $server)
|
public function includeAllocations(Server $server)
|
||||||
{
|
{
|
||||||
|
@ -101,17 +88,13 @@ class ServerTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server->loadMissing('allocations');
|
return $this->collection($server->allocations, new AllocationTransformer());
|
||||||
|
|
||||||
return $this->collection($server->getRelation('allocations'), $this->makeTransformer(AllocationTransformer::class), 'allocation');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic array of data about subusers for this server.
|
* Return a generic array of data about subusers for this server.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeSubusers(Server $server)
|
public function includeSubusers(Server $server)
|
||||||
{
|
{
|
||||||
|
@ -119,17 +102,13 @@ class ServerTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server->loadMissing('subusers');
|
return $this->collection($server->subusers, new SubuserTransformer());
|
||||||
|
|
||||||
return $this->collection($server->getRelation('subusers'), $this->makeTransformer(SubuserTransformer::class), 'subuser');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic array of data about subusers for this server.
|
* Return a generic array of data about subusers for this server.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeUser(Server $server)
|
public function includeUser(Server $server)
|
||||||
{
|
{
|
||||||
|
@ -137,17 +116,13 @@ class ServerTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server->loadMissing('user');
|
return $this->item($server->user, new UserTransformer());
|
||||||
|
|
||||||
return $this->item($server->getRelation('user'), $this->makeTransformer(UserTransformer::class), 'user');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic array with nest information for this server.
|
* Return a generic array with nest information for this server.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeNest(Server $server)
|
public function includeNest(Server $server)
|
||||||
{
|
{
|
||||||
|
@ -155,17 +130,13 @@ class ServerTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server->loadMissing('nest');
|
return $this->item($server->nest, new NestTransformer());
|
||||||
|
|
||||||
return $this->item($server->getRelation('nest'), $this->makeTransformer(NestTransformer::class), 'nest');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic array with egg information for this server.
|
* Return a generic array with egg information for this server.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeEgg(Server $server)
|
public function includeEgg(Server $server)
|
||||||
{
|
{
|
||||||
|
@ -173,17 +144,13 @@ class ServerTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server->loadMissing('egg');
|
return $this->item($server->egg, new EggTransformer());
|
||||||
|
|
||||||
return $this->item($server->getRelation('egg'), $this->makeTransformer(EggTransformer::class), 'egg');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic array of data about subusers for this server.
|
* Return a generic array of data about subusers for this server.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeVariables(Server $server)
|
public function includeVariables(Server $server)
|
||||||
{
|
{
|
||||||
|
@ -191,17 +158,13 @@ class ServerTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server->loadMissing('variables');
|
return $this->collection($server->variables, new ServerVariableTransformer());
|
||||||
|
|
||||||
return $this->collection($server->getRelation('variables'), $this->makeTransformer(ServerVariableTransformer::class), 'server_variable');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic array with location information for this server.
|
* Return a generic array with location information for this server.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeLocation(Server $server)
|
public function includeLocation(Server $server)
|
||||||
{
|
{
|
||||||
|
@ -209,17 +172,13 @@ class ServerTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server->loadMissing('location');
|
return $this->item($server->location, new LocationTransformer());
|
||||||
|
|
||||||
return $this->item($server->getRelation('location'), $this->makeTransformer(LocationTransformer::class), 'location');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic array with node information for this server.
|
* Return a generic array with node information for this server.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeNode(Server $server)
|
public function includeNode(Server $server)
|
||||||
{
|
{
|
||||||
|
@ -227,17 +186,13 @@ class ServerTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server->loadMissing('node');
|
return $this->item($server->node, new NodeTransformer());
|
||||||
|
|
||||||
return $this->item($server->getRelation('node'), $this->makeTransformer(NodeTransformer::class), 'node');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic array with database information for this server.
|
* Return a generic array with database information for this server.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeDatabases(Server $server)
|
public function includeDatabases(Server $server)
|
||||||
{
|
{
|
||||||
|
@ -245,8 +200,6 @@ class ServerTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server->loadMissing('databases');
|
return $this->collection($server->databases, new ServerDatabaseTransformer());
|
||||||
|
|
||||||
return $this->collection($server->getRelation('databases'), $this->makeTransformer(ServerDatabaseTransformer::class), 'databases');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
namespace Pterodactyl\Transformers\Api\Application;
|
namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\EggVariable;
|
use Pterodactyl\Models\EggVariable;
|
||||||
|
use Pterodactyl\Models\ServerVariable;
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class ServerVariableTransformer extends BaseTransformer
|
class ServerVariableTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* List of resources that can be included.
|
* List of resources that can be included.
|
||||||
|
@ -22,12 +24,7 @@ class ServerVariableTransformer extends BaseTransformer
|
||||||
return ServerVariable::RESOURCE_NAME;
|
return ServerVariable::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function transform(EggVariable $variable): array
|
||||||
* Return a generic transformed server variable array.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function transform(EggVariable $variable)
|
|
||||||
{
|
{
|
||||||
return $variable->toArray();
|
return $variable->toArray();
|
||||||
}
|
}
|
||||||
|
@ -36,8 +33,6 @@ class ServerVariableTransformer extends BaseTransformer
|
||||||
* Return the parent service variable data.
|
* Return the parent service variable data.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeParent(EggVariable $variable)
|
public function includeParent(EggVariable $variable)
|
||||||
{
|
{
|
||||||
|
@ -45,8 +40,6 @@ class ServerVariableTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$variable->loadMissing('variable');
|
return $this->item($variable->variable, new EggVariableTransformer());
|
||||||
|
|
||||||
return $this->item($variable->getRelation('variable'), $this->makeTransformer(EggVariableTransformer::class), 'variable');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,9 @@ namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\Subuser;
|
use Pterodactyl\Models\Subuser;
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class SubuserTransformer extends BaseTransformer
|
class SubuserTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* List of resources that can be included.
|
* List of resources that can be included.
|
||||||
|
@ -14,17 +15,11 @@ class SubuserTransformer extends BaseTransformer
|
||||||
*/
|
*/
|
||||||
protected $availableIncludes = ['user', 'server'];
|
protected $availableIncludes = ['user', 'server'];
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return Subuser::RESOURCE_NAME;
|
return Subuser::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a transformed Subuser model that can be consumed by external services.
|
|
||||||
*/
|
|
||||||
public function transform(Subuser $subuser): array
|
public function transform(Subuser $subuser): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -32,8 +27,8 @@ class SubuserTransformer extends BaseTransformer
|
||||||
'user_id' => $subuser->user_id,
|
'user_id' => $subuser->user_id,
|
||||||
'server_id' => $subuser->server_id,
|
'server_id' => $subuser->server_id,
|
||||||
'permissions' => $subuser->permissions,
|
'permissions' => $subuser->permissions,
|
||||||
'created_at' => $this->formatTimestamp($subuser->created_at),
|
'created_at' => self::formatTimestamp($subuser->created_at),
|
||||||
'updated_at' => $this->formatTimestamp($subuser->updated_at),
|
'updated_at' => self::formatTimestamp($subuser->updated_at),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +36,6 @@ class SubuserTransformer extends BaseTransformer
|
||||||
* Return a generic item of user for this subuser.
|
* Return a generic item of user for this subuser.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeUser(Subuser $subuser)
|
public function includeUser(Subuser $subuser)
|
||||||
{
|
{
|
||||||
|
@ -50,17 +43,13 @@ class SubuserTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$subuser->loadMissing('user');
|
return $this->item($subuser->user, new UserTransformer());
|
||||||
|
|
||||||
return $this->item($subuser->getRelation('user'), $this->makeTransformer(UserTransformer::class), 'user');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a generic item of server for this subuser.
|
* Return a generic item of server for this subuser.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeServer(Subuser $subuser)
|
public function includeServer(Subuser $subuser)
|
||||||
{
|
{
|
||||||
|
@ -68,8 +57,6 @@ class SubuserTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$subuser->loadMissing('server');
|
return $this->item($subuser->server, new ServerTransformer());
|
||||||
|
|
||||||
return $this->item($subuser->getRelation('server'), $this->makeTransformer(ServerTransformer::class), 'server');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,9 @@ namespace Pterodactyl\Transformers\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\User;
|
use Pterodactyl\Models\User;
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
|
|
||||||
class UserTransformer extends BaseTransformer
|
class UserTransformer extends Transformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* List of resources that can be included.
|
* List of resources that can be included.
|
||||||
|
@ -14,17 +15,11 @@ class UserTransformer extends BaseTransformer
|
||||||
*/
|
*/
|
||||||
protected $availableIncludes = ['role', 'servers'];
|
protected $availableIncludes = ['role', 'servers'];
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the resource name for the JSONAPI output.
|
|
||||||
*/
|
|
||||||
public function getResourceName(): string
|
public function getResourceName(): string
|
||||||
{
|
{
|
||||||
return User::RESOURCE_NAME;
|
return User::RESOURCE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a transformed User model that can be consumed by external services.
|
|
||||||
*/
|
|
||||||
public function transform(User $model): array
|
public function transform(User $model): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -39,8 +34,8 @@ class UserTransformer extends BaseTransformer
|
||||||
'avatar_url' => $model->avatarURL(),
|
'avatar_url' => $model->avatarURL(),
|
||||||
'admin_role_id' => $model->admin_role_id,
|
'admin_role_id' => $model->admin_role_id,
|
||||||
'role_name' => $model->adminRoleName(),
|
'role_name' => $model->adminRoleName(),
|
||||||
'created_at' => $this->formatTimestamp($model->created_at),
|
'created_at' => self::formatTimestamp($model->created_at),
|
||||||
'updated_at' => $this->formatTimestamp($model->updated_at),
|
'updated_at' => self::formatTimestamp($model->updated_at),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,9 +43,6 @@ class UserTransformer extends BaseTransformer
|
||||||
* Return the role associated with this user.
|
* Return the role associated with this user.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeRole(User $user)
|
public function includeRole(User $user)
|
||||||
{
|
{
|
||||||
|
@ -58,18 +50,13 @@ class UserTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->loadMissing('adminRole');
|
return $this->item($user->adminRole, new AdminRoleTransformer());
|
||||||
|
|
||||||
return $this->item($user->getRelation('adminRole'), $this->makeTransformer(AdminRoleTransformer::class), 'admin_role');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the servers associated with this user.
|
* Return the servers associated with this user.
|
||||||
*
|
*
|
||||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||||
*
|
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
||||||
*/
|
*/
|
||||||
public function includeServers(User $user)
|
public function includeServers(User $user)
|
||||||
{
|
{
|
||||||
|
@ -77,8 +64,6 @@ class UserTransformer extends BaseTransformer
|
||||||
return $this->null();
|
return $this->null();
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->loadMissing('servers');
|
return $this->collection($user->servers, new ServerTransformer());
|
||||||
|
|
||||||
return $this->collection($user->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,12 @@
|
||||||
namespace Pterodactyl\Tests\Integration\Api\Application;
|
namespace Pterodactyl\Tests\Integration\Api\Application;
|
||||||
|
|
||||||
use Pterodactyl\Models\User;
|
use Pterodactyl\Models\User;
|
||||||
use PHPUnit\Framework\Assert;
|
|
||||||
use Pterodactyl\Models\ApiKey;
|
use Pterodactyl\Models\ApiKey;
|
||||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||||
|
use Pterodactyl\Transformers\Api\Transformer;
|
||||||
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Pterodactyl\Tests\Traits\Integration\CreatesTestModels;
|
use Pterodactyl\Tests\Traits\Integration\CreatesTestModels;
|
||||||
use Pterodactyl\Transformers\Api\Application\BaseTransformer;
|
|
||||||
use Pterodactyl\Tests\Traits\Http\IntegrationJsonRequestAssertions;
|
use Pterodactyl\Tests\Traits\Http\IntegrationJsonRequestAssertions;
|
||||||
|
|
||||||
abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
||||||
|
@ -129,16 +128,10 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
|
||||||
*
|
*
|
||||||
* @param string $abstract
|
* @param string $abstract
|
||||||
*
|
*
|
||||||
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
|
* @return \Pterodactyl\Transformers\Api\Transformer
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
||||||
*/
|
*/
|
||||||
protected function getTransformer(string $abstract): BaseTransformer
|
protected function getTransformer(string $abstract): Transformer
|
||||||
{
|
{
|
||||||
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
|
return new $abstract;
|
||||||
$transformer = $this->app->make($abstract);
|
|
||||||
|
|
||||||
Assert::assertInstanceOf(BaseTransformer::class, $transformer);
|
|
||||||
|
|
||||||
return $transformer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ use Carbon\CarbonImmutable;
|
||||||
use Pterodactyl\Tests\TestCase;
|
use Pterodactyl\Tests\TestCase;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Pterodactyl\Tests\Traits\Integration\CreatesTestModels;
|
use Pterodactyl\Tests\Traits\Integration\CreatesTestModels;
|
||||||
use Pterodactyl\Transformers\Api\Application\BaseTransformer;
|
|
||||||
|
|
||||||
abstract class IntegrationTestCase extends TestCase
|
abstract class IntegrationTestCase extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -40,7 +39,7 @@ abstract class IntegrationTestCase extends TestCase
|
||||||
protected function formatTimestamp(string $timestamp): string
|
protected function formatTimestamp(string $timestamp): string
|
||||||
{
|
{
|
||||||
return CarbonImmutable::createFromFormat(CarbonImmutable::DEFAULT_TO_STRING_FORMAT, $timestamp)
|
return CarbonImmutable::createFromFormat(CarbonImmutable::DEFAULT_TO_STRING_FORMAT, $timestamp)
|
||||||
->setTimezone(BaseTransformer::RESPONSE_TIMEZONE)
|
->setTimezone('UTC')
|
||||||
->toIso8601String();
|
->toIso8601String();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue