diff --git a/apps/web/playwright/lib/orgMigration.ts b/apps/web/playwright/lib/orgMigration.ts index 926edeb7ec..30bdbb1933 100644 --- a/apps/web/playwright/lib/orgMigration.ts +++ b/apps/web/playwright/lib/orgMigration.ts @@ -653,6 +653,7 @@ async function dbRemoveUserFromOrg({ await ProfileRepository.deleteMany({ userIds: [userToRemoveFromOrg.id], + organizationId: userToRemoveFromOrg.organizationId!, }); } diff --git a/packages/features/profile/repositories/ProfileRepository.ts b/packages/features/profile/repositories/ProfileRepository.ts index 0f43a10aeb..42256d0e41 100644 --- a/packages/features/profile/repositories/ProfileRepository.ts +++ b/packages/features/profile/repositories/ProfileRepository.ts @@ -400,10 +400,10 @@ export class ProfileRepository implements IProfileRepository { }); } - static deleteMany({ userIds }: { userIds: number[] }) { + static deleteMany({ userIds, organizationId }: { userIds: number[]; organizationId: number }) { // Even though there can be just one profile matching a userId and organizationId, we are using deleteMany as it won't error if the profile doesn't exist return prisma.profile.deleteMany({ - where: { userId: { in: userIds } }, + where: { userId: { in: userIds }, organizationId }, }); } diff --git a/packages/trpc/server/routers/viewer/organizations/bulkDeleteUsers.handler.ts b/packages/trpc/server/routers/viewer/organizations/bulkDeleteUsers.handler.ts index da0d993e1e..8668e4d1cf 100644 --- a/packages/trpc/server/routers/viewer/organizations/bulkDeleteUsers.handler.ts +++ b/packages/trpc/server/routers/viewer/organizations/bulkDeleteUsers.handler.ts @@ -82,6 +82,7 @@ export async function bulkDeleteUsersHandler({ ctx, input }: BulkDeleteUsersHand id: { in: input.userIds, }, + organizationId: currentUserOrgId, }, data: { organizationId: null, @@ -130,6 +131,7 @@ export async function bulkDeleteUsersHandler({ ctx, input }: BulkDeleteUsersHand const removeProfiles = ProfileRepository.deleteMany({ userIds: input.userIds, + organizationId: currentUserOrgId, }); // We do this in a transaction to make sure that all memberships are removed before we remove the organization relation from the user