From 90b1aa332c1fc5814d3483b6a24b1c09f2f82cd9 Mon Sep 17 00:00:00 2001 From: Philippe Rolet Date: Tue, 19 Dec 2023 09:40:42 +0100 Subject: [PATCH] [Eng runner] Send email after github connection deletion (#2919) * [Eng runner] Send email after github connection deletion Related [task](https://github.com/dust-tt/tasks/issues/283) Did not add the link because it depends on whether the account is individual or org, which `front` does not know (connectors might be able to get the info but making a route for that seems overkill) * Update front/lib/email.ts --- front/admin/cli.ts | 3 ++- front/lib/email.ts | 16 +++++++++++++ .../[wId]/data_sources/[name]/index.ts | 24 ++++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/front/admin/cli.ts b/front/admin/cli.ts index bbadd0e8e71c..bbcd3668f0f2 100644 --- a/front/admin/cli.ts +++ b/front/admin/cli.ts @@ -430,7 +430,8 @@ const dataSource = async (command: string, args: parseArgs.ParsedArgs) => { console.log( "\n\n...to fully scrub the customer data from our infra (GCS clean-up)." ); - + console.log(`WARNING: For Github datasource, the user may want to uninstall the app from Github + to revoke the authorization. If needed, send an email (cf template in lib/email.ts) `); return; } diff --git a/front/lib/email.ts b/front/lib/email.ts index 2997d5a8fa40..c85580807161 100644 --- a/front/lib/email.ts +++ b/front/lib/email.ts @@ -55,6 +55,22 @@ The Dust Team console.log("ACTIVATION KEY SENT", user.email); }; +export async function sendGithubDeletionEmail(email: string): Promise { + const cancelMessage = { + from: { + name: "Dust team", + email: "team@dust.tt", + }, + subject: `[Dust] Github connection deleted - important information`, + html: `

Hello from Dust,

+

Your Dust connection to Github was deleted, along with all the related data on Dust servers.

+

You can now uninstall the Dust app from your Github account to revoke authorizations initially granted to Dust when you connected the Github account.

+

Please reply to this email if you have any questions.

+

The Dust team

`, + }; + return sendEmail(email, cancelMessage); +} + /** Emails for cancelling / reactivating subscription */ export async function sendCancelSubscriptionEmail( diff --git a/front/pages/api/poke/workspaces/[wId]/data_sources/[name]/index.ts b/front/pages/api/poke/workspaces/[wId]/data_sources/[name]/index.ts index 6dc9a567b847..7428186ec787 100644 --- a/front/pages/api/poke/workspaces/[wId]/data_sources/[name]/index.ts +++ b/front/pages/api/poke/workspaces/[wId]/data_sources/[name]/index.ts @@ -1,9 +1,11 @@ -import { ConnectorsAPI } from "@dust-tt/types"; +import { ConnectorProvider, ConnectorsAPI } from "@dust-tt/types"; import { CoreAPI } from "@dust-tt/types"; import { ReturnedAPIErrorType } from "@dust-tt/types"; import { NextApiRequest, NextApiResponse } from "next"; +import { getMembers } from "@app/lib/api/workspace"; import { Authenticator, getSession } from "@app/lib/auth"; +import { sendGithubDeletionEmail } from "@app/lib/email"; import { DataSource } from "@app/lib/models"; import logger from "@app/logger/logger"; import { apiError, withLogging } from "@app/logger/withlogging"; @@ -111,6 +113,9 @@ async function handler( dustAPIProjectId, }); + if (dataSource.connectorProvider) + await warnPostDeletion(auth, dataSource.connectorProvider); + return res.status(200).json({ success: true }); default: @@ -124,4 +129,21 @@ async function handler( } } +async function warnPostDeletion( + auth: Authenticator, + dataSourceProvider: ConnectorProvider +) { + // if the datasource is Github, send an email inviting to delete the Github app + switch (dataSourceProvider) { + case "github": + // get admin emails + const adminEmails = (await getMembers(auth, "admin")).map((u) => u.email); + // send email to admins + for (const email of adminEmails) await sendGithubDeletionEmail(email); + break; + default: + break; + } +} + export default withLogging(handler);