From cb992259cfe6cccc23bb1a9fbe49af10d3ac6191 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 2 Sep 2025 04:42:24 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- .../project/advanced-environment-selector.tsx | 122 ++++--- .../project/ai/template-generator.tsx | 1 - .../dashboard/project/duplicate-project.tsx | 38 +- .../components/dashboard/projects/show.tsx | 66 ++-- .../settings/users/add-permissions.tsx | 2 +- .../pages/dashboard/project/[projectId].tsx | 17 +- .../environment/[environmentId].tsx | 65 ++-- .../services/mariadb/[mariadbId].tsx | 9 +- .../services/mongo/[mongoId].tsx | 6 +- .../services/mysql/[mysqlId].tsx | 9 +- .../services/postgres/[postgresId].tsx | 329 ++++++++---------- .../services/redis/[redisId].tsx | 9 +- apps/dokploy/server/api/routers/ai.ts | 8 +- .../dokploy/server/api/routers/application.ts | 84 +++-- apps/dokploy/server/api/routers/compose.ts | 98 ++++-- apps/dokploy/server/api/routers/deployment.ts | 8 +- apps/dokploy/server/api/routers/domain.ts | 32 +- apps/dokploy/server/api/routers/mariadb.ts | 71 +++- apps/dokploy/server/api/routers/mongo.ts | 74 +++- apps/dokploy/server/api/routers/mysql.ts | 74 +++- apps/dokploy/server/api/routers/postgres.ts | 50 ++- .../server/api/routers/preview-deployment.ts | 3 +- apps/dokploy/server/api/routers/project.ts | 14 +- apps/dokploy/server/api/routers/redis.ts | 71 +++- apps/dokploy/server/api/routers/security.ts | 12 +- packages/server/src/db/schema/application.ts | 1 - packages/server/src/db/schema/compose.ts | 1 - packages/server/src/db/schema/mariadb.ts | 1 - packages/server/src/db/schema/mongo.ts | 1 - packages/server/src/db/schema/mysql.ts | 1 - packages/server/src/db/schema/postgres.ts | 1 - packages/server/src/db/schema/redis.ts | 1 - packages/server/src/services/application.ts | 1 - packages/server/src/services/environment.ts | 1 - .../server/src/services/preview-deployment.ts | 2 - packages/server/src/services/project.ts | 14 +- 36 files changed, 812 insertions(+), 485 deletions(-) diff --git a/apps/dokploy/components/dashboard/project/advanced-environment-selector.tsx b/apps/dokploy/components/dashboard/project/advanced-environment-selector.tsx index e12f27229..a12fa2e00 100644 --- a/apps/dokploy/components/dashboard/project/advanced-environment-selector.tsx +++ b/apps/dokploy/components/dashboard/project/advanced-environment-selector.tsx @@ -22,12 +22,17 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { toast } from "sonner"; -import { ChevronDownIcon, PlusIcon, PencilIcon, TrashIcon, CopyIcon } from "lucide-react"; +import { + ChevronDownIcon, + PlusIcon, + PencilIcon, + TrashIcon, + CopyIcon, +} from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { AlertBlock } from "@/components/shared/alert-block"; import { findEnvironmentById } from "@dokploy/server"; - type Environment = Awaited>; interface AdvancedEnvironmentSelectorProps { projectId: string; @@ -42,11 +47,15 @@ export const AdvancedEnvironmentSelector = ({ const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); const [isEditDialogOpen, setIsEditDialogOpen] = useState(false); const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false); - const [selectedEnvironment, setSelectedEnvironment] = useState(null); + const [selectedEnvironment, setSelectedEnvironment] = + useState(null); - const { data: project } = api.project.one.useQuery({ projectId },{ - enabled: !!projectId, - }); + const { data: project } = api.project.one.useQuery( + { projectId }, + { + enabled: !!projectId, + }, + ); const environments = project?.environments || []; // Form states @@ -54,20 +63,22 @@ export const AdvancedEnvironmentSelector = ({ const [description, setDescription] = useState(""); // API mutations - const { data: environment } = api.environment.one.useQuery({ environmentId: currentEnvironmentId || "" },{ - enabled: !!currentEnvironmentId, - }); - - - const haveServices = selectedEnvironment && ( - (selectedEnvironment?.mariadb?.length || 0) > 0 || - (selectedEnvironment?.mongo?.length || 0) > 0 || - (selectedEnvironment?.mysql?.length || 0) > 0 || - (selectedEnvironment?.postgres?.length || 0) > 0 || - (selectedEnvironment?.redis?.length || 0) > 0 || - (selectedEnvironment?.applications?.length || 0) > 0 || - (selectedEnvironment?.compose?.length || 0) > 0 + const { data: environment } = api.environment.one.useQuery( + { environmentId: currentEnvironmentId || "" }, + { + enabled: !!currentEnvironmentId, + }, ); + + const haveServices = + selectedEnvironment && + ((selectedEnvironment?.mariadb?.length || 0) > 0 || + (selectedEnvironment?.mongo?.length || 0) > 0 || + (selectedEnvironment?.mysql?.length || 0) > 0 || + (selectedEnvironment?.postgres?.length || 0) > 0 || + (selectedEnvironment?.redis?.length || 0) > 0 || + (selectedEnvironment?.applications?.length || 0) > 0 || + (selectedEnvironment?.compose?.length || 0) > 0); const createEnvironment = api.environment.create.useMutation(); const updateEnvironment = api.environment.update.useMutation(); const deleteEnvironment = api.environment.remove.useMutation(); @@ -83,7 +94,7 @@ export const AdvancedEnvironmentSelector = ({ name: name.trim(), description: description.trim() || null, }); - + toast.success("Environment created successfully"); utils.project.one.invalidate({ projectId }); setIsCreateDialogOpen(false); @@ -103,7 +114,7 @@ export const AdvancedEnvironmentSelector = ({ name: name.trim(), description: description.trim() || null, }); - + toast.success("Environment updated successfully"); utils.project.one.invalidate({ projectId }); setIsEditDialogOpen(false); @@ -122,7 +133,7 @@ export const AdvancedEnvironmentSelector = ({ await deleteEnvironment.mutateAsync({ environmentId: selectedEnvironment.environmentId, }); - + toast.success("Environment deleted successfully"); utils.project.one.invalidate({ projectId }); setIsDeleteDialogOpen(false); @@ -130,9 +141,13 @@ export const AdvancedEnvironmentSelector = ({ // Redirect to production if we deleted the current environment if (selectedEnvironment.environmentId === currentEnvironmentId) { - const productionEnv = environments.find(env => env.name === "production"); + const productionEnv = environments.find( + (env) => env.name === "production", + ); if (productionEnv) { - router.push(`/dashboard/project/${projectId}/environment/${productionEnv.environmentId}`); + router.push( + `/dashboard/project/${projectId}/environment/${productionEnv.environmentId}`, + ); } } } catch (error) { @@ -147,12 +162,14 @@ export const AdvancedEnvironmentSelector = ({ name: `${environment.name}-copy`, description: environment.description, }); - + toast.success("Environment duplicated successfully"); utils.project.one.invalidate({ projectId }); - + // Navigate to the new duplicated environment - router.push(`/dashboard/project/${projectId}/environment/${result.environmentId}`); + router.push( + `/dashboard/project/${projectId}/environment/${result.environmentId}`, + ); } catch (error) { toast.error("Failed to duplicate environment"); } @@ -170,7 +187,9 @@ export const AdvancedEnvironmentSelector = ({ setIsDeleteDialogOpen(true); }; - const currentEnv = environments.find(env => env.environmentId === currentEnvironmentId); + const currentEnv = environments.find( + (env) => env.environmentId === currentEnvironmentId, + ); return ( <> @@ -179,11 +198,7 @@ export const AdvancedEnvironmentSelector = ({ @@ -191,30 +206,28 @@ export const AdvancedEnvironmentSelector = ({ Environments - + {environments.map((environment) => (
{ - router.push(`/dashboard/project/${projectId}/environment/${environment.environmentId}`); + router.push( + `/dashboard/project/${projectId}/environment/${environment.environmentId}`, + ); }} >
{environment.name} - {environment.name === "production" && ( - - Prod - - )} + {environment.name === "production" && Prod}
{environment.environmentId === currentEnvironmentId && (
)}
- + {/* Action buttons for non-production environments */} {environment.name !== "production" && (
@@ -255,7 +268,7 @@ export const AdvancedEnvironmentSelector = ({ )}
))} - + - +
@@ -296,7 +309,7 @@ export const AdvancedEnvironmentSelector = ({ />
- + diff --git a/apps/dokploy/components/dashboard/project/ai/template-generator.tsx b/apps/dokploy/components/dashboard/project/ai/template-generator.tsx index 7b48e951c..1356b846b 100644 --- a/apps/dokploy/components/dashboard/project/ai/template-generator.tsx +++ b/apps/dokploy/components/dashboard/project/ai/template-generator.tsx @@ -103,7 +103,6 @@ export const TemplateGenerator = ({ environmentId }: Props) => { useState(defaultTemplateInfo); const utils = api.useUtils(); - const haveAtleasOneProviderEnabled = aiSettings?.some( (ai) => ai.isEnabled === true, ); diff --git a/apps/dokploy/components/dashboard/project/duplicate-project.tsx b/apps/dokploy/components/dashboard/project/duplicate-project.tsx index b9cdf56c4..47bf0c30f 100644 --- a/apps/dokploy/components/dashboard/project/duplicate-project.tsx +++ b/apps/dokploy/components/dashboard/project/duplicate-project.tsx @@ -57,17 +57,20 @@ export const DuplicateProject = ({ const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [duplicateType, setDuplicateType] = useState("new-project"); // "new-project" or "existing-environment" - const [selectedTargetProject, setSelectedTargetProject] = useState(""); - const [selectedTargetEnvironment, setSelectedTargetEnvironment] = useState(""); + const [selectedTargetProject, setSelectedTargetProject] = + useState(""); + const [selectedTargetEnvironment, setSelectedTargetEnvironment] = + useState(""); const utils = api.useUtils(); const router = useRouter(); // Queries for project and environment selection const { data: allProjects } = api.project.all.useQuery(); - const { data: selectedProjectEnvironments } = api.environment.byProjectId.useQuery( - { projectId: selectedTargetProject }, - { enabled: !!selectedTargetProject } - ); + const { data: selectedProjectEnvironments } = + api.environment.byProjectId.useQuery( + { projectId: selectedTargetProject }, + { enabled: !!selectedTargetProject }, + ); const selectedServices = services.filter((service) => selectedServiceIds.includes(service.id), @@ -84,7 +87,9 @@ export const DuplicateProject = ({ ); setOpen(false); if (duplicateType === "new-project") { - router.push(`/dashboard/project/${newProject?.projectId}/environment/${newProject?.environmentId}`); + router.push( + `/dashboard/project/${newProject?.projectId}/environment/${newProject?.environmentId}`, + ); } }, onError: (error) => { @@ -172,8 +177,13 @@ export const DuplicateProject = ({
- - + +
@@ -204,7 +214,8 @@ export const DuplicateProject = ({ {duplicateType === "existing-environment" && ( <> - {allProjects?.filter((p) => p.projectId !== environmentId).length === 0 ? ( + {allProjects?.filter((p) => p.projectId !== environmentId) + .length === 0 ? (

No other projects available. Create a new project first. @@ -291,12 +302,13 @@ export const DuplicateProject = ({ > Cancel - -

@@ -212,7 +216,8 @@ const Project = (
- No environments created yet. Click on Environments to create one. + No environments created yet. Click on Environments to create + one.
) : ( diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId].tsx index ad051ea52..8bc28e09e 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId].tsx @@ -284,10 +284,11 @@ const EnvironmentPage = ( const [selectedTargetEnvironment, setSelectedTargetEnvironment] = useState(""); - const { data: selectedProjectEnvironments } = api.environment.byProjectId.useQuery( - { projectId: selectedTargetProject }, - { enabled: !!selectedTargetProject } - ); + const { data: selectedProjectEnvironments } = + api.environment.byProjectId.useQuery( + { projectId: selectedTargetProject }, + { enabled: !!selectedTargetProject }, + ); const emptyServices = !currentEnvironment || @@ -617,7 +618,7 @@ const EnvironmentPage = ( }); break; } - await utils.environment.one.invalidate({ + await utils.environment.one.invalidate({ environmentId, }); success++; @@ -774,9 +775,7 @@ const EnvironmentPage = ( {currentEnvironment.name} {currentEnvironment.name === "production" && ( - - Production - + Production )} @@ -819,9 +818,7 @@ const EnvironmentPage = ( projectName={projectData?.name} environmentId={environmentId} /> - + Move Services - Select the target project and environment to move{" "} - {selectedServices.length} services + Select the target project and environment to + move {selectedServices.length} services
- {allProjects?.filter((p) => p.projectId !== projectId).length === 0 ? ( + {allProjects?.filter( + (p) => p.projectId !== projectId, + ).length === 0 ? (

@@ -997,7 +996,9 @@ const EnvironmentPage = ( <> {/* Step 1: Select Project */}

- + - {selectedProjectEnvironments?.map((env) => ( - - {env.name} - - ))} + {selectedProjectEnvironments?.map( + (env) => ( + + {env.name} + + ), + )}
@@ -1065,7 +1074,9 @@ const EnvironmentPage = ( onClick={handleBulkMove} isLoading={isBulkActionLoading} disabled={ - allProjects?.filter((p) => p.projectId !== projectId).length === 0 || + allProjects?.filter( + (p) => p.projectId !== projectId, + ).length === 0 || !selectedTargetProject || !selectedTargetEnvironment } diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mariadb/[mariadbId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mariadb/[mariadbId].tsx index b268beec8..11b11d026 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mariadb/[mariadbId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mariadb/[mariadbId].tsx @@ -84,7 +84,8 @@ const Mariadb = (
- Database: {data?.name} - {data?.environment?.project?.name} | Dokploy + Database: {data?.name} - {data?.environment?.project?.name} | + Dokploy @@ -303,7 +304,11 @@ Mariadb.getLayout = (page: ReactElement) => { }; export async function getServerSideProps( - ctx: GetServerSidePropsContext<{ mariadbId: string; activeTab: TabState; environmentId: string }>, + ctx: GetServerSidePropsContext<{ + mariadbId: string; + activeTab: TabState; + environmentId: string; + }>, ) { const { query, params, req, res } = ctx; const activeTab = query.tab; diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mongo/[mongoId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mongo/[mongoId].tsx index 046666550..02c863cce 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mongo/[mongoId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mongo/[mongoId].tsx @@ -305,7 +305,11 @@ Mongo.getLayout = (page: ReactElement) => { }; export async function getServerSideProps( - ctx: GetServerSidePropsContext<{ mongoId: string; activeTab: TabState; environmentId: string }>, + ctx: GetServerSidePropsContext<{ + mongoId: string; + activeTab: TabState; + environmentId: string; + }>, ) { const { query, params, req, res } = ctx; const activeTab = query.tab; diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mysql/[mysqlId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mysql/[mysqlId].tsx index d940c21b8..93a6416f4 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mysql/[mysqlId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/mysql/[mysqlId].tsx @@ -83,7 +83,8 @@ const MySql = (
- Database: {data?.name} - {data?.environment?.project?.name} | Dokploy + Database: {data?.name} - {data?.environment?.project?.name} | + Dokploy
@@ -289,7 +290,11 @@ MySql.getLayout = (page: ReactElement) => { }; export async function getServerSideProps( - ctx: GetServerSidePropsContext<{ mysqlId: string; activeTab: TabState; environmentId: string }>, + ctx: GetServerSidePropsContext<{ + mysqlId: string; + activeTab: TabState; + environmentId: string; + }>, ) { const { query, params, req, res } = ctx; const activeTab = query.tab; diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/postgres/[postgresId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/postgres/[postgresId].tsx index ed04f8205..c586a78d3 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/postgres/[postgresId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/postgres/[postgresId].tsx @@ -73,8 +73,7 @@ const Postgresql = ( }, { name: data?.environment?.name || "", - href: - `/dashboard/project/${projectId}/environment/${environmentId}`, + href: `/dashboard/project/${projectId}/environment/${environmentId}`, }, { name: data?.name || "", @@ -83,9 +82,7 @@ const Postgresql = ( /> - Database: {data?.name} - {data?.environment?.project?.name} - {" "} - | Dokploy + Database: {data?.name} - {data?.environment?.project?.name} | Dokploy
@@ -96,9 +93,7 @@ const Postgresql = (
- +
@@ -106,9 +101,7 @@ const Postgresql = ( {data?.name} {data?.description && ( - - {data?.description} - + {data?.description} )} @@ -118,17 +111,17 @@ const Postgresql = (
{data?.server?.name || "Dokploy Server"} - {data?.server?.serverStatus === - "inactive" && ( + {data?.server?.serverStatus === "inactive" && ( @@ -142,11 +135,9 @@ const Postgresql = ( side="top" > - You cannot, deploy this - application because the - server is inactive, - please upgrade your plan - to add more servers. + You cannot, deploy this application because the + server is inactive, please upgrade your plan to add + more servers. @@ -156,178 +147,138 @@ const Postgresql = (
- {(auth?.role === "owner" || - auth?.canDeleteServices) && ( - + {(auth?.role === "owner" || auth?.canDeleteServices) && ( + )}
- {data?.server?.serverStatus === "inactive" - ? ( -
-
- - - This service is hosted on the - server{" "} - {data.server.name}, but this - server has been disabled because - your current plan doesn't - include enough servers. Please - purchase more servers to regain - access to this application. - - - Go to{" "} - - Billing - - -
+ {data?.server?.serverStatus === "inactive" ? ( +
+
+ + + This service is hosted on the server {data.server.name}, + but this server has been disabled because your current + plan doesn't include enough servers. Please purchase more + servers to regain access to this application. + + + Go to{" "} + + Billing + +
- ) - : ( - { - setSab(e as TabState); - const newPath = - `/dashboard/project/${projectId}/environment/${environmentId}/services/postgres/${postgresId}?tab=${e}`; +
+ ) : ( + { + setSab(e as TabState); + const newPath = `/dashboard/project/${projectId}/environment/${environmentId}/services/postgres/${postgresId}?tab=${e}`; - router.push(newPath, undefined, { - shallow: true, - }); - }} - > -
- +
+ - - General - - - Environment - - - Logs - - {((data?.serverId && isCloud) || - !data?.server) && ( - - Monitoring - - )} - - Backups - - - Advanced - - -
+ )} + > + General + Environment + Logs + {((data?.serverId && isCloud) || !data?.server) && ( + Monitoring + )} + Backups + Advanced +
+
- -
- - - + +
+ + + +
+
+ +
+ +
+
+ +
+
+ {data?.serverId && isCloud ? ( + + ) : ( + <> + + + )}
- - -
- -
-
- -
-
- {data?.serverId && isCloud - ? ( - - ) - : ( - <> - - - )} -
-
-
- -
- -
-
- -
- -
-
- -
- -
-
- - )} +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ + )}
@@ -342,9 +293,11 @@ Postgresql.getLayout = (page: ReactElement) => { }; export async function getServerSideProps( - ctx: GetServerSidePropsContext< - { postgresId: string; activeTab: TabState; environmentId: string } - >, + ctx: GetServerSidePropsContext<{ + postgresId: string; + activeTab: TabState; + environmentId: string; + }>, ) { const { query, params, req, res } = ctx; const activeTab = query.tab; diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/redis/[redisId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/redis/[redisId].tsx index 891df9dac..b2e5b4240 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/redis/[redisId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId]/services/redis/[redisId].tsx @@ -73,8 +73,7 @@ const Redis = ( }, { name: data?.environment?.name || "", - href: - `/dashboard/project/${projectId}/environment/${environmentId}`, + href: `/dashboard/project/${projectId}/environment/${environmentId}`, }, { name: data?.name || "", @@ -295,7 +294,11 @@ Redis.getLayout = (page: ReactElement) => { }; export async function getServerSideProps( - ctx: GetServerSidePropsContext<{ redisId: string; activeTab: TabState; environmentId: string }>, + ctx: GetServerSidePropsContext<{ + redisId: string; + activeTab: TabState; + environmentId: string; + }>, ) { const { query, params, req, res } = ctx; const activeTab = query.tab; diff --git a/apps/dokploy/server/api/routers/ai.ts b/apps/dokploy/server/api/routers/ai.ts index 28265d90a..6fa2e0cdc 100644 --- a/apps/dokploy/server/api/routers/ai.ts +++ b/apps/dokploy/server/api/routers/ai.ts @@ -4,7 +4,11 @@ import { apiUpdateAi, deploySuggestionSchema, } from "@dokploy/server/db/schema/ai"; -import { createDomain, createMount, findEnvironmentById } from "@dokploy/server/index"; +import { + createDomain, + createMount, + findEnvironmentById, +} from "@dokploy/server/index"; import { deleteAiSettings, getAiSettingById, @@ -194,8 +198,6 @@ export const aiRouter = createTRPCRouter({ }); } - - const projectName = slugify(`${project.name} ${input.id}`); const compose = await createComposeByTemplate({ diff --git a/apps/dokploy/server/api/routers/application.ts b/apps/dokploy/server/api/routers/application.ts index ef85e6e9e..610b765e0 100644 --- a/apps/dokploy/server/api/routers/application.ts +++ b/apps/dokploy/server/api/routers/application.ts @@ -126,7 +126,8 @@ export const applicationRouter = createTRPCRouter({ } const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -218,7 +219,8 @@ export const applicationRouter = createTRPCRouter({ const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -260,7 +262,10 @@ export const applicationRouter = createTRPCRouter({ .input(apiFindOneApplication) .mutation(async ({ input, ctx }) => { const service = await findApplicationById(input.applicationId); - if (service.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + service.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to stop this application", @@ -280,7 +285,10 @@ export const applicationRouter = createTRPCRouter({ .input(apiFindOneApplication) .mutation(async ({ input, ctx }) => { const service = await findApplicationById(input.applicationId); - if (service.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + service.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to start this application", @@ -302,7 +310,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -337,7 +346,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -355,7 +365,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -380,7 +391,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -407,7 +419,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -435,7 +448,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -461,7 +475,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -487,7 +502,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -510,7 +526,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -535,7 +552,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -596,7 +614,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -610,7 +629,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -636,7 +656,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -653,7 +674,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -689,7 +711,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -704,7 +727,8 @@ export const applicationRouter = createTRPCRouter({ .query(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -740,7 +764,10 @@ export const applicationRouter = createTRPCRouter({ const app = await findApplicationById(input.applicationId as string); - if (app.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + app.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this application", @@ -783,7 +810,8 @@ export const applicationRouter = createTRPCRouter({ const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -825,7 +853,8 @@ export const applicationRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -833,8 +862,13 @@ export const applicationRouter = createTRPCRouter({ }); } - const targetEnvironment = await findEnvironmentById(input.targetEnvironmentId); - if (targetEnvironment.project.organizationId !== ctx.session.activeOrganizationId) { + const targetEnvironment = await findEnvironmentById( + input.targetEnvironmentId, + ); + if ( + targetEnvironment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move to this environment", diff --git a/apps/dokploy/server/api/routers/compose.ts b/apps/dokploy/server/api/routers/compose.ts index 9a4b050c3..c208efe0e 100644 --- a/apps/dokploy/server/api/routers/compose.ts +++ b/apps/dokploy/server/api/routers/compose.ts @@ -121,7 +121,10 @@ export const composeRouter = createTRPCRouter({ } const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this compose", @@ -172,7 +175,10 @@ export const composeRouter = createTRPCRouter({ .input(apiUpdateCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to update this compose", @@ -227,7 +233,10 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to clean this compose", @@ -240,7 +249,10 @@ export const composeRouter = createTRPCRouter({ .input(apiFetchServices) .query(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to load this compose", @@ -257,7 +269,10 @@ export const composeRouter = createTRPCRouter({ ) .query(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to load this compose", @@ -276,7 +291,8 @@ export const composeRouter = createTRPCRouter({ const compose = await findComposeById(input.composeId); if ( - compose.environment.project.organizationId !== ctx.session.activeOrganizationId + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -302,7 +318,10 @@ export const composeRouter = createTRPCRouter({ .input(apiRandomizeCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to randomize this compose", @@ -314,7 +333,10 @@ export const composeRouter = createTRPCRouter({ .input(apiRandomizeCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to randomize this compose", @@ -329,7 +351,10 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .query(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to get this compose", @@ -347,7 +372,10 @@ export const composeRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this compose", @@ -380,7 +408,10 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to redeploy this compose", @@ -412,7 +443,10 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to stop this compose", @@ -426,7 +460,10 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to stop this compose", @@ -441,7 +478,10 @@ export const composeRouter = createTRPCRouter({ .query(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to get this compose", @@ -454,7 +494,10 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to refresh this compose", @@ -599,7 +642,10 @@ export const composeRouter = createTRPCRouter({ .input(apiFindCompose) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to disconnect this git provider", @@ -660,15 +706,23 @@ export const composeRouter = createTRPCRouter({ ) .mutation(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move this compose", }); } - const targetEnvironment = await findEnvironmentById(input.targetEnvironmentId); - if (targetEnvironment.project.organizationId !== ctx.session.activeOrganizationId) { + const targetEnvironment = await findEnvironmentById( + input.targetEnvironmentId, + ); + if ( + targetEnvironment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move to this environment", @@ -706,7 +760,8 @@ export const composeRouter = createTRPCRouter({ const compose = await findComposeById(input.composeId); if ( - compose.environment.project.organizationId !== ctx.session.activeOrganizationId + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -777,7 +832,8 @@ export const composeRouter = createTRPCRouter({ ); if ( - compose.environment.project.organizationId !== ctx.session.activeOrganizationId + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", diff --git a/apps/dokploy/server/api/routers/deployment.ts b/apps/dokploy/server/api/routers/deployment.ts index 4807ac9ef..9004a0a05 100644 --- a/apps/dokploy/server/api/routers/deployment.ts +++ b/apps/dokploy/server/api/routers/deployment.ts @@ -29,7 +29,8 @@ export const deploymentRouter = createTRPCRouter({ .query(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -43,7 +44,10 @@ export const deploymentRouter = createTRPCRouter({ .input(apiFindAllByCompose) .query(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this compose", diff --git a/apps/dokploy/server/api/routers/domain.ts b/apps/dokploy/server/api/routers/domain.ts index d2d40419c..1f6264351 100644 --- a/apps/dokploy/server/api/routers/domain.ts +++ b/apps/dokploy/server/api/routers/domain.ts @@ -34,7 +34,8 @@ export const domainRouter = createTRPCRouter({ if (input.domainType === "compose" && input.composeId) { const compose = await findComposeById(input.composeId); if ( - compose.environment.project.organizationId !== ctx.session.activeOrganizationId + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -70,7 +71,8 @@ export const domainRouter = createTRPCRouter({ .query(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -83,7 +85,10 @@ export const domainRouter = createTRPCRouter({ .input(apiFindCompose) .query(async ({ input, ctx }) => { const compose = await findComposeById(input.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this compose", @@ -122,7 +127,8 @@ export const domainRouter = createTRPCRouter({ if (currentDomain.applicationId) { const newApp = await findApplicationById(currentDomain.applicationId); if ( - newApp.environment.project.organizationId !== ctx.session.activeOrganizationId + newApp.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -132,7 +138,8 @@ export const domainRouter = createTRPCRouter({ } else if (currentDomain.composeId) { const newCompose = await findComposeById(currentDomain.composeId); if ( - newCompose.environment.project.organizationId !== ctx.session.activeOrganizationId + newCompose.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -144,8 +151,8 @@ export const domainRouter = createTRPCRouter({ currentDomain.previewDeploymentId, ); if ( - newPreviewDeployment.application.environment.project.organizationId !== - ctx.session.activeOrganizationId + newPreviewDeployment.application.environment.project + .organizationId !== ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -175,7 +182,8 @@ export const domainRouter = createTRPCRouter({ if (domain.applicationId) { const application = await findApplicationById(domain.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -184,7 +192,10 @@ export const domainRouter = createTRPCRouter({ } } else if (domain.composeId) { const compose = await findComposeById(domain.composeId); - if (compose.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this compose", @@ -211,7 +222,8 @@ export const domainRouter = createTRPCRouter({ } else if (domain.composeId) { const compose = await findComposeById(domain.composeId); if ( - compose.environment.project.organizationId !== ctx.session.activeOrganizationId + compose.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", diff --git a/apps/dokploy/server/api/routers/mariadb.ts b/apps/dokploy/server/api/routers/mariadb.ts index 055689d61..dc811e0ca 100644 --- a/apps/dokploy/server/api/routers/mariadb.ts +++ b/apps/dokploy/server/api/routers/mariadb.ts @@ -61,7 +61,7 @@ export const mariadbRouter = createTRPCRouter({ message: "You need to use a server to create a Mariadb", }); } - + if (project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -107,7 +107,10 @@ export const mariadbRouter = createTRPCRouter({ ); } const mariadb = await findMariadbById(input.mariadbId); - if (mariadb.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mariadb.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this Mariadb", @@ -120,7 +123,10 @@ export const mariadbRouter = createTRPCRouter({ .input(apiFindOneMariaDB) .mutation(async ({ input, ctx }) => { const service = await findMariadbById(input.mariadbId); - if (service.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + service.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to start this Mariadb", @@ -157,7 +163,10 @@ export const mariadbRouter = createTRPCRouter({ .input(apiSaveExternalPortMariaDB) .mutation(async ({ input, ctx }) => { const mongo = await findMariadbById(input.mariadbId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to save this external port", @@ -173,7 +182,10 @@ export const mariadbRouter = createTRPCRouter({ .input(apiDeployMariaDB) .mutation(async ({ input, ctx }) => { const mariadb = await findMariadbById(input.mariadbId); - if (mariadb.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mariadb.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this Mariadb", @@ -194,7 +206,10 @@ export const mariadbRouter = createTRPCRouter({ .input(apiDeployMariaDB) .subscription(async ({ input, ctx }) => { const mariadb = await findMariadbById(input.mariadbId); - if (mariadb.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mariadb.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this Mariadb", @@ -211,7 +226,10 @@ export const mariadbRouter = createTRPCRouter({ .input(apiChangeMariaDBStatus) .mutation(async ({ input, ctx }) => { const mongo = await findMariadbById(input.mariadbId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to change this Mariadb status", @@ -235,7 +253,10 @@ export const mariadbRouter = createTRPCRouter({ } const mongo = await findMariadbById(input.mariadbId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to delete this Mariadb", @@ -261,7 +282,10 @@ export const mariadbRouter = createTRPCRouter({ .input(apiSaveEnvironmentVariablesMariaDB) .mutation(async ({ input, ctx }) => { const mariadb = await findMariadbById(input.mariadbId); - if (mariadb.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mariadb.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to save this environment", @@ -284,7 +308,10 @@ export const mariadbRouter = createTRPCRouter({ .input(apiResetMariadb) .mutation(async ({ input, ctx }) => { const mariadb = await findMariadbById(input.mariadbId); - if (mariadb.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mariadb.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to reload this Mariadb", @@ -314,7 +341,10 @@ export const mariadbRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const { mariadbId, ...rest } = input; const mariadb = await findMariadbById(mariadbId); - if (mariadb.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mariadb.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to update this Mariadb", @@ -342,15 +372,23 @@ export const mariadbRouter = createTRPCRouter({ ) .mutation(async ({ input, ctx }) => { const mariadb = await findMariadbById(input.mariadbId); - if (mariadb.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mariadb.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move this mariadb", }); } - const targetEnvironment = await findEnvironmentById(input.targetEnvironmentId); - if (targetEnvironment.project.organizationId !== ctx.session.activeOrganizationId) { + const targetEnvironment = await findEnvironmentById( + input.targetEnvironmentId, + ); + if ( + targetEnvironment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move to this environment", @@ -380,7 +418,10 @@ export const mariadbRouter = createTRPCRouter({ .input(apiRebuildMariadb) .mutation(async ({ input, ctx }) => { const mariadb = await findMariadbById(input.mariadbId); - if (mariadb.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mariadb.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to rebuild this MariaDB database", diff --git a/apps/dokploy/server/api/routers/mongo.ts b/apps/dokploy/server/api/routers/mongo.ts index f73a715bf..1f054a1c9 100644 --- a/apps/dokploy/server/api/routers/mongo.ts +++ b/apps/dokploy/server/api/routers/mongo.ts @@ -112,7 +112,10 @@ export const mongoRouter = createTRPCRouter({ } const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this mongo", @@ -126,7 +129,10 @@ export const mongoRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const service = await findMongoById(input.mongoId); - if (service.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + service.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to start this mongo", @@ -149,7 +155,10 @@ export const mongoRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to stop this mongo", @@ -171,7 +180,10 @@ export const mongoRouter = createTRPCRouter({ .input(apiSaveExternalPortMongo) .mutation(async ({ input, ctx }) => { const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to save this external port", @@ -187,7 +199,10 @@ export const mongoRouter = createTRPCRouter({ .input(apiDeployMongo) .mutation(async ({ input, ctx }) => { const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this mongo", @@ -207,7 +222,10 @@ export const mongoRouter = createTRPCRouter({ .input(apiDeployMongo) .subscription(async ({ input, ctx }) => { const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this mongo", @@ -224,7 +242,10 @@ export const mongoRouter = createTRPCRouter({ .input(apiChangeMongoStatus) .mutation(async ({ input, ctx }) => { const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to change this mongo status", @@ -239,7 +260,10 @@ export const mongoRouter = createTRPCRouter({ .input(apiResetMongo) .mutation(async ({ input, ctx }) => { const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to reload this mongo", @@ -278,7 +302,10 @@ export const mongoRouter = createTRPCRouter({ const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to delete this mongo", @@ -304,7 +331,10 @@ export const mongoRouter = createTRPCRouter({ .input(apiSaveEnvironmentVariablesMongo) .mutation(async ({ input, ctx }) => { const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to save this environment", @@ -328,7 +358,10 @@ export const mongoRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const { mongoId, ...rest } = input; const mongo = await findMongoById(mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to update this mongo", @@ -356,15 +389,23 @@ export const mongoRouter = createTRPCRouter({ ) .mutation(async ({ input, ctx }) => { const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move this mongo", }); } - const targetEnvironment = await findEnvironmentById(input.targetEnvironmentId); - if (targetEnvironment.project.organizationId !== ctx.session.activeOrganizationId) { + const targetEnvironment = await findEnvironmentById( + input.targetEnvironmentId, + ); + if ( + targetEnvironment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move to this environment", @@ -394,7 +435,10 @@ export const mongoRouter = createTRPCRouter({ .input(apiRebuildMongo) .mutation(async ({ input, ctx }) => { const mongo = await findMongoById(input.mongoId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to rebuild this MongoDB database", diff --git a/apps/dokploy/server/api/routers/mysql.ts b/apps/dokploy/server/api/routers/mysql.ts index 497c7fdb8..5edb27da4 100644 --- a/apps/dokploy/server/api/routers/mysql.ts +++ b/apps/dokploy/server/api/routers/mysql.ts @@ -113,7 +113,10 @@ export const mysqlRouter = createTRPCRouter({ ); } const mysql = await findMySqlById(input.mysqlId); - if (mysql.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mysql.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this MySQL", @@ -126,7 +129,10 @@ export const mysqlRouter = createTRPCRouter({ .input(apiFindOneMySql) .mutation(async ({ input, ctx }) => { const service = await findMySqlById(input.mysqlId); - if (service.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + service.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to start this MySQL", @@ -148,7 +154,10 @@ export const mysqlRouter = createTRPCRouter({ .input(apiFindOneMySql) .mutation(async ({ input, ctx }) => { const mongo = await findMySqlById(input.mysqlId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to stop this MySQL", @@ -169,7 +178,10 @@ export const mysqlRouter = createTRPCRouter({ .input(apiSaveExternalPortMySql) .mutation(async ({ input, ctx }) => { const mongo = await findMySqlById(input.mysqlId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to save this external port", @@ -185,7 +197,10 @@ export const mysqlRouter = createTRPCRouter({ .input(apiDeployMySql) .mutation(async ({ input, ctx }) => { const mysql = await findMySqlById(input.mysqlId); - if (mysql.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mysql.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this MySQL", @@ -205,7 +220,10 @@ export const mysqlRouter = createTRPCRouter({ .input(apiDeployMySql) .subscription(async ({ input, ctx }) => { const mysql = await findMySqlById(input.mysqlId); - if (mysql.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mysql.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this MySQL", @@ -222,7 +240,10 @@ export const mysqlRouter = createTRPCRouter({ .input(apiChangeMySqlStatus) .mutation(async ({ input, ctx }) => { const mongo = await findMySqlById(input.mysqlId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to change this MySQL status", @@ -237,7 +258,10 @@ export const mysqlRouter = createTRPCRouter({ .input(apiResetMysql) .mutation(async ({ input, ctx }) => { const mysql = await findMySqlById(input.mysqlId); - if (mysql.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mysql.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to reload this MySQL", @@ -273,7 +297,10 @@ export const mysqlRouter = createTRPCRouter({ ); } const mongo = await findMySqlById(input.mysqlId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to delete this MySQL", @@ -299,7 +326,10 @@ export const mysqlRouter = createTRPCRouter({ .input(apiSaveEnvironmentVariablesMySql) .mutation(async ({ input, ctx }) => { const mysql = await findMySqlById(input.mysqlId); - if (mysql.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mysql.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to save this environment", @@ -323,7 +353,10 @@ export const mysqlRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const { mysqlId, ...rest } = input; const mysql = await findMySqlById(mysqlId); - if (mysql.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mysql.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to update this MySQL", @@ -351,15 +384,23 @@ export const mysqlRouter = createTRPCRouter({ ) .mutation(async ({ input, ctx }) => { const mysql = await findMySqlById(input.mysqlId); - if (mysql.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mysql.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move this mysql", }); } - const targetEnvironment = await findEnvironmentById(input.targetEnvironmentId); - if (targetEnvironment.project.organizationId !== ctx.session.activeOrganizationId) { + const targetEnvironment = await findEnvironmentById( + input.targetEnvironmentId, + ); + if ( + targetEnvironment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move to this environment", @@ -389,7 +430,10 @@ export const mysqlRouter = createTRPCRouter({ .input(apiRebuildMysql) .mutation(async ({ input, ctx }) => { const mysql = await findMySqlById(input.mysqlId); - if (mysql.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mysql.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to rebuild this MySQL database", diff --git a/apps/dokploy/server/api/routers/postgres.ts b/apps/dokploy/server/api/routers/postgres.ts index 04a10baaf..a05072ab7 100644 --- a/apps/dokploy/server/api/routers/postgres.ts +++ b/apps/dokploy/server/api/routers/postgres.ts @@ -113,7 +113,8 @@ export const postgresRouter = createTRPCRouter({ const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -128,7 +129,10 @@ export const postgresRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const service = await findPostgresById(input.postgresId); - if (service.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + service.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to start this Postgres", @@ -151,7 +155,8 @@ export const postgresRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -175,7 +180,8 @@ export const postgresRouter = createTRPCRouter({ const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -193,7 +199,8 @@ export const postgresRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -216,7 +223,8 @@ export const postgresRouter = createTRPCRouter({ .subscription(async ({ input, ctx }) => { const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -235,7 +243,8 @@ export const postgresRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -261,7 +270,8 @@ export const postgresRouter = createTRPCRouter({ const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -286,7 +296,8 @@ export const postgresRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -311,7 +322,8 @@ export const postgresRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -343,7 +355,8 @@ export const postgresRouter = createTRPCRouter({ const { postgresId, ...rest } = input; const postgres = await findPostgresById(postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -373,7 +386,8 @@ export const postgresRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -381,8 +395,13 @@ export const postgresRouter = createTRPCRouter({ }); } - const targetEnvironment = await findEnvironmentById(input.targetEnvironmentId); - if (targetEnvironment.project.organizationId !== ctx.session.activeOrganizationId) { + const targetEnvironment = await findEnvironmentById( + input.targetEnvironmentId, + ); + if ( + targetEnvironment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move to this environment", @@ -413,7 +432,8 @@ export const postgresRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const postgres = await findPostgresById(input.postgresId); if ( - postgres.environment.project.organizationId !== ctx.session.activeOrganizationId + postgres.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", diff --git a/apps/dokploy/server/api/routers/preview-deployment.ts b/apps/dokploy/server/api/routers/preview-deployment.ts index 0aae5a65d..49b781101 100644 --- a/apps/dokploy/server/api/routers/preview-deployment.ts +++ b/apps/dokploy/server/api/routers/preview-deployment.ts @@ -15,7 +15,8 @@ export const previewDeploymentRouter = createTRPCRouter({ .query(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", diff --git a/apps/dokploy/server/api/routers/project.ts b/apps/dokploy/server/api/routers/project.ts index 42797a5ae..779756432 100644 --- a/apps/dokploy/server/api/routers/project.ts +++ b/apps/dokploy/server/api/routers/project.ts @@ -347,10 +347,15 @@ export const projectRouter = createTRPCRouter({ } // Get source project - const sourceEnvironment = input.duplicateInSameProject ? await findEnvironmentById(input.sourceEnvironmentId) : null; + const sourceEnvironment = input.duplicateInSameProject + ? await findEnvironmentById(input.sourceEnvironmentId) + : null; - - if (input.duplicateInSameProject &&sourceEnvironment?.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + input.duplicateInSameProject && + sourceEnvironment?.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this project", @@ -369,8 +374,7 @@ export const projectRouter = createTRPCRouter({ ctx.session.activeOrganizationId, ).then((value) => value.environment); - console.log("targetProject", targetProject); - + console.log("targetProject", targetProject); if (input.includeServices) { const servicesToDuplicate = input.selectedServices || []; diff --git a/apps/dokploy/server/api/routers/redis.ts b/apps/dokploy/server/api/routers/redis.ts index b842e22f6..d377b1707 100644 --- a/apps/dokploy/server/api/routers/redis.ts +++ b/apps/dokploy/server/api/routers/redis.ts @@ -60,7 +60,7 @@ export const redisRouter = createTRPCRouter({ message: "You need to use a server to create a Redis", }); } - + if (project.organizationId !== ctx.session.activeOrganizationId) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -104,7 +104,10 @@ export const redisRouter = createTRPCRouter({ } const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to access this Redis", @@ -117,7 +120,10 @@ export const redisRouter = createTRPCRouter({ .input(apiFindOneRedis) .mutation(async ({ input, ctx }) => { const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to start this Redis", @@ -139,7 +145,10 @@ export const redisRouter = createTRPCRouter({ .input(apiResetRedis) .mutation(async ({ input, ctx }) => { const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to reload this Redis", @@ -169,7 +178,10 @@ export const redisRouter = createTRPCRouter({ .input(apiFindOneRedis) .mutation(async ({ input, ctx }) => { const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to stop this Redis", @@ -190,7 +202,10 @@ export const redisRouter = createTRPCRouter({ .input(apiSaveExternalPortRedis) .mutation(async ({ input, ctx }) => { const mongo = await findRedisById(input.redisId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to save this external port", @@ -206,7 +221,10 @@ export const redisRouter = createTRPCRouter({ .input(apiDeployRedis) .mutation(async ({ input, ctx }) => { const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this Redis", @@ -226,7 +244,10 @@ export const redisRouter = createTRPCRouter({ .input(apiDeployRedis) .subscription(async ({ input, ctx }) => { const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to deploy this Redis", @@ -242,7 +263,10 @@ export const redisRouter = createTRPCRouter({ .input(apiChangeRedisStatus) .mutation(async ({ input, ctx }) => { const mongo = await findRedisById(input.redisId); - if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + mongo.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to change this Redis status", @@ -267,7 +291,10 @@ export const redisRouter = createTRPCRouter({ const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to delete this Redis", @@ -290,7 +317,10 @@ export const redisRouter = createTRPCRouter({ .input(apiSaveEnvironmentVariablesRedis) .mutation(async ({ input, ctx }) => { const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to save this environment", @@ -335,15 +365,23 @@ export const redisRouter = createTRPCRouter({ ) .mutation(async ({ input, ctx }) => { const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move this redis", }); } - const targetEnvironment = await findEnvironmentById(input.targetEnvironmentId); - if (targetEnvironment.project.organizationId !== ctx.session.activeOrganizationId) { + const targetEnvironment = await findEnvironmentById( + input.targetEnvironmentId, + ); + if ( + targetEnvironment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to move to this environment", @@ -373,7 +411,10 @@ export const redisRouter = createTRPCRouter({ .input(apiRebuildRedis) .mutation(async ({ input, ctx }) => { const redis = await findRedisById(input.redisId); - if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) { + if ( + redis.environment.project.organizationId !== + ctx.session.activeOrganizationId + ) { throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized to rebuild this Redis database", diff --git a/apps/dokploy/server/api/routers/security.ts b/apps/dokploy/server/api/routers/security.ts index edbcc9d05..3d8374b4c 100644 --- a/apps/dokploy/server/api/routers/security.ts +++ b/apps/dokploy/server/api/routers/security.ts @@ -19,7 +19,8 @@ export const securityRouter = createTRPCRouter({ .mutation(async ({ input, ctx }) => { const application = await findApplicationById(input.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -34,7 +35,8 @@ export const securityRouter = createTRPCRouter({ const security = await findSecurityById(input.securityId); const application = await findApplicationById(security.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -49,7 +51,8 @@ export const securityRouter = createTRPCRouter({ const security = await findSecurityById(input.securityId); const application = await findApplicationById(security.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", @@ -64,7 +67,8 @@ export const securityRouter = createTRPCRouter({ const security = await findSecurityById(input.securityId); const application = await findApplicationById(security.applicationId); if ( - application.environment.project.organizationId !== ctx.session.activeOrganizationId + application.environment.project.organizationId !== + ctx.session.activeOrganizationId ) { throw new TRPCError({ code: "UNAUTHORIZED", diff --git a/packages/server/src/db/schema/application.ts b/packages/server/src/db/schema/application.ts index ee00cfc88..42e958e4e 100644 --- a/packages/server/src/db/schema/application.ts +++ b/packages/server/src/db/schema/application.ts @@ -203,7 +203,6 @@ export const applications = pgTable("application", { export const applicationsRelations = relations( applications, ({ one, many }) => ({ - environment: one(environments, { fields: [applications.environmentId], references: [environments.environmentId], diff --git a/packages/server/src/db/schema/compose.ts b/packages/server/src/db/schema/compose.ts index b023149f1..2d75e511a 100644 --- a/packages/server/src/db/schema/compose.ts +++ b/packages/server/src/db/schema/compose.ts @@ -110,7 +110,6 @@ export const compose = pgTable("compose", { }); export const composeRelations = relations(compose, ({ one, many }) => ({ - environment: one(environments, { fields: [compose.environmentId], references: [environments.environmentId], diff --git a/packages/server/src/db/schema/mariadb.ts b/packages/server/src/db/schema/mariadb.ts index 17b4f9b0d..716ca7b71 100644 --- a/packages/server/src/db/schema/mariadb.ts +++ b/packages/server/src/db/schema/mariadb.ts @@ -77,7 +77,6 @@ export const mariadb = pgTable("mariadb", { }); export const mariadbRelations = relations(mariadb, ({ one, many }) => ({ - environment: one(environments, { fields: [mariadb.environmentId], references: [environments.environmentId], diff --git a/packages/server/src/db/schema/mongo.ts b/packages/server/src/db/schema/mongo.ts index 70f36c1a4..ead51ef2d 100644 --- a/packages/server/src/db/schema/mongo.ts +++ b/packages/server/src/db/schema/mongo.ts @@ -74,7 +74,6 @@ export const mongo = pgTable("mongo", { }); export const mongoRelations = relations(mongo, ({ one, many }) => ({ - environment: one(environments, { fields: [mongo.environmentId], references: [environments.environmentId], diff --git a/packages/server/src/db/schema/mysql.ts b/packages/server/src/db/schema/mysql.ts index e2367b6c3..eef6b496f 100644 --- a/packages/server/src/db/schema/mysql.ts +++ b/packages/server/src/db/schema/mysql.ts @@ -75,7 +75,6 @@ export const mysql = pgTable("mysql", { }); export const mysqlRelations = relations(mysql, ({ one, many }) => ({ - environment: one(environments, { fields: [mysql.environmentId], references: [environments.environmentId], diff --git a/packages/server/src/db/schema/postgres.ts b/packages/server/src/db/schema/postgres.ts index 99ba645db..929ee7ffa 100644 --- a/packages/server/src/db/schema/postgres.ts +++ b/packages/server/src/db/schema/postgres.ts @@ -75,7 +75,6 @@ export const postgres = pgTable("postgres", { }); export const postgresRelations = relations(postgres, ({ one, many }) => ({ - environment: one(environments, { fields: [postgres.environmentId], references: [environments.environmentId], diff --git a/packages/server/src/db/schema/redis.ts b/packages/server/src/db/schema/redis.ts index 539f4fb76..29e40282d 100644 --- a/packages/server/src/db/schema/redis.ts +++ b/packages/server/src/db/schema/redis.ts @@ -71,7 +71,6 @@ export const redis = pgTable("redis", { }); export const redisRelations = relations(redis, ({ one, many }) => ({ - environment: one(environments, { fields: [redis.environmentId], references: [environments.environmentId], diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index 30579d29a..bd5118de5 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -86,7 +86,6 @@ export const createApplication = async ( .returning() .then((value) => value[0]); - if (!newApplication) { throw new TRPCError({ code: "BAD_REQUEST", diff --git a/packages/server/src/services/environment.ts b/packages/server/src/services/environment.ts index 45341fecf..43a0d0949 100644 --- a/packages/server/src/services/environment.ts +++ b/packages/server/src/services/environment.ts @@ -62,7 +62,6 @@ export const findEnvironmentsByProjectId = async (projectId: string) => { }; export const deleteEnvironment = async (environmentId: string) => { - const currentEnvironment = await findEnvironmentById(environmentId); if (currentEnvironment.name === "production") { throw new TRPCError({ diff --git a/packages/server/src/services/preview-deployment.ts b/packages/server/src/services/preview-deployment.ts index 03346aae6..5ee763b08 100644 --- a/packages/server/src/services/preview-deployment.ts +++ b/packages/server/src/services/preview-deployment.ts @@ -49,8 +49,6 @@ export const findPreviewDeploymentById = async ( return application; }; - - export const removePreviewDeployment = async (previewDeploymentId: string) => { try { const previewDeployment = diff --git a/packages/server/src/services/project.ts b/packages/server/src/services/project.ts index fb8bd8635..cf58b18fa 100644 --- a/packages/server/src/services/project.ts +++ b/packages/server/src/services/project.ts @@ -36,13 +36,13 @@ export const createProject = async ( } // Automatically create a production environment - const newEnvironment = await createProductionEnvironment(newProject.projectId); - return { - project: newProject, - environment: newEnvironment, - }; - - + const newEnvironment = await createProductionEnvironment( + newProject.projectId, + ); + return { + project: newProject, + environment: newEnvironment, + }; }; export const findProjectById = async (projectId: string) => {