feat(roles/users): add-user form on role view + per-user direct permissions form
1. Role view (Details tab): a small form to add users to the role (select of users not yet in the role + Add) and a per-row remove button. Uses assignRole/removeRole. 2. User view (Permissions tab): the same grouped, collapsible permissions form with switches — operating on the user's DIRECT permissions (givePermissionTo/revokePermissionTo). Permissions inherited from a role show as checked+disabled with a 'from role' tag; per-group All/None too. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
<div class="py-8 max-w-4xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="py-8 max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
|
||||
{{-- Cabecera: nombre del rol + botón Volver --}}
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h2 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
|
||||
<x-heroicon-o-shield-check class="w-6 h-6 text-primary" />
|
||||
{{ $role->name }}
|
||||
@if($isProtected)
|
||||
<span class="badge badge-ghost badge-sm">{{ __('protected') }}</span>
|
||||
@endif
|
||||
</h2>
|
||||
<a href="{{ route('admin.roles') }}" class="btn btn-ghost btn-sm gap-1" wire:navigate>
|
||||
<x-heroicon-o-arrow-left class="w-4 h-4" /> {{ __('Back') }}
|
||||
</a>
|
||||
</div>
|
||||
<x-slot name="header">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h2 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
|
||||
<x-heroicon-o-shield-check class="w-6 h-6 text-primary" />
|
||||
{{ $role->name }}
|
||||
@if($isProtected)
|
||||
<span class="badge badge-ghost badge-sm">{{ __('protected') }}</span>
|
||||
@endif
|
||||
</h2>
|
||||
<a href="{{ route('admin.roles') }}" class="btn btn-ghost btn-sm gap-1" wire:navigate>
|
||||
<x-heroicon-o-arrow-left class="w-4 h-4" /> {{ __('Back') }}
|
||||
</a>
|
||||
</div>
|
||||
</x-slot>
|
||||
|
||||
{{-- Tabs --}}
|
||||
<div class="flex flex-wrap gap-1 mb-4">
|
||||
@@ -49,9 +51,24 @@
|
||||
|
||||
{{-- Usuarios con este rol --}}
|
||||
<div class="bg-white rounded-lg shadow overflow-hidden">
|
||||
<div class="px-6 py-3 border-b border-base-200">
|
||||
<div class="px-6 py-3 border-b border-base-200 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
|
||||
<h3 class="font-semibold text-gray-700">{{ __('Users with this role') }} ({{ $users->count() }})</h3>
|
||||
{{-- Formulario para añadir un usuario al rol --}}
|
||||
<form wire:submit.prevent="addUser" class="flex items-center gap-2">
|
||||
<select wire:model="newUserId" class="select select-bordered select-sm w-56 @error('newUserId') select-error @enderror">
|
||||
<option value="">{{ __('Select a user...') }}</option>
|
||||
@foreach($availableUsers as $au)
|
||||
<option value="{{ $au->id }}">
|
||||
{{ trim(($au->first_name ?? '').' '.($au->last_name ?? '')) ?: $au->name }} — {{ $au->email }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<button class="btn btn-sm btn-primary gap-1">
|
||||
<x-heroicon-o-plus class="w-4 h-4" /> {{ __('Add') }}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
@error('newUserId') <p class="text-error text-xs px-6 pt-2">{{ $message }}</p> @enderror
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-zebra">
|
||||
<thead>
|
||||
@@ -59,6 +76,7 @@
|
||||
<th>{{ __('Name') }}</th>
|
||||
<th>{{ __('Last name') }}</th>
|
||||
<th>{{ __('Status') }}</th>
|
||||
<th class="w-12"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -89,9 +107,16 @@
|
||||
@endphp
|
||||
<span class="badge badge-sm {{ $cls }}">{{ $label }}</span>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<button wire:click="removeUser({{ $u->id }})"
|
||||
wire:confirm="{{ __('Remove this user from the role?') }}"
|
||||
class="btn btn-ghost btn-xs text-error" title="{{ __('Remove') }}">
|
||||
<x-heroicon-o-x-mark class="w-4 h-4" />
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="3" class="text-center text-gray-400 py-8">{{ __('No users with this role') }}</td></tr>
|
||||
<tr><td colspan="4" class="text-center text-gray-400 py-8">{{ __('No users with this role') }}</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -134,7 +159,7 @@
|
||||
@endif
|
||||
</div>
|
||||
<input type="checkbox"
|
||||
class="toggle toggle-primary toggle-sm shrink-0"
|
||||
class="toggle toggle-sm toggle-primary"
|
||||
wire:key="perm-{{ $role->id }}-{{ $perm->id }}"
|
||||
@checked(in_array($perm->name, $rolePerms, true))
|
||||
wire:click="togglePermission('{{ $perm->name }}')" />
|
||||
|
||||
Reference in New Issue
Block a user