fix: scope bulk user deletion to callers organization (#28872)
This commit is contained in:
1 parent
cbb234cb35
commit
d25130274f
3 files changed
+5
-2
No files matched your search
@@ -653,6 +653,7 @@ async function dbRemoveUserFromOrg({
|
||||
|
||||
await ProfileRepository.deleteMany({
|
||||
userIds: [userToRemoveFromOrg.id],
|
||||
organizationId: userToRemoveFromOrg.organizationId!,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user