From d894c3d9036b11a0071bc7cf6855e80623199100 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 12 Mar 2025 16:33:35 +0100 Subject: [PATCH] feat(database): implement two-step confirmation for database deletion Added a new delete method in the Database component that includes a two-step confirmation process requiring the user to enter their password. If two-step confirmation is disabled, the deletion proceeds without password verification. Additionally, a confirmation modal has been integrated into the database view to prompt users before deletion, enhancing the safety of this critical operation. --- app/Livewire/Project/Service/Database.php | 26 +++++++++++++++++++ .../project/service/database.blade.php | 4 +++ .../livewire/project/service/index.blade.php | 8 +++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/app/Livewire/Project/Service/Database.php b/app/Livewire/Project/Service/Database.php index 9f02db05c..c3b7577e9 100644 --- a/app/Livewire/Project/Service/Database.php +++ b/app/Livewire/Project/Service/Database.php @@ -4,7 +4,10 @@ namespace App\Livewire\Project\Service; use App\Actions\Database\StartDatabaseProxy; use App\Actions\Database\StopDatabaseProxy; +use App\Models\InstanceSettings; use App\Models\ServiceDatabase; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; use Livewire\Component; class Database extends Component @@ -15,6 +18,8 @@ class Database extends Component public $fileStorages; + public $parameters; + protected $listeners = ['refreshFileStorages']; protected $rules = [ @@ -34,12 +39,33 @@ class Database extends Component public function mount() { + $this->parameters = get_route_parameters(); if ($this->database->is_public) { $this->db_url_public = $this->database->getServiceDatabaseUrl(); } $this->refreshFileStorages(); } + public function delete($password) + { + if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) { + if (! Hash::check($password, Auth::user()->password)) { + $this->addError('password', 'The provided password is incorrect.'); + + return; + } + } + + try { + $this->database->delete(); + $this->dispatch('success', 'Database deleted.'); + + return redirect()->route('project.service.configuration', $this->parameters); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function instantSaveExclude() { $this->submit(); diff --git a/resources/views/livewire/project/service/database.blade.php b/resources/views/livewire/project/service/database.blade.php index c18473a14..8ec73b4de 100644 --- a/resources/views/livewire/project/service/database.blade.php +++ b/resources/views/livewire/project/service/database.blade.php @@ -7,6 +7,10 @@

{{ Str::headline($database->name) }}

@endif Save +
diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php index 8796be966..d5c0c4778 100644 --- a/resources/views/livewire/project/service/index.blade.php +++ b/resources/views/livewire/project/service/index.blade.php @@ -3,8 +3,8 @@
+ class="{{ request()->routeIs('project.service.configuration') ? 'menu-item-active' : '' }}" wire:navigate + href="{{ route('project.service.configuration', [...$parameters, 'stack_service_uuid' => null]) }}"> General @if ($serviceDatabase?->isBackupSolutionAvailable()) Backups + @click.prevent="activeTab = 'backups'; window.location.hash = 'backups'" wire:navigate + href="#backups">Backups @endif