2019-11-03 12:20:11 -08:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2019-11-03 12:20:11 -08:00
|
|
|
namespace Pterodactyl\Transformers\Api\Client;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException;
|
|
|
|
|
use Pterodactyl\Extensions\Scribe\Attributes\ResponseField;
|
2019-11-03 12:20:11 -08:00
|
|
|
use Pterodactyl\Models\Subuser;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
#[ResponseField('permissions', schema: ['type' => 'array', 'items' => ['type' => 'string'], 'example' => ['control.console', 'file.read']])]
|
2019-11-03 12:20:11 -08:00
|
|
|
class SubuserTransformer extends BaseClientTransformer
|
|
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
protected array $eagerLoads = ['user'];
|
|
|
|
|
|
2019-11-03 12:20:11 -08:00
|
|
|
/**
|
|
|
|
|
* Return the resource name for the JSONAPI output.
|
|
|
|
|
*/
|
|
|
|
|
public function getResourceName(): string
|
|
|
|
|
{
|
|
|
|
|
return Subuser::RESOURCE_NAME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-12-28 12:03:19 -08:00
|
|
|
* Transforms a subuser into a model that can be shown to a front-end user.
|
2019-11-03 12:20:11 -08:00
|
|
|
*
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return ApiPayload
|
|
|
|
|
*
|
|
|
|
|
* @throws InvalidTransformerLevelException
|
2019-11-03 12:20:11 -08:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function transform(Subuser $model): array
|
2019-11-03 12:20:11 -08:00
|
|
|
{
|
2020-03-27 14:23:13 -07:00
|
|
|
return array_merge(
|
2026-10-05 18:10:18 -04:00
|
|
|
$this->makeTransformer(UserTransformer::class)->transform($model->loadMissing('user')->user),
|
2020-03-27 14:23:13 -07:00
|
|
|
['permissions' => $model->permissions]
|
|
|
|
|
);
|
2019-11-03 12:20:11 -08:00
|
|
|
}
|
|
|
|
|
}
|