fix: getBookings for team admins within orgs (#21833)
* fix: getBookings for team admins within orgs * fixup! fix: getBookings for team admins within orgs * chore: update getUserIdsAndEmailsWhereUserIsAdminOrOwner and remove unused orgId --------- Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
1 parent
0a60864310
commit
3dd3372c35
10 files changed
+51
-32
No files matched your search
@@ -123,7 +123,7 @@ export async function getBookings({
|
||||
getAttendeeEmailsFromUserIdsFilter(prisma, user.email, filters?.userIds),
|
||||
getEventTypeIdsFromEventTypeIdsFilter(prisma, filters?.eventTypeIds),
|
||||
getEventTypeIdsWhereUserIsAdminOrOwner(prisma, membershipConditionWhereUserIsAdminOwner),
|
||||
getUserIdsAndEmailsWhereUserIsAdminOrOwner(prisma, membershipConditionWhereUserIsAdminOwner, user.orgId),
|
||||
getUserIdsAndEmailsWhereUserIsAdminOrOwner(prisma, membershipConditionWhereUserIsAdminOwner),
|
||||
]);
|
||||
|
||||
const bookingQueries: { query: BookingsUnionQuery; tables: (keyof DB)[] }[] = [];
|
||||
@@ -829,34 +829,22 @@ async function getEventTypeIdsWhereUserIsAdminOrOwner(
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets [IDs, Emails] of members where the auth user is admin/owner.
|
||||
* Scope depends on `orgId`:
|
||||
* - If set (number): Fetches members of that specific organization (`isOrganization: true`).
|
||||
* - If unset (null/undefined): Fetches members of all teams (`isOrganization: false`)
|
||||
* where the auth user meets the `membershipCondition`.
|
||||
*
|
||||
* Gets [IDs, Emails] of members where the auth user is team/org admin/owner.
|
||||
* @param prisma The Prisma client.
|
||||
* @param membershipCondition Filter defining the auth user's required role (e.g., OWNER/ADMIN)
|
||||
* to identify the target orgs/teams.
|
||||
* @param orgId Optional ID to target a specific org; absence targets teams.
|
||||
* @param membershipCondition Filter containing the team/org ids where user is ADMIN/OWNER
|
||||
* @returns {Promise<[number[], string[]]>} [UserIDs, UserEmails] for members in the determined scope.
|
||||
*/
|
||||
async function getUserIdsAndEmailsWhereUserIsAdminOrOwner(
|
||||
prisma: PrismaClient,
|
||||
membershipCondition: PrismaClientType.MembershipListRelationFilter,
|
||||
orgId?: number | null
|
||||
membershipCondition: PrismaClientType.MembershipListRelationFilter
|
||||
): Promise<[number[], string[]]> {
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
teams: {
|
||||
some: {
|
||||
team: orgId
|
||||
? {
|
||||
isOrganization: true,
|
||||
members: membershipCondition,
|
||||
id: orgId,
|
||||
}
|
||||
: { isOrganization: false, members: membershipCondition, parentId: null },
|
||||
team: {
|
||||
members: membershipCondition,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -865,7 +853,10 @@ async function getUserIdsAndEmailsWhereUserIsAdminOrOwner(
|
||||
email: true,
|
||||
},
|
||||
});
|
||||
return [users.map((user) => user.id), users.map((user) => user.email)];
|
||||
const userIds = Array.from(new Set(users.map((user) => user.id)));
|
||||
const userEmails = Array.from(new Set(users.map((user) => user.email)));
|
||||
|
||||
return [userIds, userEmails];
|
||||
}
|
||||
|
||||
function addStatusesQueryFilters(query: BookingsUnionQuery, statuses: InputByStatus[]) {
|
||||
|
||||
Reference in new issue
Block a user