2019-08-31 08:29:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Transformers\Api\Application;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Subuser;
|
2022-10-14 16:59:20 +00:00
|
|
|
use League\Fractal\Resource\Item;
|
|
|
|
use League\Fractal\Resource\NullResource;
|
2019-08-31 08:29:44 +00:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
2022-12-15 00:05:46 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Transformer;
|
2019-08-31 08:29:44 +00:00
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
class SubuserTransformer extends Transformer
|
2019-08-31 08:29:44 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* List of resources that can be included.
|
|
|
|
*/
|
2022-12-15 00:05:46 +00:00
|
|
|
protected array $availableIncludes = ['server', 'user'];
|
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.
|
|
|
|
*/
|
2022-12-15 00:05:46 +00:00
|
|
|
public function transform(Subuser $model): array
|
2019-08-31 08:29:44 +00:00
|
|
|
{
|
|
|
|
return [
|
2022-12-15 00:05:46 +00:00
|
|
|
'id' => $model->id,
|
|
|
|
'user_id' => $model->user_id,
|
|
|
|
'server_id' => $model->server_id,
|
|
|
|
'permissions' => $model->permissions,
|
|
|
|
'created_at' => self::formatTimestamp($model->created_at),
|
|
|
|
'updated_at' => self::formatTimestamp($model->updated_at),
|
2019-08-31 08:29:44 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-15 00:05:46 +00:00
|
|
|
* Return a generic item of server for this subuser.
|
2019-08-31 08:29:44 +00:00
|
|
|
*/
|
2022-12-15 00:05:46 +00:00
|
|
|
public function includeServer(Subuser $subuser): Item|NullResource
|
2019-08-31 08:29:44 +00:00
|
|
|
{
|
2022-12-15 00:05:46 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {
|
2019-08-31 08:29:44 +00:00
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
return $this->item($subuser->server, new ServerTransformer());
|
2019-08-31 08:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-15 00:05:46 +00:00
|
|
|
* Return a generic item of user for this subuser.
|
2019-08-31 08:29:44 +00:00
|
|
|
*/
|
2022-12-15 00:05:46 +00:00
|
|
|
public function includeUser(Subuser $subuser): Item|NullResource
|
2019-08-31 08:29:44 +00:00
|
|
|
{
|
2022-12-15 00:05:46 +00:00
|
|
|
if (!$this->authorize(AdminAcl::RESOURCE_USERS)) {
|
2019-08-31 08:29:44 +00:00
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
2022-12-15 00:05:46 +00:00
|
|
|
return $this->item($subuser->user, new UserTransformer());
|
2019-08-31 08:29:44 +00:00
|
|
|
}
|
|
|
|
}
|