fix: Users details leak for team booking when the team is private (#17403)

* fix: host details leaking

* type error

* update

* update

* Update getPublicEvent.ts

* Update getPublicEvent.ts
This commit is contained in:
Anik Dhabal Babu authored and GitHub committed 2024-11-11 19:55:42 +05:30
1 parent 30f9d9b980
commit ae9063804d
5 files changed
+36 -8

No files matched your search

@@ -74,6 +74,7 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
seatsPerTimeSlot: true,
seatsShowAvailabilityCount: true,
bookingFields: true,
teamId: true,
team: {
select: {
parentId: true,
@@ -92,6 +93,7 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
logoUrl: true,
},
},
isPrivate: true,
},
},
successRedirectUrl: true,
@@ -206,7 +208,8 @@ export const getPublicEvent = async (
isTeamEvent: boolean | undefined,
org: string | null,
prisma: PrismaClient,
fromRedirectOfNonOrgLink: boolean
fromRedirectOfNonOrgLink: boolean,
currentUserId?: number
) => {
const usernameList = getUsernameList(username);
const orgQuery = org ? getSlugOrRequestedSlug(org) : null;
@@ -377,7 +380,7 @@ export const getPublicEvent = async (
hosts: hosts,
};
const users =
let users =
(await getUsersFromEvent(eventWithUserProfiles, prisma)) ||
(await getOwnerFromUsersArray(prisma, event.id));
@@ -423,6 +426,27 @@ export const getPublicEvent = async (
length: eventWithUserProfiles.length,
});
}
const isTeamAdminOrOwner = await prisma.membership.findFirst({
where: {
userId: currentUserId ?? -1,
teamId: event.teamId ?? -1,
accepted: true,
role: { in: ["ADMIN", "OWNER"] },
},
});
const isOrgAdminOrOwner = await prisma.membership.findFirst({
where: {
userId: currentUserId ?? -1,
teamId: event.team?.parentId ?? -1,
accepted: true,
role: { in: ["ADMIN", "OWNER"] },
},
});
if (event.team?.isPrivate && !isTeamAdminOrOwner && !isOrgAdminOrOwner) {
users = [];
}
return {
...eventWithUserProfiles,