2024-12-12 18:34:52 +01:00
|
|
|
<?php
|
|
|
|
|
|
2025-09-08 13:12:33 -04:00
|
|
|
namespace App\Filament\Components\Actions;
|
2024-12-12 18:34:52 +01:00
|
|
|
|
2026-01-27 11:36:07 +01:00
|
|
|
use App\Enums\TablerIcon;
|
2025-03-06 09:28:45 -05:00
|
|
|
use App\Facades\Activity;
|
2024-12-12 18:34:52 +01:00
|
|
|
use App\Models\Database;
|
2025-09-06 22:57:11 +02:00
|
|
|
use App\Services\Databases\DatabaseManagementService;
|
2024-12-12 18:34:52 +01:00
|
|
|
use Exception;
|
2025-09-08 13:12:33 -04:00
|
|
|
use Filament\Actions\Action;
|
2025-09-06 22:57:11 +02:00
|
|
|
use Filament\Facades\Filament;
|
2024-12-12 18:34:52 +01:00
|
|
|
use Filament\Notifications\Notification;
|
2025-09-24 13:34:19 +02:00
|
|
|
use Filament\Schemas\Components\Utilities\Set;
|
2024-12-12 18:34:52 +01:00
|
|
|
|
|
|
|
|
class RotateDatabasePasswordAction extends Action
|
|
|
|
|
{
|
|
|
|
|
public static function getDefaultName(): ?string
|
|
|
|
|
{
|
2026-02-15 17:31:50 +01:00
|
|
|
return 'exclude_hint_rotate';
|
2024-12-12 18:34:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2026-02-15 17:31:50 +01:00
|
|
|
$this->hiddenLabel();
|
|
|
|
|
|
2026-01-27 20:07:18 -05:00
|
|
|
$this->tooltip(trans('admin/databasehost.rotate'));
|
2024-12-12 18:34:52 +01:00
|
|
|
|
2026-01-27 11:36:07 +01:00
|
|
|
$this->icon(TablerIcon::Refresh);
|
2024-12-12 18:34:52 +01:00
|
|
|
|
2025-10-07 23:12:31 +02:00
|
|
|
$this->authorize(fn (Database $database) => user()?->can('update', $database));
|
2024-12-12 18:34:52 +01:00
|
|
|
|
2025-02-08 23:16:54 -05:00
|
|
|
$this->modalHeading(trans('admin/databasehost.rotate_password'));
|
2024-12-12 18:34:52 +01:00
|
|
|
|
|
|
|
|
$this->modalIconColor('warning');
|
|
|
|
|
|
2025-09-08 13:12:33 -04:00
|
|
|
$this->modalSubmitAction(fn (Action $action) => $action->color('warning'));
|
2024-12-12 18:34:52 +01:00
|
|
|
|
|
|
|
|
$this->requiresConfirmation();
|
|
|
|
|
|
2025-09-06 22:57:11 +02:00
|
|
|
$this->action(function (DatabaseManagementService $service, Database $database, Set $set) {
|
2024-12-12 18:34:52 +01:00
|
|
|
try {
|
2025-09-06 22:57:11 +02:00
|
|
|
$service->rotatePassword($database);
|
2024-12-12 18:34:52 +01:00
|
|
|
$database->refresh();
|
|
|
|
|
|
|
|
|
|
$set('password', $database->password);
|
|
|
|
|
$set('jdbc', $database->jdbc);
|
|
|
|
|
|
2025-03-06 09:28:45 -05:00
|
|
|
Activity::event('server:database.rotate-password')
|
|
|
|
|
->subject($database)
|
|
|
|
|
->property('name', $database->database)
|
|
|
|
|
->log();
|
|
|
|
|
|
2024-12-12 18:34:52 +01:00
|
|
|
Notification::make()
|
2025-02-08 23:16:54 -05:00
|
|
|
->title(trans('admin/databasehost.rotated'))
|
2024-12-12 18:34:52 +01:00
|
|
|
->success()
|
|
|
|
|
->send();
|
|
|
|
|
} catch (Exception $exception) {
|
|
|
|
|
Notification::make()
|
2025-02-08 23:16:54 -05:00
|
|
|
->title(trans('admin/databasehost.rotate_error'))
|
2025-10-07 23:12:31 +02:00
|
|
|
->body(fn () => user()?->canAccessPanel(Filament::getPanel('admin')) ? $exception->getMessage() : null)
|
2024-12-12 18:34:52 +01:00
|
|
|
->danger()
|
|
|
|
|
->send();
|
|
|
|
|
|
|
|
|
|
report($exception);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|