Skip to content

Commit

Permalink
fix: add messaging service sids to org shutdown email (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
bchrobot authored Sep 30, 2022
1 parent e5aef69 commit 3b16274
Showing 1 changed file with 51 additions and 36 deletions.
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

0 comments on commit 3b16274

Please sign in to comment.