Scheduling infrastructure for absolutely everyone.
fix: org-redirect-url-admin-update (#14493)
sean-brydondbafda98229d
diff --git a/packages/features/ee/users/server/trpc-router.ts b/packages/features/ee/users/server/trpc-router.tsindex a3f8c82451d..e9f1b02e596 100644--- a/packages/features/ee/users/server/trpc-router.ts+++ b/packages/features/ee/users/server/trpc-router.ts@@ -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";@@ -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 updateif (requestedUser.movedToProfileId && input.username) {- await tx.profile.update({+ const profile = await tx.profile.update({where: {id: requestedUser.movedToProfileId,},@@ -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;}