Fix chat permission for machine-linked users

Allow COLLABORATOR users who are linked to the ticket's machine
(via assignedUserId or linkedUserIds) to access the chat, not
just the ticket requester.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
esdrasrenan 2025-12-07 03:49:09 -03:00
parent ebeda62cfb
commit 9c6f19f9a5

View file

@ -1018,10 +1018,23 @@ async function requireTicketChatParticipant(
return { user: viewer.user, role: normalizedRole, kind: "manager" };
}
if (normalizedRole === "COLLABORATOR") {
if (String(ticket.requesterId) !== String(viewer.user._id)) {
throw new ConvexError("Apenas o solicitante pode conversar neste chamado");
// Verificar se e o solicitante
if (String(ticket.requesterId) === String(viewer.user._id)) {
return { user: viewer.user, role: normalizedRole, kind: "requester" };
}
return { user: viewer.user, role: normalizedRole, kind: "requester" };
// Verificar se esta vinculado a maquina do ticket
if (ticket.machineId) {
const machine = await ctx.db.get(ticket.machineId);
if (machine) {
const isLinkedToMachine =
machine.assignedUserId?.toString() === viewer.user._id.toString() ||
machine.linkedUserIds?.some((id) => id.toString() === viewer.user._id.toString());
if (isLinkedToMachine) {
return { user: viewer.user, role: normalizedRole, kind: "requester" };
}
}
}
throw new ConvexError("Apenas o solicitante pode conversar neste chamado");
}
throw new ConvexError("Usuário não possui acesso ao chat deste chamado");
}