Path: blob/1.0-develop/app/Transformers/Api/Application/UserTransformer.php
10280 views
<?php12namespace Pterodactyl\Transformers\Api\Application;34use Pterodactyl\Models\User;5use League\Fractal\Resource\Collection;6use League\Fractal\Resource\NullResource;7use Pterodactyl\Services\Acl\Api\AdminAcl;89class UserTransformer extends BaseTransformer10{11/**12* List of resources that can be included.13*/14protected array $availableIncludes = ['servers'];1516/**17* Return the resource name for the JSONAPI output.18*/19public function getResourceName(): string20{21return User::RESOURCE_NAME;22}2324/**25* Return a transformed User model that can be consumed by external services.26*/27public function transform(User $user): array28{29return [30'id' => $user->id,31'external_id' => $user->external_id,32'uuid' => $user->uuid,33'username' => $user->username,34'email' => $user->email,35'first_name' => $user->name_first,36'last_name' => $user->name_last,37'language' => $user->language,38'root_admin' => (bool) $user->root_admin,39'2fa' => (bool) $user->use_totp,40'created_at' => $this->formatTimestamp($user->created_at),41'updated_at' => $this->formatTimestamp($user->updated_at),42];43}4445/**46* Return the servers associated with this user.47*48* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException49*/50public function includeServers(User $user): Collection|NullResource51{52if (!$this->authorize(AdminAcl::RESOURCE_SERVERS)) {53return $this->null();54}5556$user->loadMissing('servers');5758return $this->collection($user->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server');59}60}616263