Files
construprogress/app/Livewire/AdminUsers.php
T
javier 941dbd5997 restore: bring back f8a1310 (security review) state
Restores all files to the f8a1310 security-review snapshot as requested,
plus the 2 boot-critical fixes from a24c8a2 (config/session.php env()
instead of app()->environment(), and removal of the duplicate $activeTab
in ProjectMap.php) so the application actually boots.

Forward commit, no history rewrite. The 7d854ff state remains in history.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 10:36:44 +02:00

65 lines
1.6 KiB
PHP

<?php
namespace App\Livewire;
use Livewire\Component;
use App\Models\User;
use Spatie\Permission\Models\Role;
use Illuminate\Support\Facades\Auth;
class AdminUsers extends Component
{
public $users;
public $roles;
public function mount()
{
if (!Auth::user()->hasRole('Admin')) {
abort(403);
}
$this->roles = Role::all();
$this->loadUsers();
}
public function loadUsers()
{
$this->users = User::with('roles')->orderBy('name')->get();
}
public function updateRole($userId, $roleName)
{
$user = Auth::user();
if (!$user->hasRole('Admin')) {
session()->flash('error', 'Solo administradores.');
return;
}
$targetUser = User::findOrFail($userId);
if ($targetUser->id === $user->id && $targetUser->hasRole('Admin')) {
session()->flash('error', 'No puedes cambiarte el rol a ti mismo.');
return;
}
$targetUser->syncRoles([$roleName]);
$this->loadUsers();
$this->dispatch('notify', 'Rol actualizado.');
}
public function deleteUser(int $userId): void
{
if (!Auth::user()->hasRole('Admin')) abort(403);
if ($userId === Auth::id()) {
session()->flash('error', 'No puedes eliminarte a ti mismo.');
return;
}
User::findOrFail($userId)->delete();
session()->flash('message', 'Usuario eliminado.');
$this->loadUsers();
}
public function render()
{
return view('livewire.admin-users');
}
}