From be6b398e2d6030b38693201fed313a81517ed8b7 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 24 Feb 2018 11:17:21 -0600 Subject: [PATCH] add support for egg variables, closes #974 --- CHANGELOG.md | 3 +++ .../Api/Application/EggTransformer.php | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c7c0f2b6..a02f1975a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Fixed * Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint. +### Added +* Adds ability to include egg variables on an API request. + ## v0.7.1 (Derelict Dermodactylus) ### Fixed * Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted. diff --git a/app/Transformers/Api/Application/EggTransformer.php b/app/Transformers/Api/Application/EggTransformer.php index 3454547bd..b73500bb8 100644 --- a/app/Transformers/Api/Application/EggTransformer.php +++ b/app/Transformers/Api/Application/EggTransformer.php @@ -5,6 +5,7 @@ namespace Pterodactyl\Transformers\Api\Application; use Pterodactyl\Models\Egg; use Pterodactyl\Models\Nest; use Pterodactyl\Models\Server; +use Pterodactyl\Models\EggVariable; use Pterodactyl\Services\Acl\Api\AdminAcl; class EggTransformer extends BaseTransformer @@ -15,7 +16,7 @@ class EggTransformer extends BaseTransformer * @var array */ protected $availableIncludes = [ - 'nest', 'servers', 'config', 'script', + 'nest', 'servers', 'config', 'script', 'variables', ]; /** @@ -147,4 +148,25 @@ class EggTransformer extends BaseTransformer ]; }); } + + /** + * Include the variables that are defined for this Egg. + * + * @param \Pterodactyl\Models\Egg $model + * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource + */ + public function includeVariables(Egg $model) + { + if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) { + return $this->null(); + } + + $model->loadMissing('variables'); + + return $this->collection( + $model->getRelation('variables'), + $this->makeTransformer(EggVariableTransformer::class), + EggVariable::RESOURCE_NAME + ); + } }