Merge pull request #1693 from TrixterTheTux/api-fixes

This commit is contained in:
Dane Everitt 2019-12-28 11:13:00 -08:00 committed by GitHub
commit 4bca3a4895
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 108 additions and 4 deletions

View File

@ -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

View File

@ -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');
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace Pterodactyl\Transformers\Api\Application;
use Pterodactyl\Models\Subuser;
use Pterodactyl\Services\Acl\Api\AdminAcl;
class SubuserTransformer extends BaseTransformer
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = ['user', 'server'];
/**
* Return the resource name for the JSONAPI output.
*
* @return string
*/
public function getResourceName(): string
{
return Subuser::RESOURCE_NAME;
}
/**
* Return a transformed Subuser model that can be consumed by external services.
*
* @param \Pterodactyl\Models\Subuser $subuser
* @return array
*/
public function transform(Subuser $subuser): array
{
return [
'id' => $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');
}
}