diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json
index 2b2e2503a84d02..2ec5493f9a9e52 100644
--- a/apps/web/public/static/locales/en/common.json
+++ b/apps/web/public/static/locales/en/common.json
@@ -2263,7 +2263,7 @@
"create_your_org_description": "Upgrade to Organizations and receive a subdomain, unified billing, Insights, extensive whitelabeling and more",
"create_your_enterprise_description": "Upgrade to Enterprise and get access to Active Directory Sync, SCIM Automatic User provisioning, Cal.ai Voice Agents, Admin APIs and more!",
"other_payment_app_enabled": "You can only enable one payment app per event type",
- "admin_delete_organization_description": "
- Teams that are member of this organization will also be deleted along with their event-types
- Users that were part of the organization will not be deleted and their event-types will also remain intact.
- Usernames would be changed to allow them to exist outside the organization
",
+ "admin_delete_organization_description": "- Teams that are member of this organization will also be deleted along with their event-types
- Users that were part of the organization will not be deleted but their usernames would be changed to allow them to exist outside the organization
- User event-types created after the user was in the organization will be deleted
- Migrated user event-types will not be deleted
",
"admin_delete_organization_title": "Delete {{organizationName}}?",
"published": "Published",
"unpublished": "Unpublished",
diff --git a/packages/prisma/seed.ts b/packages/prisma/seed.ts
index 874673df9d45ea..b1c2d90f425e85 100644
--- a/packages/prisma/seed.ts
+++ b/packages/prisma/seed.ts
@@ -7,8 +7,9 @@ import dailyMeta from "@calcom/app-store/dailyvideo/_metadata";
import googleMeetMeta from "@calcom/app-store/googlevideo/_metadata";
import zoomMeta from "@calcom/app-store/zoomvideo/_metadata";
import dayjs from "@calcom/dayjs";
+import { getOrgFullOrigin } from "@calcom/ee/organizations/lib/orgDomains";
import { hashPassword } from "@calcom/features/auth/lib/hashPassword";
-import { BookingStatus, MembershipRole, SchedulingType } from "@calcom/prisma/enums";
+import { BookingStatus, MembershipRole, RedirectType, SchedulingType } from "@calcom/prisma/enums";
import type { Ensure } from "@calcom/types/utils";
import prisma from ".";
@@ -147,6 +148,15 @@ async function createOrganizationAndAddMembersAndTeams({
orgProfile: member.orgProfile,
};
+ await prisma.tempOrgRedirect.create({
+ data: {
+ fromOrgId: 0,
+ type: RedirectType.User,
+ from: member.memberData.username,
+ toUrl: `${getOrgFullOrigin(orgData.slug)}/${member.orgProfile.username}`,
+ },
+ });
+
orgMembersInDb.push(orgMemberInDb);
}
} catch (e) {
@@ -191,6 +201,11 @@ async function createOrganizationAndAddMembersAndTeams({
create: orgMembersInDb.map((member) => ({
uid: uuid(),
username: member.orgProfile.username,
+ movedFromUser: {
+ connect: {
+ id: member.id,
+ },
+ },
user: {
connect: {
id: member.id,
diff --git a/packages/trpc/server/routers/viewer/organizations/adminDelete.handler.ts b/packages/trpc/server/routers/viewer/organizations/adminDelete.handler.ts
index 8a8e52c8eaedc6..cf73e1bc208cd8 100644
--- a/packages/trpc/server/routers/viewer/organizations/adminDelete.handler.ts
+++ b/packages/trpc/server/routers/viewer/organizations/adminDelete.handler.ts
@@ -1,6 +1,7 @@
import { deleteDomain } from "@calcom/lib/domainManager/organization";
import logger from "@calcom/lib/logger";
import { prisma } from "@calcom/prisma";
+import { RedirectType } from "@calcom/prisma/enums";
import { TRPCError } from "@trpc/server";
@@ -44,6 +45,8 @@ export const adminDeleteHandler = async ({ input }: AdminDeleteOption) => {
}
}
+ await deleteAllRedirectsForUsers(foundOrg.members.map((member) => member.user));
+
await renameUsersToAvoidUsernameConflicts(foundOrg.members.map((member) => member.user));
await prisma.team.delete({
where: {
@@ -79,3 +82,25 @@ async function renameUsersToAvoidUsernameConflicts(users: { id: number; username
});
}
}
+
+async function deleteAllRedirectsForUsers(users: { username: string | null }[]) {
+ return await Promise.all(
+ users
+ .filter(
+ (
+ user
+ ): user is {
+ username: string;
+ } => !!user.username
+ )
+ .map((user) =>
+ prisma.tempOrgRedirect.deleteMany({
+ where: {
+ from: user.username,
+ type: RedirectType.User,
+ fromOrgId: 0,
+ },
+ })
+ )
+ );
+}