Skip to content

Commit d251302

Browse files
authored
fix: scope bulk user deletion to callers organization (calcom#28872)
1 parent cbb234c commit d251302

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

apps/web/playwright/lib/orgMigration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ async function dbRemoveUserFromOrg({
653653

654654
await ProfileRepository.deleteMany({
655655
userIds: [userToRemoveFromOrg.id],
656+
organizationId: userToRemoveFromOrg.organizationId!,
656657
});
657658
}
658659

packages/features/profile/repositories/ProfileRepository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ export class ProfileRepository implements IProfileRepository {
400400
});
401401
}
402402

403-
static deleteMany({ userIds }: { userIds: number[] }) {
403+
static deleteMany({ userIds, organizationId }: { userIds: number[]; organizationId: number }) {
404404
// 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
405405
return prisma.profile.deleteMany({
406-
where: { userId: { in: userIds } },
406+
where: { userId: { in: userIds }, organizationId },
407407
});
408408
}
409409

packages/trpc/server/routers/viewer/organizations/bulkDeleteUsers.handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export async function bulkDeleteUsersHandler({ ctx, input }: BulkDeleteUsersHand
8282
id: {
8383
in: input.userIds,
8484
},
85+
organizationId: currentUserOrgId,
8586
},
8687
data: {
8788
organizationId: null,
@@ -130,6 +131,7 @@ export async function bulkDeleteUsersHandler({ ctx, input }: BulkDeleteUsersHand
130131

131132
const removeProfiles = ProfileRepository.deleteMany({
132133
userIds: input.userIds,
134+
organizationId: currentUserOrgId,
133135
});
134136

135137
// We do this in a transaction to make sure that all memberships are removed before we remove the organization relation from the user

0 commit comments

Comments
 (0)