Skip to content

Commit

Permalink
fix: don't add inactive users to usergroups
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Oct 28, 2024
1 parent d148264 commit 4b23a8d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/lib/cert_operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export async function getManagers() {
select: {
Member: {
select: {
active: true,
email: true,
slack_id: true
}
Expand All @@ -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)
)
}))
}
2 changes: 1 addition & 1 deletion src/slack/blocks/certify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/slack_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 4b23a8d

Please sign in to comment.