fix: org-redirect-url-admin-update (#14493)
This commit is contained in:
@@ -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 update
|
||||
if (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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user