Replace hasRoles calls with hasPermission in all server actions and page components. Update qualification checks (logistics, intelligence) to use permission-based checks instead of role name matching. Update staff lookup in tickets/staff.ts to query roles collection. Use enlistmentDate field on profile page instead of createdAt.
34 lines
1,013 B
TypeScript
34 lines
1,013 B
TypeScript
/**
|
|
* Helpdesk staff resolution. "Staff" = users with the `admin` or `developer`
|
|
* role — the people who can manage tickets. Used to fan out notifications when
|
|
* a new ticket is created.
|
|
*/
|
|
|
|
type PayloadType = Awaited<ReturnType<typeof import("payload").getPayload>>;
|
|
|
|
export async function getStaffUserIds(payload: PayloadType): Promise<number[]> {
|
|
try {
|
|
const adminRole = await payload.find({
|
|
collection: "roles",
|
|
where: { slug: { in: ["admin", "developer"] } },
|
|
limit: 2,
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
});
|
|
const roleIds = adminRole.docs.map((d) => d.id);
|
|
if (roleIds.length === 0) return [];
|
|
|
|
const res = await payload.find({
|
|
collection: "users",
|
|
where: { roleDocs: { in: roleIds } },
|
|
limit: 50,
|
|
depth: 0,
|
|
select: { username: true },
|
|
overrideAccess: true,
|
|
});
|
|
return res.docs.map((d) => d.id);
|
|
} catch (err) {
|
|
console.error("[Tickets] Failed to resolve staff recipients:", err);
|
|
return [];
|
|
}
|
|
}
|