Skip to content

Commit 8b041dc

Browse files
authored
Fix/deactivation email sending to past isomer members (#1755)
* fix(inactiveUsers.service): update email filtering to exclude past and former Isomer members * fix(inactiveUsers.service): enhance email filtering to exclude past Isomer members * fix(inactiveUsers.service): update email notification logic to include past Isomer members
1 parent c1c6255 commit 8b041dc

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

apps/studio/src/server/modules/user/__tests__/inactiveUsers.service.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { ISOMER_ADMINS_AND_MIGRATORS_EMAILS } from "~prisma/constants"
1+
import {
2+
ISOMER_ADMINS_AND_MIGRATORS_EMAILS,
3+
PAST_AND_FORMER_ISOMER_MEMBERS_EMAILS,
4+
PAST_ISOMER_MEMBERS,
5+
} from "~prisma/constants"
26
import { resetTables } from "tests/integration/helpers/db"
37
import {
48
setupAdminPermissions,
@@ -374,15 +378,15 @@ describe("inactiveUsers.service", () => {
374378
expect(sendAccountDeactivationEmail).toHaveBeenCalledTimes(1)
375379
})
376380

377-
it("should not include isomer admins and migrators in the email", async () => {
381+
it("should not include isomer admins and migrators (including former members) in the email", async () => {
378382
// Arrange
379383
const userToDeactivate = await setupUserWrapper({
380384
siteId: site.id,
381385
createdDaysAgo: 91,
382386
lastLoginDaysAgo: null,
383387
})
384388
await Promise.all(
385-
ISOMER_ADMINS_AND_MIGRATORS_EMAILS.map((email) =>
389+
PAST_AND_FORMER_ISOMER_MEMBERS_EMAILS.map((email) =>
386390
setupUserWrapper({
387391
siteId: site.id,
388392
email,
@@ -396,7 +400,11 @@ describe("inactiveUsers.service", () => {
396400
await bulkDeactivateInactiveUsers()
397401

398402
// Assert
399-
expect(sendAccountDeactivationEmail).toHaveBeenCalledTimes(1) // send to deactivated user
403+
expect(sendAccountDeactivationEmail).toHaveBeenCalledTimes(
404+
1 +
405+
// we actually want to send the email to ex-isomer members as well
406+
PAST_ISOMER_MEMBERS.length,
407+
) // send to deactivated user and all past isomer members
400408
expect(sendAccountDeactivationEmail).toHaveBeenCalledWith({
401409
recipientEmail: userToDeactivate.email,
402410
sitesAndAdmins: expect.any(Array),

apps/studio/src/server/modules/user/inactiveUsers.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ISOMER_ADMINS_AND_MIGRATORS_EMAILS } from "~prisma/constants"
1+
import {
2+
ISOMER_ADMINS_AND_MIGRATORS_EMAILS,
3+
PAST_AND_FORMER_ISOMER_MEMBERS_EMAILS,
4+
} from "~prisma/constants"
25
import { startOfDay, subDays } from "date-fns"
36
import { toZonedTime } from "date-fns-tz"
47

@@ -188,7 +191,7 @@ const getSiteAndAdmins = async ({ userId, siteIds }: GetSiteAndAdminsProps) => {
188191
.where("ResourcePermission.userId", "!=", userId) // don't want to ask users to ask themselves for permissions
189192
.where("ResourcePermission.deletedAt", "is", null)
190193
.where("ResourcePermission.role", "=", RoleType.Admin) // should only give the admin emails to request reactivation permissions from
191-
.where("User.email", "not in", ISOMER_ADMINS_AND_MIGRATORS_EMAILS) // we don't want to send emails to admins and migrators
194+
.where("User.email", "not in", PAST_AND_FORMER_ISOMER_MEMBERS_EMAILS) // we don't want to send emails to admins and migrators
192195
.select([
193196
"Site.id as siteId",
194197
db.fn.agg<string[]>("array_agg", ["User.email"]).as("adminEmails"),

0 commit comments

Comments
 (0)