mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-19 14:53:45 +02:00
db_hosts: add ability to link more than one node
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
@@ -12,9 +13,7 @@ class DatabaseHostTransformer extends BaseTransformer
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = [
|
||||
'databases',
|
||||
];
|
||||
protected $availableIncludes = ['databases', 'nodes'];
|
||||
|
||||
/**
|
||||
* Return the resource name for the JSONAPI output.
|
||||
@@ -68,6 +67,36 @@ class DatabaseHostTransformer extends BaseTransformer
|
||||
|
||||
$model->loadMissing('databases');
|
||||
|
||||
return $this->collection($model->getRelation('databases'), $this->makeTransformer(ServerDatabaseTransformer::class), Database::RESOURCE_NAME);
|
||||
return $this->collection(
|
||||
$model->getRelation('databases'),
|
||||
$this->makeTransformer(ServerDatabaseTransformer::class),
|
||||
Database::RESOURCE_NAME
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the nodes associated with this mount.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Mount $mount
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function includeNodes(DatabaseHost $model)
|
||||
{
|
||||
if (!$this->authorize(AdminAcl::RESOURCE_NODES)) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
$model->loadMissing('nodes');
|
||||
|
||||
return $this->collection(
|
||||
$model->getRelation('nodes'),
|
||||
$this->makeTransformer(NodeTransformer::class),
|
||||
Node::RESOURCE_NAME
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace Pterodactyl\Transformers\Api\Application;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Mount;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
|
||||
class MountTransformer extends BaseTransformer
|
||||
@@ -64,7 +67,7 @@ class MountTransformer extends BaseTransformer
|
||||
return $this->collection(
|
||||
$mount->getRelation('eggs'),
|
||||
$this->makeTransformer(EggTransformer::class),
|
||||
'egg',
|
||||
Egg::RESOURCE_NAME
|
||||
);
|
||||
}
|
||||
|
||||
@@ -88,7 +91,7 @@ class MountTransformer extends BaseTransformer
|
||||
return $this->collection(
|
||||
$mount->getRelation('nodes'),
|
||||
$this->makeTransformer(NodeTransformer::class),
|
||||
'node',
|
||||
Node::RESOURCE_NAME
|
||||
);
|
||||
}
|
||||
|
||||
@@ -112,7 +115,7 @@ class MountTransformer extends BaseTransformer
|
||||
return $this->collection(
|
||||
$mount->getRelation('servers'),
|
||||
$this->makeTransformer(ServerTransformer::class),
|
||||
'server',
|
||||
Server::RESOURCE_NAME
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user