From 9c6f19f9a55c452dd6ad3de7ff61891d5ea8d510 Mon Sep 17 00:00:00 2001 From: esdrasrenan Date: Sun, 7 Dec 2025 03:49:09 -0300 Subject: [PATCH] Fix chat permission for machine-linked users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- convex/tickets.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/convex/tickets.ts b/convex/tickets.ts index 834a4d9..3cc9ce4 100644 --- a/convex/tickets.ts +++ b/convex/tickets.ts @@ -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"); }