941dbd5997
Restores all files to thef8a1310security-review snapshot as requested, plus the 2 boot-critical fixes froma24c8a2(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. The7d854ffstate remains in history. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
65 lines
1.6 KiB
PHP
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');
|
|
}
|
|
} |