From 20c594ae3b99ad91d8f9ccb5706e059afd44297a Mon Sep 17 00:00:00 2001 From: TrixterTheTux Date: Sat, 24 Aug 2019 15:47:11 +0300 Subject: [PATCH 1/3] Include the egg name in egg model's response from the application API --- CHANGELOG.md | 4 ++++ app/Transformers/Api/Application/EggTransformer.php | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22858333..1d2edc87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa This project follows [Semantic Versioning](http://semver.org) guidelines. +## v0.7.16 (Derelict Dermodactylus) +### Added +* The application API now includes the egg's name in the egg model's response. + ## v0.7.15 (Derelict Dermodactylus) ### Fixed * Fixes support for PHP 7.3 when running `composer install` commands due to a dependency that needed updating. diff --git a/app/Transformers/Api/Application/EggTransformer.php b/app/Transformers/Api/Application/EggTransformer.php index 98765bf4..a3686341 100644 --- a/app/Transformers/Api/Application/EggTransformer.php +++ b/app/Transformers/Api/Application/EggTransformer.php @@ -41,6 +41,7 @@ class EggTransformer extends BaseTransformer return [ 'id' => $model->id, 'uuid' => $model->uuid, + 'name' => $model->name, 'nest' => $model->nest_id, 'author' => $model->author, 'description' => $model->description, From ab09c7db28cc8ae80b4dc17465a3c740f05cb107 Mon Sep 17 00:00:00 2001 From: TrixterTheTux Date: Sat, 31 Aug 2019 11:29:44 +0300 Subject: [PATCH 2/3] Fix couple of issues with /api/application/servers --- CHANGELOG.md | 4 + .../Api/Application/ServerTransformer.php | 28 ++++++- .../Api/Application/SubuserTransformer.php | 80 +++++++++++++++++++ 3 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 app/Transformers/Api/Application/SubuserTransformer.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d2edc87..43423427 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,12 @@ This file is a running track of new features and fixes to each version of the pa This project follows [Semantic Versioning](http://semver.org) guidelines. ## v0.7.16 (Derelict Dermodactylus) +### Fixed +* Fixed the /api/application/servers endpoint erroring when including subusers or egg + ### Added * The application API now includes the egg's name in the egg model's response. +* The /api/application/servers endpoint can now include server's databases and subusers ## v0.7.15 (Derelict Dermodactylus) ### Fixed diff --git a/app/Transformers/Api/Application/ServerTransformer.php b/app/Transformers/Api/Application/ServerTransformer.php index 2a542dbc..27e377e2 100644 --- a/app/Transformers/Api/Application/ServerTransformer.php +++ b/app/Transformers/Api/Application/ServerTransformer.php @@ -28,6 +28,7 @@ class ServerTransformer extends BaseTransformer 'variables', 'location', 'node', + 'databases', ]; /** @@ -131,7 +132,7 @@ class ServerTransformer extends BaseTransformer $server->loadMissing('subusers'); - return $this->collection($server->getRelation('subusers'), $this->makeTransformer(UserTransformer::class), 'user'); + return $this->collection($server->getRelation('subusers'), $this->makeTransformer(SubuserTransformer::class), 'user'); } /** @@ -195,14 +196,14 @@ class ServerTransformer extends BaseTransformer } /** - * Return a generic array with service option information for this server. + * Return a generic array with egg information for this server. * * @param \Pterodactyl\Models\Server $server * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException */ - public function includeOption(Server $server) + public function includeEgg(Server $server) { if (! $this->authorize(AdminAcl::RESOURCE_EGGS)) { return $this->null(); @@ -210,7 +211,7 @@ class ServerTransformer extends BaseTransformer $server->loadMissing('egg'); - return $this->item($server->getRelation('egg'), $this->makeTransformer(EggVariableTransformer::class), 'egg'); + return $this->item($server->getRelation('egg'), $this->makeTransformer(EggTransformer::class), 'egg'); } /** @@ -269,4 +270,23 @@ class ServerTransformer extends BaseTransformer return $this->item($server->getRelation('node'), $this->makeTransformer(NodeTransformer::class), 'node'); } + + /** + * Return a generic array with database information for this server. + * + * @param \Pterodactyl\Models\Server $server + * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource + * + * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + */ + public function includeDatabases(Server $server) + { + if (! $this->authorize(AdminAcl::RESOURCE_SERVER_DATABASES)) { + return $this->null(); + } + + $server->loadMissing('databases'); + + return $this->collection($server->getRelation('databases'), $this->makeTransformer(ServerDatabaseTransformer::class), 'databases'); + } } diff --git a/app/Transformers/Api/Application/SubuserTransformer.php b/app/Transformers/Api/Application/SubuserTransformer.php new file mode 100644 index 00000000..1bb5d601 --- /dev/null +++ b/app/Transformers/Api/Application/SubuserTransformer.php @@ -0,0 +1,80 @@ + $subuser->id, + 'permissions' => $subuser->permissions->toArray(), + 'created_at' => $this->formatTimestamp($subuser->created_at), + 'updated_at' => $this->formatTimestamp($subuser->updated_at), + ]; + } + + /** + * Return a generic item of user for this subuser. + * + * @param \Pterodactyl\Models\Subuser $subuser + * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource + * + * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + */ + public function includeUser(Subuser $subuser) + { + if (! $this->authorize(AdminAcl::RESOURCE_USERS)) { + return $this->null(); + } + + $subuser->loadMissing('user'); + + return $this->item($subuser->getRelation('user'), $this->makeTransformer(UserTransformer::class), 'user'); + } + + /** + * Return a generic item of server for this subuser. + * + * @param \Pterodactyl\Models\Subuser $subuser + * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource + * + * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + */ + public function includeServer(Subuser $subuser) + { + if (! $this->authorize(AdminAcl::RESOURCE_SERVERS)) { + return $this->null(); + } + + $subuser->loadMissing('server'); + + return $this->item($subuser->getRelation('server'), $this->makeTransformer(ServerTransformer::class), 'server'); + } +} From 5f60a6c73566764c5268f281288c141821b2c5e5 Mon Sep 17 00:00:00 2001 From: Stepan Fedotov Date: Sat, 28 Dec 2019 13:53:33 +0200 Subject: [PATCH 3/3] Fix the resource key for subusers --- app/Transformers/Api/Application/ServerTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Transformers/Api/Application/ServerTransformer.php b/app/Transformers/Api/Application/ServerTransformer.php index 27e377e2..70dc185d 100644 --- a/app/Transformers/Api/Application/ServerTransformer.php +++ b/app/Transformers/Api/Application/ServerTransformer.php @@ -132,7 +132,7 @@ class ServerTransformer extends BaseTransformer $server->loadMissing('subusers'); - return $this->collection($server->getRelation('subusers'), $this->makeTransformer(SubuserTransformer::class), 'user'); + return $this->collection($server->getRelation('subusers'), $this->makeTransformer(SubuserTransformer::class), 'subuser'); } /**