generated from thegrind/laravel-dockerized
Move user management to its own page
This commit is contained in:
parent
292ec10b48
commit
a6d3b533ca
@ -8,8 +8,10 @@ use App\Models\User;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
|
||||
#[Layout('components.layouts.app')]
|
||||
class ManageUsers extends Component
|
||||
{
|
||||
public string $invite_email = '';
|
||||
@ -19,11 +21,9 @@ class ManageUsers extends Component
|
||||
|
||||
public function mount()
|
||||
{
|
||||
// Only load data if user is authorized to view it
|
||||
if (auth()->user()->can('viewAny', User::class)) {
|
||||
$this->users = User::all();
|
||||
$this->invitations = Invitation::orderBy('accepted_at', 'desc')->get();
|
||||
}
|
||||
// Load data since route is already protected by middleware
|
||||
$this->users = User::all();
|
||||
$this->invitations = Invitation::orderBy('accepted_at', 'desc')->get();
|
||||
}
|
||||
|
||||
public function inviteUser()
|
||||
@ -106,6 +106,6 @@ class ManageUsers extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.manage-users');
|
||||
return view('livewire.manage-users')->title('User Management');
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,12 @@
|
||||
wire:navigate>
|
||||
{{ __('Apps') }}
|
||||
</flux:navbar.item>
|
||||
@can('viewAny', App\Models\User::class)
|
||||
<flux:navbar.item icon="users" :href="route('admin.users')" :current="request()->routeIs('admin.users')"
|
||||
wire:navigate>
|
||||
{{ __('User Management') }}
|
||||
</flux:navbar.item>
|
||||
@endcan
|
||||
</flux:navbar>
|
||||
|
||||
<flux:spacer />
|
||||
@ -90,6 +96,12 @@
|
||||
:current="request()->routeIs('dashboard')" wire:navigate>
|
||||
{{ __('Dashboard') }}
|
||||
</flux:navlist.item>
|
||||
@can('viewAny', App\Models\User::class)
|
||||
<flux:navlist.item icon="users" :href="route('admin.users')"
|
||||
:current="request()->routeIs('admin.users')" wire:navigate>
|
||||
{{ __('User Management') }}
|
||||
</flux:navlist.item>
|
||||
@endcan
|
||||
</flux:navlist.group>
|
||||
</flux:navlist>
|
||||
|
||||
|
@ -14,6 +14,9 @@
|
||||
<flux:navlist variant="outline">
|
||||
<flux:navlist.group :heading="__('Platform')" class="grid">
|
||||
<flux:navlist.item icon="home" :href="route('dashboard')" :current="request()->routeIs('dashboard')" wire:navigate>{{ __('Dashboard') }}</flux:navlist.item>
|
||||
@can('viewAny', App\Models\User::class)
|
||||
<flux:navlist.item icon="users" :href="route('admin.users')" :current="request()->routeIs('admin.users')" wire:navigate>{{ __('User Management') }}</flux:navlist.item>
|
||||
@endcan
|
||||
</flux:navlist.group>
|
||||
</flux:navlist>
|
||||
|
||||
|
@ -1,11 +1,5 @@
|
||||
<x-layouts.app :title="__('Dashboard')">
|
||||
<div class="max-w-4xl mx-auto py-12">
|
||||
@can('viewAny', App\Models\User::class)
|
||||
<div class="mb-4">
|
||||
<livewire:manage-users />
|
||||
</div>
|
||||
@endcan
|
||||
|
||||
<div class="grid grid-cols-2">
|
||||
<livewire:forms.user-profile />
|
||||
</div>
|
||||
|
@ -1,4 +1,4 @@
|
||||
@can('viewAny', App\Models\User::class)
|
||||
<div class="max-w-4xl mx-auto py-12">
|
||||
<div>
|
||||
<div class="flex justify-between items-center">
|
||||
<flux:heading size="xl">Users</flux:heading>
|
||||
@ -95,4 +95,4 @@
|
||||
</flux:modal>
|
||||
@endcan
|
||||
</div>
|
||||
@endcan
|
||||
</div>
|
@ -2,6 +2,7 @@
|
||||
|
||||
use App\Http\Controllers\OIDCController;
|
||||
use App\Livewire\ConsentScreen;
|
||||
use App\Livewire\ManageUsers;
|
||||
use App\Livewire\Settings\Appearance;
|
||||
use App\Livewire\Settings\Password;
|
||||
use App\Livewire\Settings\Profile;
|
||||
@ -19,6 +20,10 @@ Route::view('dashboard', 'dashboard')
|
||||
->middleware(['auth', 'verified'])
|
||||
->name('dashboard');
|
||||
|
||||
Route::get('admin/users', ManageUsers::class)
|
||||
->middleware(['auth', 'can:viewAny,App\Models\User'])
|
||||
->name('admin.users');
|
||||
|
||||
Route::middleware(['auth'])->group(function () {
|
||||
Route::redirect('settings', 'settings/profile');
|
||||
|
||||
|
59
tests/Feature/UserManagementPageTest.php
Normal file
59
tests/Feature/UserManagementPageTest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->admin = User::factory()->create(['is_admin' => true]);
|
||||
$this->user = User::factory()->create(['is_admin' => false]);
|
||||
});
|
||||
|
||||
describe('User Management Page', function () {
|
||||
|
||||
it('allows admin users to access the user management page', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
$response = $this->get(route('admin.users'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('User Management');
|
||||
$response->assertSee('Users');
|
||||
$response->assertSee('Invitations');
|
||||
});
|
||||
|
||||
it('prevents non-admin users from accessing the user management page', function () {
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$response = $this->get(route('admin.users'));
|
||||
|
||||
$response->assertStatus(403);
|
||||
});
|
||||
|
||||
it('redirects unauthenticated users to login', function () {
|
||||
$response = $this->get(route('admin.users'));
|
||||
|
||||
$response->assertRedirect(route('login'));
|
||||
});
|
||||
|
||||
it('shows the user management navigation link only to admins', function () {
|
||||
// Test admin sees the link
|
||||
$this->actingAs($this->admin);
|
||||
$response = $this->get(route('dashboard'));
|
||||
$response->assertSee('User Management');
|
||||
|
||||
// Test regular user doesn't see the link in navigation
|
||||
$this->actingAs($this->user);
|
||||
$response = $this->get(route('dashboard'));
|
||||
$response->assertDontSee('href="' . route('admin.users') . '"', false);
|
||||
});
|
||||
|
||||
it('properly displays the page title', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
$response = $this->get(route('admin.users'));
|
||||
|
||||
$response->assertSee('<title>User Management</title>', false);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user