chore: Remove deprecated logo/avatar/away fields (#14705)
* chore: Remove deprecated logo/avatar/away fields * Use right variables for accounts-step-card * Remove more deprecated logo/avatar usage * Dont drop the fields until all usages are gone * Remove the avatar/logo drops for staggered release * fix: Typescript blindspot (unvalidated include fields) * fix: Further updates (mostly to API) typescript missed --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Bailey Pumfleet <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
15 files changed
+105
-85
No files matched your search
@@ -7,7 +7,12 @@ import { schemaUserReadPublic } from "~/lib/validations/user";
|
||||
|
||||
async function handler({ userId }: NextApiRequest) {
|
||||
const data = await prisma.user.findUniqueOrThrow({ where: { id: userId } });
|
||||
return { user: schemaUserReadPublic.parse(data) };
|
||||
return {
|
||||
user: schemaUserReadPublic.parse({
|
||||
...data,
|
||||
avatar: data.avatarUrl,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export default defaultResponder(handler);
|
||||
@@ -45,7 +45,10 @@ export async function getHandler(req: NextApiRequest) {
|
||||
if (!isSystemWideAdmin && query.userId !== req.userId)
|
||||
throw new HttpError({ statusCode: 403, message: "Forbidden" });
|
||||
const data = await prisma.user.findUnique({ where: { id: query.userId } });
|
||||
const user = schemaUserReadPublic.parse(data);
|
||||
const user = schemaUserReadPublic.parse({
|
||||
...data,
|
||||
avatar: data?.avatarUrl,
|
||||
});
|
||||
return { user };
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ import type { NextApiRequest } from "next";
|
||||
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import { defaultResponder } from "@calcom/lib/server";
|
||||
import { uploadAvatar } from "@calcom/lib/server/avatar";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
import { schemaQueryUserId } from "~/lib/validations/shared/queryUserId";
|
||||
import { schemaUserEditBodyParams, schemaUserReadPublic } from "~/lib/validations/user";
|
||||
@@ -101,7 +103,8 @@ export async function patchHandler(req: NextApiRequest) {
|
||||
if (!isSystemWideAdmin && query.userId !== req.userId)
|
||||
throw new HttpError({ statusCode: 403, message: "Forbidden" });
|
||||
|
||||
const body = await schemaUserEditBodyParams.parseAsync(req.body);
|
||||
const { avatar, ...body }: { avatar?: string | undefined } & Prisma.UserUpdateInput =
|
||||
await schemaUserEditBodyParams.parseAsync(req.body);
|
||||
// disable role or branding changes unless admin.
|
||||
if (!isSystemWideAdmin) {
|
||||
if (body.role) body.role = undefined;
|
||||
@@ -119,6 +122,14 @@ export async function patchHandler(req: NextApiRequest) {
|
||||
message: "Bad request: Invalid default schedule id",
|
||||
});
|
||||
}
|
||||
|
||||
if (avatar) {
|
||||
body.avatarUrl = await uploadAvatar({
|
||||
userId: query.userId,
|
||||
avatar: await (await import("@calcom/lib/server/resizeBase64Image")).resizeBase64Image(avatar),
|
||||
});
|
||||
}
|
||||
|
||||
const data = await prisma.user.update({
|
||||
where: { id: query.userId },
|
||||
data: body,
|
||||
|
||||
@@ -53,7 +53,7 @@ const AccountSelector: FC<AccountSelectorProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
export type PersonalAccountProps = Pick<User, "id" | "avatar" | "name"> & { alreadyInstalled: boolean };
|
||||
export type PersonalAccountProps = Pick<User, "id" | "avatarUrl" | "name"> & { alreadyInstalled: boolean };
|
||||
|
||||
export type TeamsProp = (Pick<Team, "id" | "name" | "logoUrl"> & {
|
||||
alreadyInstalled: boolean;
|
||||
@@ -74,7 +74,7 @@ export const AccountsStepCard: FC<AccountStepCardProps> = ({ teams, personalAcco
|
||||
<div className={classNames("mt-2 flex flex-col gap-2 ")}>
|
||||
<AccountSelector
|
||||
testId="install-app-button-personal"
|
||||
avatar={personalAccount.avatar ?? ""}
|
||||
avatar={personalAccount.avatarUrl ?? ""}
|
||||
name={personalAccount.name ?? ""}
|
||||
alreadyInstalled={personalAccount.alreadyInstalled}
|
||||
onClick={() => onSelect()}
|
||||
|
||||
@@ -474,7 +474,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
const personalAccount = {
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
avatar: user.avatarUrl,
|
||||
avatarUrl: user.avatarUrl,
|
||||
alreadyInstalled: appInstalls.some((install) => !Boolean(install.teamId) && install.userId === user.id),
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user