🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore: improve org deletion warning (#10474)
Marc Klingend808579f1a91
diff --git a/web/src/ee/features/admin-api/server/organizations/organizationById.ts b/web/src/ee/features/admin-api/server/organizations/organizationById.tsindex 238bf6bbb3..a28e44c542 100644--- a/web/src/ee/features/admin-api/server/organizations/organizationById.ts+++ b/web/src/ee/features/admin-api/server/organizations/organizationById.ts@@ -163,12 +163,22 @@ export async function handleDeleteOrganization(return res.status(404).json({ error: "Organization not found" });}- // Check if organization has any projects- const projectCount = await prisma.project.count({- where: { orgId: organizationId },+ // count non-deleted projects+ const countNonDeletedProjects = await prisma.project.count({+ where: {+ orgId: organizationId,+ deletedAt: null,+ },});- if (projectCount > 0) {+ // count all projects (including soft-deleted)+ const countAllProjects = await prisma.project.count({+ where: {+ orgId: organizationId,+ },+ });++ if (countNonDeletedProjects > 0) {return res.status(400).json({error: "Cannot delete organization with existing projects",message:@@ -176,6 +186,14 @@ export async function handleDeleteOrganization(});}+ if (countAllProjects > 0) {+ return res.status(400).json({+ error: "Cannot delete organization with existing projects",+ message:+ "Deletion of your projects is still being processed, please try deleting the organization later",+ });+ }+// Delete the organizationconst deletedOrganization = await prisma.organization.delete({where: { id: organizationId },diff --git a/web/src/features/organizations/server/organizationRouter.ts b/web/src/features/organizations/server/organizationRouter.tsindex 76df83f37d..ef6a164315 100644--- a/web/src/features/organizations/server/organizationRouter.ts+++ b/web/src/features/organizations/server/organizationRouter.ts@@ -123,14 +123,22 @@ export const organizationsRouter = createTRPCRouter({scope: "organization:delete",});- // count soft and hard deleted projects- const countProjects = await ctx.prisma.project.count({+ // count non-deleted projects+ const countNonDeletedProjects = await ctx.prisma.project.count({where: {orgId: input.orgId,+ deletedAt: null,},});- if (countProjects > 0) {+ // count all projects (including soft-deleted)+ const countAllProjects = await ctx.prisma.project.count({+ where: {+ orgId: input.orgId,+ },+ });++ if (countNonDeletedProjects > 0) {throw new TRPCError({code: "FORBIDDEN",message:@@ -138,6 +146,14 @@ export const organizationsRouter = createTRPCRouter({});}+ if (countAllProjects > 0) {+ throw new TRPCError({+ code: "FORBIDDEN",+ message:+ "Deletion of your projects is still being processed, please try deleting the organization later",+ });+ }+// Attempt to cancel Stripe subscription immediately (Cloud only) before deleting orgif (isCloudBillingEnabled()) {try {