mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +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>
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers\Api\Client;
|
|
|
|
use App\Models\Database;
|
|
use League\Fractal\Resource\Item;
|
|
use App\Models\Permission;
|
|
use League\Fractal\Resource\NullResource;
|
|
|
|
class DatabaseTransformer extends BaseClientTransformer
|
|
{
|
|
protected array $availableIncludes = ['password'];
|
|
|
|
public function getResourceName(): string
|
|
{
|
|
return Database::RESOURCE_NAME;
|
|
}
|
|
|
|
/**
|
|
* @param Database $model
|
|
*/
|
|
public function transform($model): array
|
|
{
|
|
$model->loadMissing('host');
|
|
|
|
return [
|
|
'id' => $model->id,
|
|
'host' => [
|
|
'address' => $model->getRelation('host')->host,
|
|
'port' => $model->getRelation('host')->port,
|
|
],
|
|
'name' => $model->database,
|
|
'username' => $model->username,
|
|
'connections_from' => $model->remote,
|
|
'max_connections' => $model->max_connections,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Include the database password in the request.
|
|
*/
|
|
public function includePassword(Database $database): Item|NullResource
|
|
{
|
|
if (!$this->request->user()->can(Permission::ACTION_DATABASE_VIEW_PASSWORD, $database->server)) {
|
|
return $this->null();
|
|
}
|
|
|
|
return $this->item($database, function (Database $model) {
|
|
return [
|
|
'password' => $model->password,
|
|
];
|
|
}, 'database_password');
|
|
}
|
|
}
|