Assignee picker: return only ADMIN/AGENT (exclude collaborators/managers)

This commit is contained in:
Esdras Renan 2025-10-19 03:03:10 -03:00
parent 51d92b230e
commit 2607ca5ce3

View file

@ -2,7 +2,10 @@ import { mutation, query } from "./_generated/server";
import { ConvexError, v } from "convex/values";
import { requireAdmin } from "./rbac";
const STAFF_ROLES = new Set(["ADMIN", "MANAGER", "AGENT", "COLLABORATOR"]);
// All roles that have staff-level access in some areas. Do NOT include COLLABORATOR here
// to avoid leaking collaborators into staff pickers such as "responsável".
const STAFF_ROLES = new Set(["ADMIN", "MANAGER", "AGENT"]);
const INTERNAL_STAFF_ROLES = new Set(["ADMIN", "AGENT"]);
export const ensureUser = mutation({
args: {
@ -81,11 +84,9 @@ export const listAgents = query({
.withIndex("by_tenant", (q) => q.eq("tenantId", tenantId))
.collect();
// Only internal staff (ADMIN/AGENT) should appear as responsáveis
return users
.filter((user) => {
const normalizedRole = (user.role ?? "AGENT").toUpperCase();
return STAFF_ROLES.has(normalizedRole);
})
.filter((user) => INTERNAL_STAFF_ROLES.has((user.role ?? "AGENT").toUpperCase()))
.sort((a, b) => a.name.localeCompare(b.name, "pt-BR"));
},
});