forked from Alex/Pterodactyl-Panel
Merge pull request #1693 from TrixterTheTux/api-fixes
This commit is contained in:
commit
4bca3a4895
@ -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
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
80
app/Transformers/Api/Application/SubuserTransformer.php
Normal file
80
app/Transformers/Api/Application/SubuserTransformer.php
Normal 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');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user