Skip to content

Commit

Permalink
Merge branch 'main' into fix/location-tests-flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
keithwillcode committed Feb 6, 2024
2 parents ed64e75 + 66b5dfd commit 0bdc380
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 46 deletions.
1 change: 0 additions & 1 deletion apps/api/pages/api/event-types/[id]/_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export async function getHandler(req: NextApiRequest) {
include: {
customInputs: true,
team: { select: { slug: true } },
users: true,
hosts: { select: { userId: true, isFixed: true } },
owner: { select: { username: true, id: true } },
children: { select: { id: true, userId: true } },
Expand Down
1 change: 0 additions & 1 deletion apps/api/pages/api/event-types/_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ async function getHandler(req: NextApiRequest) {
include: {
customInputs: true,
team: { select: { slug: true } },
users: true,
hosts: { select: { userId: true, isFixed: true } },
owner: { select: { username: true, id: true } },
children: { select: { id: true, userId: true } },
Expand Down
1 change: 0 additions & 1 deletion apps/api/pages/api/teams/[teamId]/event-types/_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ async function getHandler(req: NextApiRequest) {
include: {
customInputs: true,
team: { select: { slug: true } },
users: true,
hosts: { select: { userId: true, isFixed: true } },
owner: { select: { username: true, id: true } },
children: { select: { id: true, userId: true } },
Expand Down
7 changes: 6 additions & 1 deletion packages/app-store/routing-forms/trpc/response.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export const responseHandler = async ({ ctx, input }: ResponseHandlerOptions) =>
id: formId,
},
include: {
user: true,
user: {
select: {
id: true,
email: true,
},
},
},
});
if (!form) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-store/routing-forms/trpc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { OrderedResponses } from "../types/types";
import type { Response, SerializableForm } from "../types/types";

export async function onFormSubmission(
form: Ensure<SerializableForm<App_RoutingForms_Form> & { user: User }, "fields">,
form: Ensure<SerializableForm<App_RoutingForms_Form> & { user: Pick<User, "id" | "email"> }, "fields">,
response: Response
) {
const fieldResponsesByName: Record<
Expand Down
2 changes: 0 additions & 2 deletions packages/app-store/vital/lib/reschedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ const Reschedule = async (bookingUid: string, cancellationReason: string) => {
const event = await prisma.eventType.findFirstOrThrow({
select: {
title: true,
users: true,
schedulingType: true,
},
where: {
id: bookingToReschedule.eventTypeId,
Expand Down
1 change: 0 additions & 1 deletion packages/app-store/wipemycalother/lib/reschedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const Reschedule = async (bookingUid: string, cancellationReason: string) => {
const event = await prisma.eventType.findFirstOrThrow({
select: {
title: true,
users: true,
schedulingType: true,
},
where: {
Expand Down
12 changes: 8 additions & 4 deletions packages/features/auth/lib/next-auth-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const loginWithTotp = async (user: { email: string }) =>

type UserTeams = {
teams: (Membership & {
team: Team;
team: Pick<Team, "metadata">;
})[];
};

Expand Down Expand Up @@ -106,7 +106,9 @@ const providers: Provider[] = [
throw new Error(ErrorCode.InternalServerError);
}

const user = await UserRepository.findByEmailAndIncludeProfiles({ email: credentials.email });
const user = await UserRepository.findByEmailAndIncludeProfilesAndPassword({
email: credentials.email,
});
// Don't leak information about it being username or password that is invalid
if (!user) {
throw new Error(ErrorCode.IncorrectEmailPassword);
Expand Down Expand Up @@ -273,7 +275,9 @@ if (isSAMLLoginEnabled) {
email?: string;
locale?: string;
}) => {
const user = await UserRepository.findByEmailAndIncludeProfiles({ email: profile.email || "" });
const user = await UserRepository.findByEmailAndIncludeProfilesAndPassword({
email: profile.email || "",
});
if (!user) {
throw new Error(ErrorCode.UserNotFound);
}
Expand Down Expand Up @@ -339,7 +343,7 @@ if (isSAMLLoginEnabled) {
}

const { id, firstName, lastName, email } = userInfo;
const user = await UserRepository.findByEmailAndIncludeProfiles({ email });
const user = await UserRepository.findByEmailAndIncludeProfilesAndPassword({ email });
if (!user) {
throw new Error(ErrorCode.UserNotFound);
}
Expand Down
25 changes: 20 additions & 5 deletions packages/lib/server/repository/eventType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Prisma, EventType as PrismaEventType } from "@prisma/client";
import type { EventType as PrismaEventType } from "@prisma/client";
import { Prisma } from "@prisma/client";

import logger from "@calcom/lib/logger";
import { prisma } from "@calcom/prisma";
Expand All @@ -22,6 +23,16 @@ type IEventType = Ensure<
"title" | "slug" | "length"
>;

const userSelect = Prisma.validator<Prisma.UserSelect>()({
name: true,
avatarUrl: true,
username: true,
id: true,
email: true,
locale: true,
defaultScheduleId: true,
});

export class EventTypeRepository {
static async create(data: IEventType) {
const {
Expand Down Expand Up @@ -92,19 +103,23 @@ export class EventTypeRepository {
// TODO: As required by getByViewHandler - Make it configurable
team: {
include: {
eventTypes: true,
eventTypes: {
include: {
users: { select: userSelect },
},
},
},
},
hashedLink: true,
users: true,
users: { select: userSelect },
children: {
include: {
users: true,
users: { select: userSelect },
},
},
hosts: {
include: {
user: true,
user: { select: userSelect },
},
},
};
Expand Down
54 changes: 45 additions & 9 deletions packages/lib/server/repository/membership.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { prisma } from "@calcom/prisma";
import type { Prisma, MembershipRole } from "@calcom/prisma/client";
import type { MembershipRole } from "@calcom/prisma/client";
import { Prisma } from "@calcom/prisma/client";

import logger from "../../logger";
import { safeStringify } from "../../safeStringify";
Expand All @@ -14,6 +15,33 @@ type IMembership = {
role: MembershipRole;
};

const membershipSelect = Prisma.validator<Prisma.MembershipSelect>()({
id: true,
teamId: true,
userId: true,
accepted: true,
role: true,
disableImpersonation: true,
});

const teamParentSelect = Prisma.validator<Prisma.TeamSelect>()({
id: true,
name: true,
slug: true,
logoUrl: true,
parentId: true,
});

const userSelect = Prisma.validator<Prisma.UserSelect>()({
name: true,
avatarUrl: true,
username: true,
id: true,
email: true,
locale: true,
defaultScheduleId: true,
});

export class MembershipRepository {
static async create(data: IMembership) {
return await prisma.membership.create({
Expand Down Expand Up @@ -68,25 +96,33 @@ export class MembershipRepository {
include: {
team: {
include: {
members: true,
parent: true,
members: {
select: membershipSelect,
},
parent: {
select: teamParentSelect,
},
eventTypes: {
include: {
team: {
include: {
eventTypes: true,
eventTypes: {
include: {
users: { select: userSelect },
},
},
},
},
hashedLink: true,
users: true,
hosts: {
users: { select: userSelect },
children: {
include: {
user: true,
users: { select: userSelect },
},
},
children: {
hosts: {
include: {
users: true,
user: { select: userSelect },
},
},
},
Expand Down
58 changes: 49 additions & 9 deletions packages/lib/server/repository/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,36 @@ import { v4 as uuidv4 } from "uuid";
import { whereClauseForOrgWithSlugOrRequestedSlug } from "@calcom/ee/organizations/lib/orgDomains";
import { safeStringify } from "@calcom/lib/safeStringify";
import prisma from "@calcom/prisma";
import { Prisma } from "@calcom/prisma/client";
import type { Team } from "@calcom/prisma/client";
import type { UpId, UserAsPersonalProfile, UserProfile } from "@calcom/types/UserProfile";

import logger from "../../logger";
import { getParsedTeam } from "./teamUtils";
import { UserRepository } from "./user";

const userSelect = Prisma.validator<Prisma.UserSelect>()({
name: true,
avatarUrl: true,
username: true,
id: true,
email: true,
locale: true,
defaultScheduleId: true,
startTime: true,
endTime: true,
bufferTime: true,
});

const membershipSelect = Prisma.validator<Prisma.MembershipSelect>()({
id: true,
teamId: true,
userId: true,
accepted: true,
role: true,
disableImpersonation: true,
});

const log = logger.getSubLogger({ prefix: ["repository/profile"] });
const organizationSelect = {
id: true,
Expand All @@ -30,14 +53,17 @@ export class ProfileRepository {
return uuidv4();
}

private static getInheritedDataFromUser({ user }: { user: PrismaUser }) {
private static getInheritedDataFromUser({
user,
}: {
user: Pick<PrismaUser, "name" | "avatarUrl" | "startTime" | "endTime" | "bufferTime">;
}) {
return {
name: user.name,
avatarUrl: user.avatarUrl,
startTime: user.startTime,
endTime: user.endTime,
bufferTime: user.bufferTime,
avatar: user.avatar,
};
}

Expand Down Expand Up @@ -233,7 +259,9 @@ export class ProfileRepository {
organization: {
select: organizationSelect,
},
user: true,
user: {
select: userSelect,
},
},
});

Expand Down Expand Up @@ -268,7 +296,9 @@ export class ProfileRepository {
organization: {
select: organizationSelect,
},
user: true,
user: {
select: userSelect,
},
},
});
return profile;
Expand Down Expand Up @@ -313,11 +343,15 @@ export class ProfileRepository {
id,
},
include: {
user: true,
user: {
select: userSelect,
},
movedFromUser: true,
organization: {
include: {
members: true,
members: {
select: membershipSelect,
},
},
},
},
Expand Down Expand Up @@ -346,7 +380,9 @@ export class ProfileRepository {
organization: whereClauseForOrgWithSlugOrRequestedSlug(orgSlug),
},
include: {
user: true,
user: {
select: userSelect,
},
organization: {
select: organizationSelect,
},
Expand Down Expand Up @@ -416,7 +452,9 @@ export class ProfileRepository {
organizationId,
},
include: {
user: true,
user: {
select: userSelect,
},
organization: {
select: organizationSelect,
},
Expand All @@ -434,7 +472,9 @@ export class ProfileRepository {
organization: {
select: organizationSelect,
},
user: true,
user: {
select: userSelect,
},
},
});
if (!profile) {
Expand Down
13 changes: 12 additions & 1 deletion packages/lib/server/repository/team.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Prisma } from "@prisma/client";
import { Prisma } from "@prisma/client";
import type { z } from "zod";

import { whereClauseForOrgWithSlugOrRequestedSlug } from "@calcom/ee/organizations/lib/orgDomains";
Expand Down Expand Up @@ -148,12 +148,23 @@ export async function getOrg<TeamSelect extends Prisma.TeamSelect>({
teamSelect,
});
}

const teamSelect = Prisma.validator<Prisma.TeamSelect>()({
id: true,
name: true,
slug: true,
logoUrl: true,
parentId: true,
metadata: true,
});

export class TeamRepository {
static async findById({ id }: { id: number }) {
const team = await prisma.team.findUnique({
where: {
id,
},
select: teamSelect,
});
if (!team) {
return null;
Expand Down
Loading

0 comments on commit 0bdc380

Please sign in to comment.