From 4b23a8d2ff88f26d18ab6579bc5a76fe4bbec1ab Mon Sep 17 00:00:00 2001 From: Zach R Date: Sun, 27 Oct 2024 18:26:07 -0700 Subject: [PATCH] fix: don't add inactive users to usergroups --- src/lib/cert_operations.ts | 7 ++++++- src/slack/blocks/certify.ts | 2 +- src/tasks/slack_groups.ts | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/cert_operations.ts b/src/lib/cert_operations.ts index 2af9eda..cc30f9c 100644 --- a/src/lib/cert_operations.ts +++ b/src/lib/cert_operations.ts @@ -95,6 +95,7 @@ export async function getManagers() { select: { Member: { select: { + active: true, email: true, slack_id: true } @@ -108,6 +109,10 @@ export async function getManagers() { return departments.map((dept) => ({ dept, - managers: dept.Certs.flatMap((cert) => cert.Instances.map((instance) => instance.Member.slack_id).filter((v) => v != null)) + managers: dept.Certs.flatMap((cert) => + cert.Instances.filter((instance) => instance.Member.active) + .map((instance) => instance.Member.slack_id) + .filter((v) => v != null) + ) })) } diff --git a/src/slack/blocks/certify.ts b/src/slack/blocks/certify.ts index ae888e5..599f090 100644 --- a/src/slack/blocks/certify.ts +++ b/src/slack/blocks/certify.ts @@ -6,7 +6,7 @@ import config from '~config' export async function getCertifyModal(user: Prisma.MemberWhereUniqueInput) { const manager = await prisma.member.findUnique({ - where: user, + where: { ...user, active: true }, select: { MemberCerts: { where: { Cert: { isManager: true } }, diff --git a/src/tasks/slack_groups.ts b/src/tasks/slack_groups.ts index b9fef24..0c62451 100644 --- a/src/tasks/slack_groups.ts +++ b/src/tasks/slack_groups.ts @@ -20,7 +20,7 @@ export async function updateSlackUsergroups() { } const usergroups_list = await slack_client.usergroups.list({ include_disabled: true }) const usergroups = new Map(usergroups_list.usergroups!.map((g) => [g.id!, g])) - const departments = await prisma.department.findMany({ include: { Members: { select: { Member: { select: { slack_id: true } } } } } }) + const departments = await prisma.department.findMany({ include: { Members: { select: { Member: { select: { slack_id: true, active: true } } } } } }) const syncUsergroup = async (data: { department_id: string; group_id: string | null; title: string; handle: string; member_ids: string[] }) => { const existing = usergroups.get(data.group_id ?? '') let returnValue: { group_id: string; isNew: boolean } @@ -80,7 +80,7 @@ export async function updateSlackUsergroups() { group_id: department.slack_group, title: department.name, handle: department.name.toLowerCase().replace(' ', '-') + '-dept', - member_ids: department.Members.filter((m) => m.Member.slack_id != null).map((m) => m.Member.slack_id!) + member_ids: department.Members.filter((m) => m.Member.slack_id != null && m.Member.active).map((m) => m.Member.slack_id!) }) if (res?.isNew) { await prisma.department.update({