2021-01-05 21:52:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Application;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Mount;
|
2021-01-13 16:52:04 +00:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
2021-08-07 20:25:06 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Transformer;
|
2021-01-05 21:52:49 +00:00
|
|
|
|
2021-08-07 20:25:06 +00:00
|
|
|
class MountTransformer extends Transformer
|
2021-01-05 21:52:49 +00:00
|
|
|
{
|
2021-01-13 16:52:04 +00:00
|
|
|
/**
|
|
|
|
* List of resources that can be included.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = ['eggs', 'nodes', 'servers'];
|
|
|
|
|
2021-01-05 21:52:49 +00:00
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return Mount::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transform(Mount $model): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $model->id,
|
|
|
|
'uuid' => $model->uuid,
|
|
|
|
'name' => $model->name,
|
|
|
|
'description' => $model->description,
|
|
|
|
'source' => $model->source,
|
|
|
|
'target' => $model->target,
|
|
|
|
'read_only' => $model->read_only,
|
|
|
|
'user_mountable' => $model->user_mountable,
|
|
|
|
];
|
|
|
|
}
|
2021-01-13 16:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the eggs associated with this mount.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
|
|
|
*/
|
|
|
|
public function includeEggs(Mount $mount)
|
|
|
|
{
|
2021-08-07 20:25:06 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_EGGS)) {
|
2021-01-13 16:52:04 +00:00
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
2021-08-07 20:25:06 +00:00
|
|
|
return $this->collection($mount->eggs, new EggTransformer());
|
2021-01-13 16:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the nodes associated with this mount.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
|
|
|
*/
|
|
|
|
public function includeNodes(Mount $mount)
|
|
|
|
{
|
2021-08-07 20:25:06 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
|
2021-01-13 16:52:04 +00:00
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
2021-08-07 20:25:06 +00:00
|
|
|
return $this->collection($mount->nodes, new NodeTransformer());
|
2021-01-13 16:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the servers associated with this mount.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
|
|
|
*/
|
|
|
|
public function includeServers(Mount $mount)
|
|
|
|
{
|
2021-08-07 20:25:06 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
2021-01-13 16:52:04 +00:00
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
2021-08-07 20:25:06 +00:00
|
|
|
return $this->collection($mount->servers, new ServerTransformer());
|
2021-01-13 16:52:04 +00:00
|
|
|
}
|
2021-01-05 21:52:49 +00:00
|
|
|
}
|