Skip to content

Commit

Permalink
[Eng runner] Send email after github connection deletion (#2919)
Browse files Browse the repository at this point in the history
* [Eng runner] Send email after github connection deletion

Related [task](dust-tt/tasks#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
  • Loading branch information
philipperolet authored Dec 19, 2023
1 parent 2e01c60 commit 90b1aa3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion front/admin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 16 additions & 0 deletions front/lib/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ The Dust Team
console.log("ACTIVATION KEY SENT", user.email);
};

export async function sendGithubDeletionEmail(email: string): Promise<void> {
const cancelMessage = {
from: {
name: "Dust team",
email: "[email protected]",
},
subject: `[Dust] Github connection deleted - important information`,
html: `<p>Hello from Dust,</p>
<p>Your Dust connection to Github was deleted, along with all the related data on Dust servers.</p>
<p>You can now uninstall the Dust app from your Github account to revoke authorizations initially granted to Dust when you connected the Github account.</p>
<p>Please reply to this email if you have any questions.</p>
<p>The Dust team</p>`,
};
return sendEmail(email, cancelMessage);
}

/** Emails for cancelling / reactivating subscription */

export async function sendCancelSubscriptionEmail(
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -111,6 +113,9 @@ async function handler(
dustAPIProjectId,
});

if (dataSource.connectorProvider)
await warnPostDeletion(auth, dataSource.connectorProvider);

return res.status(200).json({ success: true });

default:
Expand All @@ -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);

0 comments on commit 90b1aa3

Please sign in to comment.