From 66ead2f682fab0235b63015bd4204f326b379498 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 28 Dec 2019 11:39:44 -0800 Subject: [PATCH] Update subuser API output to work correctly --- CHANGELOG.md | 2 +- app/Models/Server.php | 4 ++-- app/Transformers/Api/Application/SubuserTransformer.php | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bacba59eb..33749dd55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### 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 +* The /api/application/servers endpoint can now include server's databases and subusers. ## v0.7.15 (Derelict Dermodactylus) ### Fixed diff --git a/app/Models/Server.php b/app/Models/Server.php index 174453cfb..fd5d9d121 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -168,11 +168,11 @@ class Server extends Model implements CleansAttributes, ValidableContract /** * Gets the subusers associated with a server. * - * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough + * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function subusers() { - return $this->hasManyThrough(User::class, Subuser::class, 'server_id', 'id', 'id', 'user_id'); + return $this->hasMany(Subuser::class, 'server_id', 'id'); } /** diff --git a/app/Transformers/Api/Application/SubuserTransformer.php b/app/Transformers/Api/Application/SubuserTransformer.php index 1bb5d6017..7927272ca 100644 --- a/app/Transformers/Api/Application/SubuserTransformer.php +++ b/app/Transformers/Api/Application/SubuserTransformer.php @@ -3,6 +3,7 @@ namespace Pterodactyl\Transformers\Api\Application; use Pterodactyl\Models\Subuser; +use Pterodactyl\Models\Permission; use Pterodactyl\Services\Acl\Api\AdminAcl; class SubuserTransformer extends BaseTransformer @@ -34,7 +35,11 @@ class SubuserTransformer extends BaseTransformer { return [ 'id' => $subuser->id, - 'permissions' => $subuser->permissions->toArray(), + 'user_id' => $subuser->user_id, + 'server_id' => $subuser->server_id, + 'permissions' => $subuser->permissions->map(function (Permission $permission) { + return $permission->permission; + }), 'created_at' => $this->formatTimestamp($subuser->created_at), 'updated_at' => $this->formatTimestamp($subuser->updated_at), ];