diff --git a/apps/dokploy/server/api/routers/ai.ts b/apps/dokploy/server/api/routers/ai.ts index c64a7705..e023f936 100644 --- a/apps/dokploy/server/api/routers/ai.ts +++ b/apps/dokploy/server/api/routers/ai.ts @@ -163,7 +163,7 @@ export const aiRouter = createTRPCRouter({ deploy: protectedProcedure .input(deploySuggestionSchema) .mutation(async ({ ctx, input }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.session.activeOrganizationId, input.projectId, @@ -216,7 +216,7 @@ export const aiRouter = createTRPCRouter({ } } - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewService( ctx.session.activeOrganizationId, ctx.user.ownerId, diff --git a/apps/dokploy/server/api/routers/application.ts b/apps/dokploy/server/api/routers/application.ts index ca7939ac..0899903f 100644 --- a/apps/dokploy/server/api/routers/application.ts +++ b/apps/dokploy/server/api/routers/application.ts @@ -62,7 +62,7 @@ export const applicationRouter = createTRPCRouter({ .input(apiCreateApplication) .mutation(async ({ input, ctx }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.projectId, @@ -87,7 +87,7 @@ export const applicationRouter = createTRPCRouter({ } const newApplication = await createApplication(input); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewService( ctx.user.id, newApplication.applicationId, @@ -109,7 +109,7 @@ export const applicationRouter = createTRPCRouter({ one: protectedProcedure .input(apiFindOneApplication) .query(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.applicationId, @@ -168,7 +168,7 @@ export const applicationRouter = createTRPCRouter({ delete: protectedProcedure .input(apiFindOneApplication) .mutation(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.applicationId, diff --git a/apps/dokploy/server/api/routers/compose.ts b/apps/dokploy/server/api/routers/compose.ts index c4f9b317..48c2bfa7 100644 --- a/apps/dokploy/server/api/routers/compose.ts +++ b/apps/dokploy/server/api/routers/compose.ts @@ -62,7 +62,7 @@ export const composeRouter = createTRPCRouter({ .input(apiCreateCompose) .mutation(async ({ ctx, input }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.projectId, @@ -86,7 +86,7 @@ export const composeRouter = createTRPCRouter({ } const newService = await createCompose(input); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewService( ctx.user.id, newService.composeId, @@ -103,7 +103,7 @@ export const composeRouter = createTRPCRouter({ one: protectedProcedure .input(apiFindCompose) .query(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.composeId, @@ -137,7 +137,7 @@ export const composeRouter = createTRPCRouter({ delete: protectedProcedure .input(apiDeleteCompose) .mutation(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.composeId, @@ -408,7 +408,7 @@ export const composeRouter = createTRPCRouter({ }), ) .mutation(async ({ ctx, input }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.projectId, @@ -455,7 +455,7 @@ export const composeRouter = createTRPCRouter({ isolatedDeployment: true, }); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewService( ctx.user.id, compose.composeId, diff --git a/apps/dokploy/server/api/routers/mariadb.ts b/apps/dokploy/server/api/routers/mariadb.ts index 241274f1..dd3b1bf7 100644 --- a/apps/dokploy/server/api/routers/mariadb.ts +++ b/apps/dokploy/server/api/routers/mariadb.ts @@ -41,7 +41,7 @@ export const mariadbRouter = createTRPCRouter({ .input(apiCreateMariaDB) .mutation(async ({ input, ctx }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.projectId, @@ -65,7 +65,7 @@ export const mariadbRouter = createTRPCRouter({ }); } const newMariadb = await createMariadb(input); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewService( ctx.user.id, newMariadb.mariadbId, @@ -92,7 +92,7 @@ export const mariadbRouter = createTRPCRouter({ one: protectedProcedure .input(apiFindOneMariaDB) .query(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.mariadbId, @@ -219,7 +219,7 @@ export const mariadbRouter = createTRPCRouter({ remove: protectedProcedure .input(apiFindOneMariaDB) .mutation(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.mariadbId, diff --git a/apps/dokploy/server/api/routers/mongo.ts b/apps/dokploy/server/api/routers/mongo.ts index eb51522a..4d815c0a 100644 --- a/apps/dokploy/server/api/routers/mongo.ts +++ b/apps/dokploy/server/api/routers/mongo.ts @@ -41,7 +41,7 @@ export const mongoRouter = createTRPCRouter({ .input(apiCreateMongo) .mutation(async ({ input, ctx }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.projectId, @@ -65,7 +65,7 @@ export const mongoRouter = createTRPCRouter({ }); } const newMongo = await createMongo(input); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewService( ctx.user.id, newMongo.mongoId, @@ -96,7 +96,7 @@ export const mongoRouter = createTRPCRouter({ one: protectedProcedure .input(apiFindOneMongo) .query(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.mongoId, @@ -261,7 +261,7 @@ export const mongoRouter = createTRPCRouter({ remove: protectedProcedure .input(apiFindOneMongo) .mutation(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.mongoId, diff --git a/apps/dokploy/server/api/routers/mysql.ts b/apps/dokploy/server/api/routers/mysql.ts index 91087601..ee1b80dc 100644 --- a/apps/dokploy/server/api/routers/mysql.ts +++ b/apps/dokploy/server/api/routers/mysql.ts @@ -44,7 +44,7 @@ export const mysqlRouter = createTRPCRouter({ .input(apiCreateMySql) .mutation(async ({ input, ctx }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.projectId, @@ -69,7 +69,7 @@ export const mysqlRouter = createTRPCRouter({ } const newMysql = await createMysql(input); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewService( ctx.user.id, newMysql.mysqlId, @@ -100,7 +100,7 @@ export const mysqlRouter = createTRPCRouter({ one: protectedProcedure .input(apiFindOneMySql) .query(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.mysqlId, @@ -260,7 +260,7 @@ export const mysqlRouter = createTRPCRouter({ remove: protectedProcedure .input(apiFindOneMySql) .mutation(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.mysqlId, diff --git a/apps/dokploy/server/api/routers/organization.ts b/apps/dokploy/server/api/routers/organization.ts index 25498143..55981e59 100644 --- a/apps/dokploy/server/api/routers/organization.ts +++ b/apps/dokploy/server/api/routers/organization.ts @@ -15,7 +15,7 @@ export const organizationRouter = createTRPCRouter({ }), ) .mutation(async ({ ctx, input }) => { - if (ctx.user.rol !== "owner" && !IS_CLOUD) { + if (ctx.user.role !== "owner" && !IS_CLOUD) { throw new TRPCError({ code: "FORBIDDEN", message: "Only the organization owner can create an organization", @@ -86,7 +86,7 @@ export const organizationRouter = createTRPCRouter({ }), ) .mutation(async ({ ctx, input }) => { - if (ctx.user.rol !== "owner" && !IS_CLOUD) { + if (ctx.user.role !== "owner" && !IS_CLOUD) { throw new TRPCError({ code: "FORBIDDEN", message: "Only the organization owner can update it", @@ -109,7 +109,7 @@ export const organizationRouter = createTRPCRouter({ }), ) .mutation(async ({ ctx, input }) => { - if (ctx.user.rol !== "owner" && !IS_CLOUD) { + if (ctx.user.role !== "owner" && !IS_CLOUD) { throw new TRPCError({ code: "FORBIDDEN", message: "Only the organization owner can delete it", diff --git a/apps/dokploy/server/api/routers/postgres.ts b/apps/dokploy/server/api/routers/postgres.ts index 28d5558a..9eef11f8 100644 --- a/apps/dokploy/server/api/routers/postgres.ts +++ b/apps/dokploy/server/api/routers/postgres.ts @@ -41,7 +41,7 @@ export const postgresRouter = createTRPCRouter({ .input(apiCreatePostgres) .mutation(async ({ input, ctx }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.projectId, @@ -65,7 +65,7 @@ export const postgresRouter = createTRPCRouter({ }); } const newPostgres = await createPostgres(input); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewService( ctx.user.id, newPostgres.postgresId, @@ -96,7 +96,7 @@ export const postgresRouter = createTRPCRouter({ one: protectedProcedure .input(apiFindOnePostgres) .query(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.postgresId, @@ -244,7 +244,7 @@ export const postgresRouter = createTRPCRouter({ remove: protectedProcedure .input(apiFindOnePostgres) .mutation(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.postgresId, diff --git a/apps/dokploy/server/api/routers/project.ts b/apps/dokploy/server/api/routers/project.ts index d686479b..05875450 100644 --- a/apps/dokploy/server/api/routers/project.ts +++ b/apps/dokploy/server/api/routers/project.ts @@ -57,7 +57,7 @@ export const projectRouter = createTRPCRouter({ .input(apiCreateProject) .mutation(async ({ ctx, input }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkProjectAccess( ctx.user.id, "create", @@ -78,7 +78,7 @@ export const projectRouter = createTRPCRouter({ input, ctx.session.activeOrganizationId, ); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewProject( ctx.user.id, project.projectId, @@ -99,7 +99,7 @@ export const projectRouter = createTRPCRouter({ one: protectedProcedure .input(apiFindOneProject) .query(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { const { accessedServices } = await findMemberById( ctx.user.id, ctx.session.activeOrganizationId, @@ -118,15 +118,15 @@ export const projectRouter = createTRPCRouter({ eq(projects.organizationId, ctx.session.activeOrganizationId), ), with: { - compose: { - where: buildServiceFilter(compose.composeId, accessedServices), - }, applications: { where: buildServiceFilter( applications.applicationId, accessedServices, ), }, + compose: { + where: buildServiceFilter(compose.composeId, accessedServices), + }, mariadb: { where: buildServiceFilter(mariadb.mariadbId, accessedServices), }, @@ -164,8 +164,7 @@ export const projectRouter = createTRPCRouter({ return project; }), all: protectedProcedure.query(async ({ ctx }) => { - // console.log(ctx.user); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { const { accessedProjects, accessedServices } = await findMemberById( ctx.user.id, ctx.session.activeOrganizationId, @@ -175,7 +174,7 @@ export const projectRouter = createTRPCRouter({ return []; } - const query = await db.query.projects.findMany({ + return await db.query.projects.findMany({ where: and( sql`${projects.projectId} IN (${sql.join( accessedProjects.map((projectId) => sql`${projectId}`), @@ -213,8 +212,6 @@ export const projectRouter = createTRPCRouter({ }, orderBy: desc(projects.createdAt), }); - - return query; } return await db.query.projects.findMany({ @@ -244,7 +241,7 @@ export const projectRouter = createTRPCRouter({ .input(apiRemoveProject) .mutation(async ({ input, ctx }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkProjectAccess( ctx.user.id, "delete", @@ -316,7 +313,7 @@ export const projectRouter = createTRPCRouter({ ) .mutation(async ({ ctx, input }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkProjectAccess( ctx.user.id, "create", @@ -581,7 +578,7 @@ export const projectRouter = createTRPCRouter({ } } - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewProject( ctx.user.id, newProject.projectId, @@ -604,10 +601,10 @@ function buildServiceFilter( fieldName: AnyPgColumn, accessedServices: string[], ) { - return accessedServices.length > 0 - ? sql`${fieldName} IN (${sql.join( + return accessedServices.length === 0 + ? sql`false` + : sql`${fieldName} IN (${sql.join( accessedServices.map((serviceId) => sql`${serviceId}`), sql`, `, - )})` - : sql`1 = 0`; + )})`; } diff --git a/apps/dokploy/server/api/routers/redis.ts b/apps/dokploy/server/api/routers/redis.ts index 1de13fcb..0aafac8e 100644 --- a/apps/dokploy/server/api/routers/redis.ts +++ b/apps/dokploy/server/api/routers/redis.ts @@ -41,7 +41,7 @@ export const redisRouter = createTRPCRouter({ .input(apiCreateRedis) .mutation(async ({ input, ctx }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.projectId, @@ -65,7 +65,7 @@ export const redisRouter = createTRPCRouter({ }); } const newRedis = await createRedis(input); - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await addNewService( ctx.user.id, newRedis.redisId, @@ -89,7 +89,7 @@ export const redisRouter = createTRPCRouter({ one: protectedProcedure .input(apiFindOneRedis) .query(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.redisId, @@ -251,7 +251,7 @@ export const redisRouter = createTRPCRouter({ remove: protectedProcedure .input(apiFindOneRedis) .mutation(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { await checkServiceAccess( ctx.user.id, input.redisId, diff --git a/apps/dokploy/server/api/routers/settings.ts b/apps/dokploy/server/api/routers/settings.ts index 5ca4c106..a4e667f1 100644 --- a/apps/dokploy/server/api/routers/settings.ts +++ b/apps/dokploy/server/api/routers/settings.ts @@ -407,7 +407,7 @@ export const settingsRouter = createTRPCRouter({ .input(apiServerSchema) .query(async ({ ctx, input }) => { try { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { const canAccess = await canAccessToTraefikFiles( ctx.user.id, ctx.session.activeOrganizationId, @@ -428,7 +428,7 @@ export const settingsRouter = createTRPCRouter({ updateTraefikFile: protectedProcedure .input(apiModifyTraefikConfig) .mutation(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { const canAccess = await canAccessToTraefikFiles( ctx.user.id, ctx.session.activeOrganizationId, @@ -449,7 +449,7 @@ export const settingsRouter = createTRPCRouter({ readTraefikFile: protectedProcedure .input(apiReadTraefikConfig) .query(async ({ input, ctx }) => { - if (ctx.user.rol === "member") { + if (ctx.user.role === "member") { const canAccess = await canAccessToTraefikFiles( ctx.user.id, ctx.session.activeOrganizationId, diff --git a/apps/dokploy/server/api/trpc.ts b/apps/dokploy/server/api/trpc.ts index 4c88eb22..1b22ca34 100644 --- a/apps/dokploy/server/api/trpc.ts +++ b/apps/dokploy/server/api/trpc.ts @@ -30,7 +30,7 @@ import { ZodError } from "zod"; */ interface CreateContextOptions { - user: (User & { rol: "member" | "admin" | "owner"; ownerId: string }) | null; + user: (User & { role: "member" | "admin" | "owner"; ownerId: string }) | null; session: (Session & { activeOrganizationId: string }) | null; req: CreateNextContextOptions["req"]; res: CreateNextContextOptions["res"]; @@ -83,7 +83,7 @@ export const createTRPCContext = async (opts: CreateNextContextOptions) => { ? { ...user, email: user.email, - rol: user.role as "owner" | "member" | "admin", + role: user.role as "owner" | "member" | "admin", id: user.id, ownerId: user.ownerId, } @@ -180,7 +180,7 @@ export const uploadProcedure = async (opts: any) => { }; export const cliProcedure = t.procedure.use(({ ctx, next }) => { - if (!ctx.session || !ctx.user || ctx.user.rol !== "owner") { + if (!ctx.session || !ctx.user || ctx.user.role !== "owner") { throw new TRPCError({ code: "UNAUTHORIZED" }); } return next({ @@ -194,7 +194,7 @@ export const cliProcedure = t.procedure.use(({ ctx, next }) => { }); export const adminProcedure = t.procedure.use(({ ctx, next }) => { - if (!ctx.session || !ctx.user || ctx.user.rol !== "owner") { + if (!ctx.session || !ctx.user || ctx.user.role !== "owner") { throw new TRPCError({ code: "UNAUTHORIZED" }); } return next({