Skip to content

Commit 8a0e442

Browse files
authored
fix(deployment): resolve schedule to its service before permission check in allByType (Dokploy#4733)
Members with access to a schedule's application/compose got a 401 on deployment.allByType because it passed the scheduleId straight into checkServicePermissionAndAccess, which expects a service id.
1 parent 3e11c0a commit 8a0e442

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

‎apps/dokploy/server/api/routers/deployment.ts‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
findAllDeploymentsByServerId,
77
findAllDeploymentsCentralized,
88
findDeploymentById,
9+
findScheduleById,
910
IS_CLOUD,
1011
removeDeployment,
1112
resolveServicePath,
@@ -126,9 +127,27 @@ export const deploymentRouter = createTRPCRouter({
126127
allByType: protectedProcedure
127128
.input(apiFindAllByType)
128129
.query(async ({ input, ctx }) => {
129-
await checkServicePermissionAndAccess(ctx, input.id, {
130-
deployment: ["read"],
131-
});
130+
if (input.type === "schedule") {
131+
const schedule = await findScheduleById(input.id);
132+
const serviceId = schedule.applicationId || schedule.composeId;
133+
if (serviceId) {
134+
await checkServicePermissionAndAccess(ctx, serviceId, {
135+
deployment: ["read"],
136+
});
137+
} else if (schedule.serverId) {
138+
const targetServer = await findServerById(schedule.serverId);
139+
if (targetServer.organizationId !== ctx.session.activeOrganizationId) {
140+
throw new TRPCError({
141+
code: "UNAUTHORIZED",
142+
message: "You don't have access to this schedule.",
143+
});
144+
}
145+
}
146+
} else {
147+
await checkServicePermissionAndAccess(ctx, input.id, {
148+
deployment: ["read"],
149+
});
150+
}
132151
const deploymentsList = await db.query.deployments.findMany({
133152
where: eq(deployments[`${input.type}Id`], input.id),
134153
orderBy: desc(deployments.createdAt),

0 commit comments

Comments
 (0)