fix: org username check for dynamic and signup (#11390)

pull/11395/head
Leo Giovanetti 2023-09-15 13:06:56 -03:00 committed by GitHub
parent 7beb9568ba
commit 7154349e9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -196,7 +196,6 @@ export default class SalesforceCalendarService implements Calendar {
}
async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> {
debugger;
const contacts = await this.salesforceContactSearch(event);
if (contacts.length) {
if (contacts.length == event.attendees.length) {

View File

@ -9,7 +9,9 @@ export const validateUsername = async (username: string, email: string, organiza
where: {
...(organizationId ? { organizationId } : {}),
OR: [
{ username },
// When inviting to org, invited user gets created with username now, so in an org context we
// can't check for username as it will exist on signup
...(!organizationId ? [{ username }] : [{}]),
{
AND: [
{ email },

View File

@ -202,7 +202,11 @@ export async function getEventType(
};
}
export async function getDynamicEventType(input: TGetScheduleInputSchema) {
export async function getDynamicEventType(
input: TGetScheduleInputSchema,
organizationDetails: { currentOrgDomain: string | null; isValidOrgDomain: boolean }
) {
const { currentOrgDomain, isValidOrgDomain } = organizationDetails;
// For dynamic booking, we need to get and update user credentials, schedule and availability in the eventTypeObject as they're required in the new availability logic
if (!input.eventTypeSlug) {
throw new TRPCError({
@ -220,6 +224,7 @@ export async function getDynamicEventType(input: TGetScheduleInputSchema) {
? [input.usernameList]
: [],
},
organization: isValidOrgDomain && currentOrgDomain ? getSlugOrRequestedSlug(currentOrgDomain) : null,
},
select: {
allowDynamicBooking: true,
@ -246,7 +251,9 @@ export function getRegularOrDynamicEventType(
organizationDetails: { currentOrgDomain: string | null; isValidOrgDomain: boolean }
) {
const isDynamicBooking = input.usernameList && input.usernameList.length > 1;
return isDynamicBooking ? getDynamicEventType(input) : getEventType(input, organizationDetails);
return isDynamicBooking
? getDynamicEventType(input, organizationDetails)
: getEventType(input, organizationDetails);
}
export async function getAvailableSlots({ input, ctx }: GetScheduleOptions) {