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..70dc185d 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), 'subuser'); } /** @@ -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'); + } +}