fix: Org Seeder - to better represent production scenario and fix admin org delete cleanup (#15157)
* Fix seeder and update message to inform well about org deletion implication * Cleanup tempOrgRedirect as well --------- Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
1 parent
8831ff13c7
commit
1a381695e5
3 files changed
+42
-2
No files matched your search
@@ -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": "<ul><li>Teams that are member of this organization will also be deleted along with their event-types</li><li>Users that were part of the organization will not be deleted and their event-types will also remain intact.</li><li>Usernames would be changed to allow them to exist outside the organization</li></ul>",
|
||||
"admin_delete_organization_description": "<ul><li>Teams that are member of this organization will also be deleted along with their event-types</li><li>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</li><li>User event-types created after the user was in the organization will be deleted</li><li>Migrated user event-types will not be deleted</li></ul>",
|
||||
"admin_delete_organization_title": "Delete {{organizationName}}?",
|
||||
"published": "Published",
|
||||
"unpublished": "Unpublished",
|
||||
|
||||
+16
-1
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user