Return a null resource if an allocation has no server; closes #2117

This commit is contained in:
Dane Everitt 2020-06-13 09:56:40 -07:00
parent b30d7429f3
commit be91913f23
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -2,6 +2,8 @@
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Services\Acl\Api\AdminAcl;
@ -54,10 +56,8 @@ class AllocationTransformer extends BaseTransformer
return $this->null();
}
$allocation->loadMissing('node');
return $this->item(
$allocation->getRelation('node'), $this->makeTransformer(NodeTransformer::class), 'node'
$allocation->node, $this->makeTransformer(NodeTransformer::class), Node::RESOURCE_NAME
);
}
@ -70,14 +70,12 @@ class AllocationTransformer extends BaseTransformer
*/
public function includeServer(Allocation $allocation)
{
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS)) {
if (! $this->authorize(AdminAcl::RESOURCE_SERVERS) || ! $allocation->server) {
return $this->null();
}
$allocation->loadMissing('server');
return $this->item(
$allocation->getRelation('server'), $this->makeTransformer(ServerTransformer::class), 'server'
$allocation->server, $this->makeTransformer(ServerTransformer::class), Server::RESOURCE_NAME
);
}
}