mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 01:44:45 +02:00

* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers\Api\Application;
|
|
|
|
use App\Models\Role;
|
|
use App\Models\User;
|
|
use App\Models\Server;
|
|
use League\Fractal\Resource\Collection;
|
|
use League\Fractal\Resource\NullResource;
|
|
|
|
class UserTransformer extends BaseTransformer
|
|
{
|
|
protected array $availableIncludes = [
|
|
'servers',
|
|
'roles',
|
|
];
|
|
|
|
/**
|
|
* Return the resource name for the JSONAPI output.
|
|
*/
|
|
public function getResourceName(): string
|
|
{
|
|
return User::RESOURCE_NAME;
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
*/
|
|
public function transform($user): array
|
|
{
|
|
return [
|
|
'id' => $user->id,
|
|
'external_id' => $user->external_id,
|
|
'uuid' => $user->uuid,
|
|
'username' => $user->username,
|
|
'email' => $user->email,
|
|
'language' => $user->language,
|
|
'root_admin' => $user->isRootAdmin(),
|
|
'2fa_enabled' => (bool) $user->use_totp,
|
|
'2fa' => (bool) $user->use_totp, // deprecated, use "2fa_enabled"
|
|
'created_at' => $this->formatTimestamp($user->created_at),
|
|
'updated_at' => $this->formatTimestamp($user->updated_at),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Return the servers associated with this user.
|
|
*/
|
|
public function includeServers(User $user): Collection|NullResource
|
|
{
|
|
if (!$this->authorize(Server::RESOURCE_NAME)) {
|
|
return $this->null();
|
|
}
|
|
|
|
$user->loadMissing('servers');
|
|
|
|
return $this->collection($user->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server');
|
|
}
|
|
|
|
/**
|
|
* Return the roles associated with this user.
|
|
*/
|
|
public function includeRoles(User $user): Collection|NullResource
|
|
{
|
|
if (!$this->authorize(Role::RESOURCE_NAME)) {
|
|
return $this->null();
|
|
}
|
|
|
|
$user->loadMissing('roles');
|
|
|
|
return $this->collection($user->getRelation('roles'), $this->makeTransformer(RoleTransformer::class), Role::RESOURCE_NAME);
|
|
}
|
|
}
|