feat(roles): Rappasoft list, slim create form, and 2-tab role view
1. Roles list now uses a Rappasoft table (RoleTable): search/sort, per-row
view/edit/delete, and built-in bulk selection + 'Delete selected'. The
/admin/roles page is a plain view embedding <livewire:role-table />.
RoleForm create/edit now only has Name + Description (permissions removed).
2. New RoleView page (/admin/roles/{role}) with two tabs:
- 'Details': header with role name + Back button; description with Edit/Delete
buttons; table of users holding the role (avatar+name | last name | status).
- 'Permissions': all permissions grouped by section (by resource), each with a
toggle switch to grant/revoke for this role (Admin keeps 'manage all').
Removed the old RoleManager component/view (superseded).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,6 @@ use Livewire\Component;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\PermissionRegistrar;
|
||||
|
||||
#[Layout('layouts.app')]
|
||||
@@ -16,7 +15,6 @@ class RoleForm extends Component
|
||||
|
||||
public string $name = '';
|
||||
public string $description = '';
|
||||
public array $rolePermissions = [];
|
||||
|
||||
private const PROTECTED_ROLES = ['Admin'];
|
||||
private const CORE_PERMISSION = 'manage all';
|
||||
@@ -26,10 +24,9 @@ class RoleForm extends Component
|
||||
abort_unless(Auth::user()?->can(self::CORE_PERMISSION), 403);
|
||||
|
||||
if ($role && $role->exists) {
|
||||
$this->role = $role;
|
||||
$this->name = $role->name;
|
||||
$this->description = $role->description ?? '';
|
||||
$this->rolePermissions = $role->permissions->pluck('name')->toArray();
|
||||
$this->role = $role;
|
||||
$this->name = $role->name;
|
||||
$this->description = $role->description ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,26 +38,17 @@ class RoleForm extends Component
|
||||
], [], ['name' => 'nombre', 'description' => 'descripción']);
|
||||
|
||||
if ($this->role) {
|
||||
$isProtected = in_array($this->role->name, self::PROTECTED_ROLES, true);
|
||||
if (! $isProtected) {
|
||||
// Protected roles can't be renamed
|
||||
if (! in_array($this->role->name, self::PROTECTED_ROLES, true)) {
|
||||
$this->role->name = $this->name;
|
||||
}
|
||||
$this->role->description = $this->description ?: null;
|
||||
$this->role->save();
|
||||
|
||||
$perms = $this->rolePermissions;
|
||||
if ($this->role->name === 'Admin' && ! in_array(self::CORE_PERMISSION, $perms, true)) {
|
||||
$perms[] = self::CORE_PERMISSION;
|
||||
}
|
||||
$this->role->syncPermissions($perms);
|
||||
} else {
|
||||
$role = Role::create([
|
||||
Role::create([
|
||||
'name' => $this->name,
|
||||
'description' => $this->description ?: null,
|
||||
]);
|
||||
if (! empty($this->rolePermissions)) {
|
||||
$role->syncPermissions($this->rolePermissions);
|
||||
}
|
||||
}
|
||||
|
||||
app(PermissionRegistrar::class)->forgetCachedPermissions();
|
||||
@@ -72,7 +60,6 @@ class RoleForm extends Component
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.roles.role-form', [
|
||||
'permissions' => Permission::orderBy('name')->get(),
|
||||
'isProtected' => $this->role && in_array($this->role->name, self::PROTECTED_ROLES, true),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user