Fix/user creds (#8393)

* fix-user-creds

* Type fixes

* Type fixes

* Type fixes

---------

Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
alannncandAlex van Andel authored and GitHub committed 2023-04-20 15:55:19 +00:00
1 parent c1c95f711b
commit fe996b4e41
13 files changed
+92 -39

No files matched your search

@@ -38,7 +38,7 @@ async function getBookingToDelete(id: number | undefined, uid: string | undefine
user: {
select: {
id: true,
credentials: true,
credentials: true, // Not leaking at the moment, be careful with
email: true,
timeZone: true,
name: true,
@@ -197,7 +197,12 @@ const getEventTypesFromDB = async (eventTypeId: number) => {
id: true,
customInputs: true,
disableGuests: true,
users: userSelect,
users: {
select: {
credentials: true,
...userSelect.select,
},
},
slug: true,
team: {
select: {
@@ -253,7 +258,12 @@ const getEventTypesFromDB = async (eventTypeId: number) => {
hosts: {
select: {
isFixed: true,
user: userSelect,
user: {
select: {
credentials: true,
...userSelect.select,
},
},
},
},
availability: {
@@ -277,7 +287,7 @@ const getEventTypesFromDB = async (eventTypeId: number) => {
};
};
type IsFixedAwareUser = User & { isFixed: boolean };
type IsFixedAwareUser = User & { isFixed: boolean; credentials: Credential[] };
async function ensureAvailableUsers(
eventType: Awaited<ReturnType<typeof getEventTypesFromDB>> & {
@@ -623,6 +633,7 @@ async function handler(
},
select: {
...userSelect.select,
credentials: true, // Don't leak to client
metadata: true,
},
})
@@ -654,7 +665,10 @@ async function handler(
where: {
id: eventType.userId,
},
...userSelect,
select: {
credentials: true, // Don't leak to client
...userSelect.select,
},
});
if (!eventTypeUser) {
log.warn({ message: "NewBooking: eventTypeUser.notFound" });
+33 -7
View File
@@ -55,7 +55,6 @@ async function getBooking(bookingId: number) {
select: {
id: true,
username: true,
credentials: true,
timeZone: true,
email: true,
name: true,
@@ -176,9 +175,11 @@ async function handlePaymentSuccess(event: Stripe.Event) {
eventTypeRaw = await getEventType(booking.eventTypeId);
}
const { user } = booking;
const { user: userWithCredentials } = booking;
if (!user) throw new HttpCode({ statusCode: 204, message: "No user found" });
if (!userWithCredentials) throw new HttpCode({ statusCode: 204, message: "No user found" });
const { credentials, ...user } = userWithCredentials;
const t = await getTranslation(user.locale ?? "en", "common");
const attendeesListPromises = booking.attendees.map(async (attendee) => {
@@ -227,7 +228,7 @@ async function handlePaymentSuccess(event: Stripe.Event) {
const isConfirmed = booking.status === BookingStatus.ACCEPTED;
if (isConfirmed) {
const eventManager = new EventManager(user);
const eventManager = new EventManager(userWithCredentials);
const scheduleResult = await eventManager.create(evt);
bookingData.references = { create: scheduleResult.referencesToCreate };
}
@@ -255,7 +256,14 @@ async function handlePaymentSuccess(event: Stripe.Event) {
await prisma.$transaction([paymentUpdate, bookingUpdate]);
if (!isConfirmed && !eventTypeRaw?.requiresConfirmation) {
await handleConfirmation({ user, evt, prisma, bookingId: booking.id, booking, paid: true });
await handleConfirmation({
user: userWithCredentials,
evt,
prisma,
bookingId: booking.id,
booking,
paid: true,
});
} else {
await sendScheduledEmails({ ...evt });
}
@@ -276,14 +284,32 @@ const handleSetupSuccess = async (event: Stripe.Event) => {
if (!payment?.data || !payment?.id) throw new HttpCode({ statusCode: 204, message: "Payment not found" });
const { booking, user, evt, eventTypeRaw } = await getBooking(payment.bookingId);
const { user, evt, eventTypeRaw } = await getBooking(payment.bookingId);
const bookingData: Prisma.BookingUpdateInput = {
paid: true,
};
const userWithCredentials = await prisma.user.findUnique({
where: {
id: user.id,
},
select: {
id: true,
username: true,
timeZone: true,
email: true,
name: true,
locale: true,
destinationCalendar: true,
credentials: true,
},
});
if (!userWithCredentials) throw new HttpCode({ statusCode: 204, message: "No user found" });
if (!eventTypeRaw?.requiresConfirmation) {
const eventManager = new EventManager(user);
const eventManager = new EventManager(userWithCredentials);
const scheduleResult = await eventManager.create(evt);
bookingData.references = { create: scheduleResult.referencesToCreate };
bookingData.status = BookingStatus.ACCEPTED;