Skip to content

Commit

Permalink
add reminder for unapproved users
Browse files Browse the repository at this point in the history
  • Loading branch information
polypixeldev committed Dec 12, 2024
1 parent 7d45593 commit 9029b77
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
1 change: 1 addition & 0 deletions quetzal/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ model users {
ssh_public_key String
description String
is_approved Boolean? @default(false)
message_id String?
created_at DateTime? @default(dbgenerated("'1970-01-01 00:00:00+00'::timestamp with time zone")) @db.Timestamptz(6)
}
29 changes: 29 additions & 0 deletions quetzal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as events from "./events/index.js";
import * as actions from "./actions/index.js";
import * as views from "./views/index.js";
import populate_users from "./util/populate_users.js";
import { prisma } from "./util/prisma.js";

import "dotenv/config";

Expand Down Expand Up @@ -31,6 +32,34 @@ if (process.env.POPULATE_USERS === "true") {
populate_users();
}

// Reminder for forgotten approvals
setInterval(
async () => {
const users = await prisma.users.findMany({
where: {
is_approved: null,
},
});

for (const user of users) {
if (user.message_id) {
app.client.chat.postMessage({
channel: "C05VBD1B7V4",
reply_broadcast: true,
thread_ts: user.message_id,
text: `Reminder: @${user.slack_user_id} is waiting on a response!`,
});
} else {
app.client.chat.postMessage({
channel: "C05VBD1B7V4",
text: `Reminder: @${user.slack_user_id} is waiting on a response!`,
});
}
}
},
24 * 60 * 60 * 1000, // every 24 hours
);

(async () => {
await app.start(process.env.PORT ?? 3000);

Expand Down
27 changes: 14 additions & 13 deletions quetzal/src/views/register_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,7 @@ export function register_user(app: Slack.App) {

ack();

await prisma.users.create({
data: {
slack_user_id: body.user.id,
name,
email,
ssh_public_key: key.toString("ssh"),
description,
tilde_username: username,
created_at: new Date()
},
});

await client.chat.postMessage({
const slackApprovalMsg = await client.chat.postMessage({
channel: "C05VBD1B7V4", // private #nest-registration channel id
blocks: approval_message(
body.user.id,
Expand All @@ -125,6 +113,19 @@ export function register_user(app: Slack.App) {
text: `<@${body.user.id}> is requesting an approval for Nest`,
});

await prisma.users.create({
data: {
slack_user_id: body.user.id,
name,
email,
ssh_public_key: key.toString("ssh"),
description,
tilde_username: username,
created_at: new Date(),
message_id: slackApprovalMsg.ts,
},
});

await client.views.publish({
user_id: body.user.id,
view: unapproved_home(name, username, email, ssh_key),
Expand Down

0 comments on commit 9029b77

Please sign in to comment.