diff --git a/apps/dokploy/__test__/wss/authorize.test.ts b/apps/dokploy/__test__/wss/authorize.test.ts index aafcccec4..1c073c033 100644 --- a/apps/dokploy/__test__/wss/authorize.test.ts +++ b/apps/dokploy/__test__/wss/authorize.test.ts @@ -15,8 +15,6 @@ vi.mock("@dokploy/server", () => ({ getAccessibleServerIds: mockGetAccessibleServerIds, })); -vi.mock("@dokploy/server/db", () => ({ db: {} })); - import { canAccessDockerOverWss, canAccessTerminalOverWss, diff --git a/apps/dokploy/server/wss/authorize.ts b/apps/dokploy/server/wss/authorize.ts index 9cf922b12..f03cda7c0 100644 --- a/apps/dokploy/server/wss/authorize.ts +++ b/apps/dokploy/server/wss/authorize.ts @@ -1,5 +1,4 @@ import { getAccessibleServerIds } from "@dokploy/server"; -import { db } from "@dokploy/server/db"; import { checkServiceAccess, findMemberByUserId, @@ -60,50 +59,6 @@ export const canAccessDockerOverWss = async ( return true; }; -// Returns the appName of the service with this id, whichever service type it -// is. Service-scoped sockets use it to check that the requested container -// belongs to the service the caller was authorized for. -export const findServiceAppName = async ( - serviceId: string, -): Promise => { - const columns = { appName: true } as const; - const results = await Promise.all([ - db.query.applications.findFirst({ - columns, - where: (t, { eq }) => eq(t.applicationId, serviceId), - }), - db.query.compose.findFirst({ - columns, - where: (t, { eq }) => eq(t.composeId, serviceId), - }), - db.query.postgres.findFirst({ - columns, - where: (t, { eq }) => eq(t.postgresId, serviceId), - }), - db.query.mysql.findFirst({ - columns, - where: (t, { eq }) => eq(t.mysqlId, serviceId), - }), - db.query.mariadb.findFirst({ - columns, - where: (t, { eq }) => eq(t.mariadbId, serviceId), - }), - db.query.mongo.findFirst({ - columns, - where: (t, { eq }) => eq(t.mongoId, serviceId), - }), - db.query.redis.findFirst({ - columns, - where: (t, { eq }) => eq(t.redisId, serviceId), - }), - db.query.libsql.findFirst({ - columns, - where: (t, { eq }) => eq(t.libsqlId, serviceId), - }), - ]); - return results.find(Boolean)?.appName ?? null; -}; - // Whether a stats request for `appName` targets the service named // `serviceAppName`. Applications and databases run as one swarm service named // after the app; stack tasks are namespaced "_". Compose diff --git a/apps/dokploy/server/wss/container-ownership.ts b/apps/dokploy/server/wss/container-ownership.ts index 0c536a5e3..976fdb394 100644 --- a/apps/dokploy/server/wss/container-ownership.ts +++ b/apps/dokploy/server/wss/container-ownership.ts @@ -33,7 +33,7 @@ const SERVICE_TABLES = [ { table: libsql, id: libsql.libsqlId }, ]; -const findServiceAppName = async (serviceId: string) => { +export const findServiceAppName = async (serviceId: string) => { for (const { table, id } of SERVICE_TABLES) { const [row] = await db .select({ appName: table.appName }) diff --git a/apps/dokploy/server/wss/docker-stats.ts b/apps/dokploy/server/wss/docker-stats.ts index 6e9f7265b..e9800b8b2 100644 --- a/apps/dokploy/server/wss/docker-stats.ts +++ b/apps/dokploy/server/wss/docker-stats.ts @@ -10,11 +10,8 @@ import { } from "@dokploy/server"; import { quote } from "shell-quote"; import { WebSocketServer } from "ws"; -import { - canAccessDockerOverWss, - findServiceAppName, - isServiceContainerName, -} from "./authorize"; +import { canAccessDockerOverWss, isServiceContainerName } from "./authorize"; +import { findServiceAppName } from "./container-ownership"; type AppType = "application" | "stack" | "docker-compose";