Skip to content

Commit

Permalink
fix: update profile fields periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Aug 30, 2024
1 parent 3c9e2d1 commit dfa4893
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"students": "SXXX"
},
"users": {
"admins": ["UXXX"]
"admins": ["UXXX"],
"devs": ["UXXX"]
}
},
"google": {
Expand Down
12 changes: 7 additions & 5 deletions src/slack/blocks/app_home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ import { getTaskKeys } from '~tasks'

export async function getAppHome(user_id: string) {
const homeTab = HomeTab()
if (config.slack.users.admins.includes(user_id)) {
const pending_requests = await getPendingHourSubmissionData()
const pending_certs = await prisma.memberCertRequest.findMany({ where: { state: 'pending' }, include: { Member: true, Cert: true, Requester: true } })

if (config.slack.users.devs.includes(user_id)) {
homeTab.blocks(
Blocks.Header().text('Admin Dashboard'),
Blocks.Header().text('Dev Dashboard'),
Blocks.Section()
.text('Manual Tasks')
.accessory(
Expand All @@ -29,6 +26,11 @@ export async function getAppHome(user_id: string) {
Elements.Button().text('Send Pending Requests').actionId(ActionIDs.SEND_PENDING_REQUESTS)
)
)
}
if (config.slack.users.admins.includes(user_id)) {
const pending_requests = await getPendingHourSubmissionData()
const pending_certs = await prisma.memberCertRequest.findMany({ where: { state: 'pending' }, include: { Member: true, Cert: true, Requester: true } })

homeTab.blocks(Blocks.Header().text('Pending Hour Submissions'))
if (pending_requests.length > 0) {
homeTab.blocks(pending_requests.flatMap((req) => [...getHourSubmissionBlocks(req), Blocks.Divider()]))
Expand Down
23 changes: 23 additions & 0 deletions src/tasks/certs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,26 @@ export async function announceNewCerts() {
}
await prisma.memberCert.updateMany({ where: { announced: false }, data: { announced: true } })
}

export async function updateProfileCerts() {
const members = await prisma.member.findMany({
where: { slack_id: {not: null} },
select: {
slack_id: true,
MemberCerts: {
select: { Cert: { select: { label: true } } }
}
}
})
for (const member of members) {
if (member.slack_id) {
await setProfileAttribute(
member.slack_id,
'certs',
member.MemberCerts.map((cert) => cert.Cert.label)
.sort(sortCertLabels)
.join(', ')
)
}
}
}
5 changes: 3 additions & 2 deletions src/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logger from '~lib/logger'
import { updateSlackUsergroups } from '~tasks/slack_groups'
import { syncSlackMembers } from '~tasks/slack'
import { announceNewCerts } from '~tasks/certs'
import { announceNewCerts, updateProfileCerts } from '~tasks/certs'
import { updateSheet } from '~spreadsheet'

type TaskFunc = (reason: string) => Promise<void>
Expand Down Expand Up @@ -41,7 +41,8 @@ export function scheduleTasks() {
tasks['Sync Sheet'] = scheduleTask(updateSheet, 60 * 30, isProd, 0) // Update spreadsheet every half-hour
tasks['Sync Members'] = scheduleTask(syncSlackMembers, 60 * 60, isProd, 0) // Update slack members every hour, can also be run manually on admin dashboard
tasks['Announce Certs'] = scheduleTask(announceNewCerts, 60 * 60, isProd, 60) // Just in case the cert announcement isn't automatically run on changes
tasks['Sync Departments'] = scheduleTask(updateSlackUsergroups, 60 * 60, isProd, 120)
tasks['Sync Usergroups'] = scheduleTask(updateSlackUsergroups, 60 * 60, isProd, 2*60)
tasks['Update Profile Certs'] = scheduleTask(updateProfileCerts, 60*60*24, isProd, 5*60)
}

export async function runTask(key: string) {
Expand Down

0 comments on commit dfa4893

Please sign in to comment.