mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-17 09:25:20 +00:00
fix(deployment): resolve schedule to its service before permission check in allByType (#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.
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
findAllDeploymentsByServerId,
|
findAllDeploymentsByServerId,
|
||||||
findAllDeploymentsCentralized,
|
findAllDeploymentsCentralized,
|
||||||
findDeploymentById,
|
findDeploymentById,
|
||||||
|
findScheduleById,
|
||||||
IS_CLOUD,
|
IS_CLOUD,
|
||||||
removeDeployment,
|
removeDeployment,
|
||||||
resolveServicePath,
|
resolveServicePath,
|
||||||
@@ -126,9 +127,27 @@ export const deploymentRouter = createTRPCRouter({
|
|||||||
allByType: protectedProcedure
|
allByType: protectedProcedure
|
||||||
.input(apiFindAllByType)
|
.input(apiFindAllByType)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
await checkServicePermissionAndAccess(ctx, input.id, {
|
if (input.type === "schedule") {
|
||||||
deployment: ["read"],
|
const schedule = await findScheduleById(input.id);
|
||||||
});
|
const serviceId = schedule.applicationId || schedule.composeId;
|
||||||
|
if (serviceId) {
|
||||||
|
await checkServicePermissionAndAccess(ctx, serviceId, {
|
||||||
|
deployment: ["read"],
|
||||||
|
});
|
||||||
|
} else if (schedule.serverId) {
|
||||||
|
const targetServer = await findServerById(schedule.serverId);
|
||||||
|
if (targetServer.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "UNAUTHORIZED",
|
||||||
|
message: "You don't have access to this schedule.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await checkServicePermissionAndAccess(ctx, input.id, {
|
||||||
|
deployment: ["read"],
|
||||||
|
});
|
||||||
|
}
|
||||||
const deploymentsList = await db.query.deployments.findMany({
|
const deploymentsList = await db.query.deployments.findMany({
|
||||||
where: eq(deployments[`${input.type}Id`], input.id),
|
where: eq(deployments[`${input.type}Id`], input.id),
|
||||||
orderBy: desc(deployments.createdAt),
|
orderBy: desc(deployments.createdAt),
|
||||||
|
|||||||
Reference in New Issue
Block a user