From 17309315b8b1aac4fe50f21c5a9022f3a497dd08 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sat, 8 Aug 2026 12:36:56 +0200 Subject: [PATCH] Fix restore and verify buttons in admin user list --- .../js/alpine/components/admin/user-list.js | 13 +++++++ resources/views/admin/users/index.blade.php | 28 ++++++-------- .../Feature/Admin/AdminUserControllerTest.php | 38 +++++++++++++++++++ 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/resources/js/alpine/components/admin/user-list.js b/resources/js/alpine/components/admin/user-list.js index 5f072d0fc..64f258b53 100644 --- a/resources/js/alpine/components/admin/user-list.js +++ b/resources/js/alpine/components/admin/user-list.js @@ -33,6 +33,19 @@ Alpine.data('adminUserList', () => ({ if (form) { form.addEventListener('submit', e => this.submitBulkAction(e)); } + + // Verify-user trigger buttons (modal lives in the separate verifyUser component) + this.$el.addEventListener('click', e => { + const verifyBtn = e.target.closest('[data-show-verify-modal]'); + if (!verifyBtn) { + return; + } + e.preventDefault(); + const verifyForm = verifyBtn.closest('form'); + if (verifyForm && typeof window.showVerifyModal === 'function') { + window.showVerifyModal(e, verifyForm); + } + }); }, _checkboxes() { diff --git a/resources/views/admin/users/index.blade.php b/resources/views/admin/users/index.blade.php index 524176007..2be1c6155 100644 --- a/resources/views/admin/users/index.blade.php +++ b/resources/views/admin/users/index.blade.php @@ -329,13 +329,15 @@
@if($user->deleted_at) - +
+ @csrf + +
@else Verify User -
@@ -431,12 +433,12 @@
@@ -444,10 +446,4 @@
- - @endsection - -{{-- Scripts moved to resources/js/csp-safe.js --}} diff --git a/tests/Feature/Admin/AdminUserControllerTest.php b/tests/Feature/Admin/AdminUserControllerTest.php index 974c928e0..8ec585e9d 100644 --- a/tests/Feature/Admin/AdminUserControllerTest.php +++ b/tests/Feature/Admin/AdminUserControllerTest.php @@ -188,6 +188,43 @@ class AdminUserControllerTest extends TestCase $this->assertSame($user->roles_id, $user->fresh()->roles_id); } + public function test_admin_user_list_shows_restore_form_only_for_deleted_users(): void + { + $admin = $this->createUserWithRole('Admin', false); + $activeUser = $this->createUserWithRole('User', true); + $deletedUser = $this->createUserWithRole('User', true); + $deletedUser->delete(); + + $response = $this->actingAs($admin)->get(route('admin.user-list')); + + $response->assertOk(); + $response->assertSee('action="'.route('admin.deleted.users.restore', $deletedUser->id).'"', false); + $response->assertDontSee('action="'.route('admin.deleted.users.restore', $activeUser->id).'"', false); + } + + public function test_admin_can_restore_soft_deleted_user(): void + { + $admin = $this->createUserWithRole('Admin', false); + $user = $this->createUserWithRole('User', true); + $user->delete(); + + $response = $this->actingAs($admin)->post(route('admin.deleted.users.restore', $user->id)); + + $response->assertRedirect(route('admin.deleted.users.index')); + $response->assertSessionHas('success', "User '{$user->username}' has been restored successfully."); + $this->assertNull($user->fresh()->deleted_at); + } + + public function test_admin_restore_returns_error_for_missing_user(): void + { + $admin = $this->createUserWithRole('Admin', false); + + $response = $this->actingAs($admin)->post(route('admin.deleted.users.restore', 9999)); + + $response->assertRedirect(route('admin.deleted.users.index')); + $response->assertSessionHas('error', 'User not found.'); + } + private function createSchema(): void { Schema::create('settings', function (Blueprint $table): void { @@ -230,6 +267,7 @@ class AdminUserControllerTest extends TestCase $table->string('verification_token')->nullable(); $table->timestamp('lastlogin')->nullable(); $table->rememberToken(); + $table->string('deleted_by')->nullable(); $table->timestamps(); $table->softDeletes(); });