Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: org-redirect-url-admin-update #14493

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 34 additions & 1 deletion packages/features/ee/users/server/trpc-router.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { z } from "zod";

import { getOrgFullOrigin } from "@calcom/ee/organizations/lib/orgDomains";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { AVATAR_FALLBACK } from "@calcom/lib/constants";
import { RedirectType } from "@calcom/prisma/enums";
import { _UserModel as User } from "@calcom/prisma/zod";
import type { inferRouterOutputs } from "@calcom/trpc";
import { TRPCError } from "@calcom/trpc";
Expand Down Expand Up @@ -106,7 +108,7 @@ export const userAdminRouter = router({

// If the profile has been moved to an Org -> we can easily access the profile we need to update
if (requestedUser.movedToProfileId && input.username) {
await tx.profile.update({
const profile = await tx.profile.update({
where: {
id: requestedUser.movedToProfileId,
},
Expand All @@ -115,6 +117,37 @@ export const userAdminRouter = router({
},
});

// Update all of this users tempOrgRedirectUrls
if (requestedUser.username && profile.organizationId) {
const data = await prisma.team.findUnique({
where: {
id: profile.organizationId,
},
select: {
slug: true,
},
});

// We should never hit this
if (!data?.slug) {
throw new Error("Team has no attached slug.");
}

const orgUrlPrefix = getOrgFullOrigin(data.slug);

const toUrl = `${orgUrlPrefix}/${input.username}`;

await prisma.tempOrgRedirect.updateMany({
where: {
type: RedirectType.User,
from: requestedUser.username, // Old username
},
data: {
toUrl,
},
});
}

return userInternal;
}

Expand Down