Files
construprogress/app/Livewire/ProjectUsers.php
T
javier c44958ac16 revert: roll back to 7d854ff (pre-security-review state)
Restores all 27 files changed by the security commit (f8a1310) and later
work back to their 7d854ff state (2026-06-16 18:05), as requested. The
security rewrite regressed map functionality (tabs, inspection editor,
collapsing layers panel) without adding protections the 7d854ff version
did not already have (XSS escaping + IDOR checks were already present).

Done as a forward commit (no history rewrite / force-push) so f8a1310,
a24c8a2 and the merge remain in history and are fully recoverable.

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

81 lines
2.3 KiB
PHP

<?php
namespace App\Livewire;
use Livewire\Component;
use App\Models\Project;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
class ProjectUsers extends Component
{
public Project $project;
public $assignedUsers = [];
public $allUsers = [];
public $selectedUserId = '';
public $selectedRole = 'viewer';
public function mount(Project $project)
{
$this->project = $project;
$this->loadUsers();
}
public function loadUsers()
{
$this->assignedUsers = $this->project->users()->withPivot('role_in_project')->get();
$assignedIds = $this->assignedUsers->pluck('id')->toArray();
$this->allUsers = User::whereNotIn('id', $assignedIds)->orderBy('name')->get();
}
public function assignUser()
{
$user = Auth::user();
if (!$user->can('assign users') && !$user->hasRole('Admin')) {
session()->flash('error', 'No tienes permisos para asignar usuarios.');
return;
}
$this->validate([
'selectedUserId' => 'required|exists:users,id',
'selectedRole' => 'required|in:supervisor,consultant,client,viewer',
]);
$this->project->users()->attach($this->selectedUserId, [
'role_in_project' => $this->selectedRole
]);
$this->reset(['selectedUserId', 'selectedRole']);
$this->loadUsers();
$this->dispatch('notify', 'Usuario asignado al proyecto.');
}
public function removeUser($userId)
{
$user = Auth::user();
if (!$user->can('assign users') && !$user->hasRole('Admin')) {
session()->flash('error', 'Sin permisos.');
return;
}
$this->project->users()->detach($userId);
$this->loadUsers();
$this->dispatch('notify', 'Usuario eliminado del proyecto.');
}
public function changeRole($userId, $role)
{
if (!in_array($role, ['supervisor', 'consultant', 'client', 'viewer'])) return;
$this->project->users()->updateExistingPivot($userId, [
'role_in_project' => $role
]);
$this->loadUsers();
$this->dispatch('notify', 'Rol actualizado.');
}
public function render()
{
return view('livewire.project-users');
}
}