From f70e154e83f86dd02e34d013817c7005b001b258 Mon Sep 17 00:00:00 2001 From: Joffrey Date: Mon, 4 Nov 2024 13:48:19 +0100 Subject: [PATCH 1/7] fix(dokploy): exclude password column from application queries --- apps/dokploy/server/api/routers/project.ts | 6 ++++++ packages/server/src/services/application.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/apps/dokploy/server/api/routers/project.ts b/apps/dokploy/server/api/routers/project.ts index 744589028..2914f2ce2 100644 --- a/apps/dokploy/server/api/routers/project.ts +++ b/apps/dokploy/server/api/routers/project.ts @@ -139,6 +139,9 @@ export const projectRouter = createTRPCRouter({ )})`, with: { applications: { + columns: { + password: false, + }, where: and( buildServiceFilter(applications.applicationId, accesedServices), eq(projects.adminId, ctx.user.adminId), @@ -174,6 +177,9 @@ export const projectRouter = createTRPCRouter({ return await db.query.projects.findMany({ with: { applications: { + columns: { + password: false, + }, with: { domains: true, }, diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index ec0c0c2f5..a0fb419f1 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -101,6 +101,9 @@ export const findApplicationById = async (applicationId: string) => { bitbucket: true, server: true, }, + columns: { + password: false, + }, }); if (!application) { throw new TRPCError({ From 8d154200d3ea76b2e5ef4d47312d4987421ff006 Mon Sep 17 00:00:00 2001 From: Joffrey Date: Mon, 4 Nov 2024 13:52:35 +0100 Subject: [PATCH 2/7] fix(dokploy): exclude password column from project queries --- apps/dokploy/server/api/routers/project.ts | 3 +++ packages/server/src/services/project.ts | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/dokploy/server/api/routers/project.ts b/apps/dokploy/server/api/routers/project.ts index 2914f2ce2..027f0d957 100644 --- a/apps/dokploy/server/api/routers/project.ts +++ b/apps/dokploy/server/api/routers/project.ts @@ -86,6 +86,9 @@ export const projectRouter = createTRPCRouter({ applications.applicationId, accesedServices, ), + columns: { + password: false, + }, }, mariadb: { where: buildServiceFilter(mariadb.mariadbId, accesedServices), diff --git a/packages/server/src/services/project.ts b/packages/server/src/services/project.ts index 47e8ac40e..b0d9982e3 100644 --- a/packages/server/src/services/project.ts +++ b/packages/server/src/services/project.ts @@ -41,7 +41,11 @@ export const findProjectById = async (projectId: string) => { const project = await db.query.projects.findFirst({ where: eq(projects.projectId, projectId), with: { - applications: true, + applications: { + columns: { + password: false, + }, + }, mariadb: true, mongo: true, mysql: true, From 756999b26243bf1d3dd93fd8732f4d15d0174e80 Mon Sep 17 00:00:00 2001 From: Joffrey Date: Tue, 5 Nov 2024 09:33:01 +0100 Subject: [PATCH 3/7] fix(dokploy): add passwordLenght column and hide password --- .../general/generic/save-docker-provider.tsx | 2 +- packages/server/src/services/application.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/general/generic/save-docker-provider.tsx b/apps/dokploy/components/dashboard/application/general/generic/save-docker-provider.tsx index 81a350498..a841cdce8 100644 --- a/apps/dokploy/components/dashboard/application/general/generic/save-docker-provider.tsx +++ b/apps/dokploy/components/dashboard/application/general/generic/save-docker-provider.tsx @@ -47,7 +47,7 @@ export const SaveDockerProvider = ({ applicationId }: Props) => { if (data) { form.reset({ dockerImage: data.dockerImage || "", - password: data.password || "", + password: "*".repeat(data.passwordLength || 0) || "", username: data.username || "", }); } diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index a0fb419f1..08f36f09c 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -101,9 +101,6 @@ export const findApplicationById = async (applicationId: string) => { bitbucket: true, server: true, }, - columns: { - password: false, - }, }); if (!application) { throw new TRPCError({ @@ -111,7 +108,12 @@ export const findApplicationById = async (applicationId: string) => { message: "Application not found", }); } - return application; + const applicationWithoutPassword: Application & { passwordLength?: number } = + application; + applicationWithoutPassword.passwordLength = application.password?.length || 0; // Calculate length + applicationWithoutPassword.password = ""; // Remove password + + return applicationWithoutPassword; }; export const findApplicationByName = async (appName: string) => { From 22440d2108687f900f8f5ef9e21feb9c37092c8e Mon Sep 17 00:00:00 2001 From: Joffrey Date: Thu, 7 Nov 2024 14:09:46 +0100 Subject: [PATCH 4/7] fix(dashboard): remove pass only in api router not service --- .../components/dashboard/application/general/show.tsx | 4 ++-- .../dashboard/application/rebuild-application.tsx | 2 +- apps/dokploy/server/api/routers/application.ts | 10 +++++++++- packages/server/src/services/application.ts | 6 +----- packages/server/src/services/project.ts | 6 +----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/general/show.tsx b/apps/dokploy/components/dashboard/application/general/show.tsx index 277ae1ebb..c20e81fc4 100644 --- a/apps/dokploy/components/dashboard/application/general/show.tsx +++ b/apps/dokploy/components/dashboard/application/general/show.tsx @@ -8,7 +8,7 @@ import { CheckCircle2, Terminal } from "lucide-react"; import React from "react"; import { toast } from "sonner"; import { DockerTerminalModal } from "../../settings/web-server/docker-terminal-modal"; -import { RedbuildApplication } from "../rebuild-application"; +import { RebuildApplication } from "../rebuild-application"; import { StartApplication } from "../start-application"; import { StopApplication } from "../stop-application"; import { DeployApplication } from "./deploy-application"; @@ -60,7 +60,7 @@ export const ShowGeneralApplication = ({ applicationId }: Props) => { Autodeploy {data?.autoDeploy && } - + {data?.applicationStatus === "idle" ? ( ) : ( diff --git a/apps/dokploy/components/dashboard/application/rebuild-application.tsx b/apps/dokploy/components/dashboard/application/rebuild-application.tsx index 0284ab8f6..6c1cf7f85 100644 --- a/apps/dokploy/components/dashboard/application/rebuild-application.tsx +++ b/apps/dokploy/components/dashboard/application/rebuild-application.tsx @@ -18,7 +18,7 @@ interface Props { applicationId: string; } -export const RedbuildApplication = ({ applicationId }: Props) => { +export const RebuildApplication = ({ applicationId }: Props) => { const { data } = api.application.one.useQuery( { applicationId, diff --git a/apps/dokploy/server/api/routers/application.ts b/apps/dokploy/server/api/routers/application.ts index 2f0064713..7934fb8e0 100644 --- a/apps/dokploy/server/api/routers/application.ts +++ b/apps/dokploy/server/api/routers/application.ts @@ -24,6 +24,7 @@ import { cleanQueuesByApplication, myQueue } from "@/server/queues/queueSetup"; import { deploy } from "@/server/utils/deploy"; import { uploadFileSchema } from "@/utils/schema"; import { + type Application, IS_CLOUD, addNewService, checkServiceAccess, @@ -112,7 +113,14 @@ export const applicationRouter = createTRPCRouter({ message: "You are not authorized to access this application", }); } - return application; + const applicationWithoutPassword: Application & { + passwordLength?: number; + } = application; + applicationWithoutPassword.passwordLength = + application.password?.length || 0; // Calculate length + applicationWithoutPassword.password = ""; // Remove password + + return applicationWithoutPassword; }), reload: protectedProcedure diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index 08f36f09c..569fc62d4 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -108,12 +108,8 @@ export const findApplicationById = async (applicationId: string) => { message: "Application not found", }); } - const applicationWithoutPassword: Application & { passwordLength?: number } = - application; - applicationWithoutPassword.passwordLength = application.password?.length || 0; // Calculate length - applicationWithoutPassword.password = ""; // Remove password - return applicationWithoutPassword; + return application; }; export const findApplicationByName = async (appName: string) => { diff --git a/packages/server/src/services/project.ts b/packages/server/src/services/project.ts index b0d9982e3..47e8ac40e 100644 --- a/packages/server/src/services/project.ts +++ b/packages/server/src/services/project.ts @@ -41,11 +41,7 @@ export const findProjectById = async (projectId: string) => { const project = await db.query.projects.findFirst({ where: eq(projects.projectId, projectId), with: { - applications: { - columns: { - password: false, - }, - }, + applications: true, mariadb: true, mongo: true, mysql: true, From 9ab877037a93ee2fafa6501dcbd6707aadc0399f Mon Sep 17 00:00:00 2001 From: Joffrey Date: Fri, 8 Nov 2024 09:14:20 +0100 Subject: [PATCH 5/7] refactor(application): remove password correctly from response --- apps/dokploy/server/api/routers/application.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/dokploy/server/api/routers/application.ts b/apps/dokploy/server/api/routers/application.ts index 7934fb8e0..299b995dd 100644 --- a/apps/dokploy/server/api/routers/application.ts +++ b/apps/dokploy/server/api/routers/application.ts @@ -113,12 +113,14 @@ export const applicationRouter = createTRPCRouter({ message: "You are not authorized to access this application", }); } - const applicationWithoutPassword: Application & { + const { + password, + ...applicationWithoutPassword + }: Application & { passwordLength?: number; } = application; applicationWithoutPassword.passwordLength = - application.password?.length || 0; // Calculate length - applicationWithoutPassword.password = ""; // Remove password + application.password?.length || 0; return applicationWithoutPassword; }), From fdcb014a67adc6f24e241bc29683160d7d40b939 Mon Sep 17 00:00:00 2001 From: Joffrey Date: Tue, 12 Nov 2024 08:52:51 +0100 Subject: [PATCH 6/7] refactor(application router): renaming and retyping --- apps/dokploy/server/api/routers/application.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/dokploy/server/api/routers/application.ts b/apps/dokploy/server/api/routers/application.ts index 299b995dd..958bde585 100644 --- a/apps/dokploy/server/api/routers/application.ts +++ b/apps/dokploy/server/api/routers/application.ts @@ -115,14 +115,12 @@ export const applicationRouter = createTRPCRouter({ } const { password, - ...applicationWithoutPassword - }: Application & { + ...rest + }: Awaited> & { passwordLength?: number; } = application; - applicationWithoutPassword.passwordLength = - application.password?.length || 0; - - return applicationWithoutPassword; + rest.passwordLength = application.password?.length || 0; + return rest; }), reload: protectedProcedure From 92f7bfb85cd8dd474e8ee4bdb9b692b02feb4453 Mon Sep 17 00:00:00 2001 From: Joffrey Date: Wed, 13 Nov 2024 10:55:29 +0100 Subject: [PATCH 7/7] refactor(dashboard): remove unused project query and refacto project type definition --- .../dashboard/settings/users/add-permissions.tsx | 2 -- apps/dokploy/pages/dashboard/project/[projectId].tsx | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/dokploy/components/dashboard/settings/users/add-permissions.tsx b/apps/dokploy/components/dashboard/settings/users/add-permissions.tsx index 3684c814b..c2f7022e4 100644 --- a/apps/dokploy/components/dashboard/settings/users/add-permissions.tsx +++ b/apps/dokploy/components/dashboard/settings/users/add-permissions.tsx @@ -50,8 +50,6 @@ interface Props { } export const AddUserPermissions = ({ userId }: Props) => { - const { data: projects } = api.project.all.useQuery(); - const { data, refetch } = api.user.byUserId.useQuery( { userId, diff --git a/apps/dokploy/pages/dashboard/project/[projectId].tsx b/apps/dokploy/pages/dashboard/project/[projectId].tsx index afbd25906..8c1785c77 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId].tsx @@ -59,7 +59,17 @@ export type Services = { status?: "idle" | "running" | "done" | "error"; }; -type Project = Awaited>; +type ChangeFields = Omit & R; + +type Project = ChangeFields< + Awaited>, + { + applications: Omit< + Awaited>["applications"][number], + "password" + >[]; + } +>; export const extractServices = (data: Project | undefined) => { const applications: Services[] =