2019-08-31 08:29:44 +00:00
|
|
|
<?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.
|
|
|
|
*/
|
2022-05-04 23:11:42 +00:00
|
|
|
protected array $availableIncludes = ['user', 'server'];
|
2019-08-31 08:29:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the resource name for the JSONAPI output.
|
|
|
|
*/
|
|
|
|
public function getResourceName(): string
|
|
|
|
{
|
|
|
|
return Subuser::RESOURCE_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a transformed Subuser model that can be consumed by external services.
|
|
|
|
*/
|
|
|
|
public function transform(Subuser $subuser): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $subuser->id,
|
2019-12-28 19:39:44 +00:00
|
|
|
'user_id' => $subuser->user_id,
|
|
|
|
'server_id' => $subuser->server_id,
|
2020-09-18 03:44:33 +00:00
|
|
|
'permissions' => $subuser->permissions,
|
2019-08-31 08:29:44 +00:00
|
|
|
'created_at' => $this->formatTimestamp($subuser->created_at),
|
|
|
|
'updated_at' => $this->formatTimestamp($subuser->updated_at),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a generic item of user for this subuser.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
|
|
*/
|
|
|
|
public function includeUser(Subuser $subuser)
|
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_USERS)) {
|
2019-08-31 08:29:44 +00:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
|
|
|
*/
|
|
|
|
public function includeServer(Subuser $subuser)
|
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
2019-08-31 08:29:44 +00:00
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
|
|
|
$subuser->loadMissing('server');
|
|
|
|
|
|
|
|
return $this->item($subuser->getRelation('server'), $this->makeTransformer(ServerTransformer::class), 'server');
|
|
|
|
}
|
|
|
|
}
|