mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 22:01:33 +00:00
Fix restore and verify buttons in admin user list
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -329,13 +329,15 @@
|
||||
<div class="flex gap-2">
|
||||
@if($user->deleted_at)
|
||||
<!-- Show restore button for deleted users -->
|
||||
<button type="button"
|
||||
class="restore-user-btn text-green-600 dark:text-green-400 hover:text-green-900 dark:hover:text-green-300 bg-transparent border-0 p-0 cursor-pointer"
|
||||
title="Restore User"
|
||||
data-user-id="{{ $user->id }}"
|
||||
data-username="{{ $user->username }}">
|
||||
<i class="fas fa-undo"></i>
|
||||
</button>
|
||||
<form action="{{ route('admin.deleted.users.restore', $user->id) }}" method="POST" class="inline-form">
|
||||
@csrf
|
||||
<button type="submit"
|
||||
class="text-green-600 dark:text-green-400 hover:text-green-900 dark:hover:text-green-300 bg-transparent border-0 p-0 cursor-pointer"
|
||||
title="Restore User"
|
||||
data-confirm="Are you sure you want to restore user '{{ $user->username }}'?">
|
||||
<i class="fas fa-undo"></i>
|
||||
</button>
|
||||
</form>
|
||||
@else
|
||||
<!-- Show normal actions for active users -->
|
||||
<a href="{{ url('admin/user-edit?id=' . $user->id) }}"
|
||||
@@ -419,7 +421,7 @@
|
||||
<i class="fas fa-check-circle text-green-600 dark:text-green-400 mr-2"></i>
|
||||
Verify User
|
||||
</h3>
|
||||
<button type="button" data-close-verify-modal class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300">
|
||||
<button type="button" @click="hide()" class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300">
|
||||
<i class="fas fa-times text-xl"></i>
|
||||
</button>
|
||||
</div>
|
||||
@@ -431,12 +433,12 @@
|
||||
</div>
|
||||
<div class="px-6 py-4 bg-gray-50 dark:bg-gray-900 border-t border-gray-200 dark:border-gray-700 flex justify-end space-x-3">
|
||||
<button type="button"
|
||||
data-close-verify-modal
|
||||
@click="hide()"
|
||||
class="px-4 py-2 bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition font-medium">
|
||||
<i class="fas fa-times mr-2"></i>Cancel
|
||||
</button>
|
||||
<button type="button"
|
||||
data-submit-verify-form
|
||||
@click="submit()"
|
||||
class="px-4 py-2 bg-green-600 dark:bg-green-700 text-white rounded-lg hover:bg-green-700 dark:hover:bg-green-800 transition font-medium">
|
||||
<i class="fas fa-check mr-2"></i>Verify
|
||||
</button>
|
||||
@@ -444,10 +446,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Hidden form for individual actions (restore deleted users) -->
|
||||
<form id="individualActionForm" method="POST" class="hidden">
|
||||
@csrf
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
{{-- Scripts moved to resources/js/csp-safe.js --}}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user