🪢 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
fix(organizations): block org deletion in case of active projects (#4707)
marliessophie8b8d1086e5c4
diff --git a/web/src/features/organizations/components/DeleteOrganizationButton.tsx b/web/src/features/organizations/components/DeleteOrganizationButton.tsxindex 308fa49325..13360d97d2 100644--- a/web/src/features/organizations/components/DeleteOrganizationButton.tsx+++ b/web/src/features/organizations/components/DeleteOrganizationButton.tsx@@ -43,6 +43,7 @@ export function DeleteOrganizationButton() {});const deleteOrganization = api.organizations.delete.useMutation();+ const hasProjects = !!organization && organization.projects.length > 0;const form = useForm<z.infer<typeof formSchema>>({resolver: zodResolver(formSchema),@@ -52,7 +53,7 @@ export function DeleteOrganizationButton() {});const onSubmit = async () => {- if (!organization) return;+ if (!organization || hasProjects) return;try {await deleteOrganization.mutateAsync({orgId: organization.id,@@ -82,7 +83,9 @@ export function DeleteOrganizationButton() {Delete Organization</DialogTitle><DialogDescription>- {`To confirm, type "${confirmMessage}" in the input box `}+ {hasProjects+ ? "You can only delete an organization if it has no projects associated with it. Please delete or transfer all projects first. Deleting projects may take a few minutes."+ : `To confirm, type "${confirmMessage}" in the input box `}</DialogDescription></DialogHeader><Form {...form}>@@ -91,22 +94,25 @@ export function DeleteOrganizationButton() {onSubmit={form.handleSubmit(onSubmit)}className="space-y-8">- <FormField- control={form.control}- name="name"- render={({ field }) => (- <FormItem>- <FormControl>- <Input placeholder={confirmMessage} {...field} />- </FormControl>- <FormMessage />- </FormItem>- )}- />+ {!hasProjects && (+ <FormField+ control={form.control}+ name="name"+ render={({ field }) => (+ <FormItem>+ <FormControl>+ <Input placeholder={confirmMessage} {...field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ )}<Buttontype="submit"variant="destructive"loading={deleteOrganization.isLoading}+ disabled={hasProjects}className="w-full">Delete Organizationdiff --git a/web/src/features/organizations/server/organizationRouter.ts b/web/src/features/organizations/server/organizationRouter.tsindex 1e98c612e8..9acc0a934c 100644--- a/web/src/features/organizations/server/organizationRouter.ts+++ b/web/src/features/organizations/server/organizationRouter.ts@@ -98,10 +98,10 @@ export const organizationsRouter = createTRPCRouter({scope: "organization:delete",});+ // count soft and hard deleted projectsconst countProjects = await ctx.prisma.project.count({where: {orgId: input.orgId,- deletedAt: null,},});if (countProjects > 0) {