Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add messaging service sids to org shutdown email #1440

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 51 additions & 36 deletions src/server/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3419,43 +3419,58 @@ const rootMutations = {
.where({ id: organizationId })
.update({ deleted_at: null, deleted_by: null });
} else {
await r
.knex("organization")
.where({ id: organizationId })
.update({ deleted_at: r.knex.fn.now(), deleted_by: user.id });

switch (deactivateMode) {
case DeactivateMode.Nosuspend:
break;
case DeactivateMode.Suspendall:
await r
.knex("user_organization")
.where({ organization_id: organizationId })
.whereNot({ role: UserRoleType.OWNER })
.update({ role: UserRoleType.SUSPENDED });
break;
case DeactivateMode.Deleteall:
{
await r
.knex("user_organization")
.where({ organization_id: organizationId })
.delete();

const org = await r
.knex("organization")
.where({ id: organizationId })
.first();
await r.knex.transaction(async (trx) => {
await trx("organization")
.where({ id: organizationId })
.update({ deleted_at: r.knex.fn.now(), deleted_by: user.id });

await sendEmail({
to: "support@spokerewired.com",
subject: "Automated organization shutdown request",
text: `This is an automated org shutdown request triggered through the superadmin. Organization id: ${organizationId}, name: ${org.name}, from instance hosted at ${config.BASE_URL}.`
});
}
break;
default:
break;
}
switch (deactivateMode) {
case DeactivateMode.Nosuspend:
break;
case DeactivateMode.Suspendall:
await trx("user_organization")
.where({ organization_id: organizationId })
.whereNot({ role: UserRoleType.OWNER })
.update({ role: UserRoleType.SUSPENDED });
break;
case DeactivateMode.Deleteall:
{
await trx("user_organization")
.where({ organization_id: organizationId })
.delete();

const org = await r
.reader("organization")
.where({ id: organizationId })
.first(["name"]);

const messagingServices = await r
.reader("messaging_service")
.where({ organization_id: organizationId })
.select("messaging_service_sid");

const messagingServiceSids = messagingServices
.map(({ messaging_service_sid }) => messaging_service_sid)
.join("\n");
const switchboard = config.SWITCHBOARD_BASE_URL ?? "[default]";

const text = [
"This is an automated org shutdown request triggered through the superadmin.",
`Organization id: ${organizationId}, name: ${org.name}, from instance hosted at ${config.BASE_URL}.`,
`Switchboard ${switchboard}, profiles:\n${messagingServiceSids}`
].join("\n\n");

await sendEmail({
to: "support@spokerewired.com",
subject: "Automated organization shutdown request",
text
});
}
break;
default:
break;
}
});
}
return true;
},
Expand Down