From 8ed04d0b750174f7d815b24469f075ba702da8fb Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Wed, 2 Oct 2024 20:09:31 +0400 Subject: [PATCH] fix: made all update fields optional --- .../src/server/routes/v1/integration-router.ts | 6 +++--- .../services/integration/integration-service.ts | 17 +++++++++++------ .../services/integration/integration-types.ts | 8 ++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/backend/src/server/routes/v1/integration-router.ts b/backend/src/server/routes/v1/integration-router.ts index 202b5cf8c5..2a09da5262 100644 --- a/backend/src/server/routes/v1/integration-router.ts +++ b/backend/src/server/routes/v1/integration-router.ts @@ -131,9 +131,9 @@ export const registerIntegrationRouter = async (server: FastifyZodProvider) => { .default("/") .transform(removeTrailingSlash) .describe(INTEGRATION.UPDATE.secretPath), - targetEnvironment: z.string().trim().describe(INTEGRATION.UPDATE.targetEnvironment), - owner: z.string().trim().describe(INTEGRATION.UPDATE.owner), - environment: z.string().trim().describe(INTEGRATION.UPDATE.environment), + targetEnvironment: z.string().trim().optional().describe(INTEGRATION.UPDATE.targetEnvironment), + owner: z.string().trim().optional().describe(INTEGRATION.UPDATE.owner), + environment: z.string().trim().optional().describe(INTEGRATION.UPDATE.environment), metadata: IntegrationMetadataSchema.optional() }), response: { diff --git a/backend/src/services/integration/integration-service.ts b/backend/src/services/integration/integration-service.ts index 5e77f43493..db49973222 100644 --- a/backend/src/services/integration/integration-service.ts +++ b/backend/src/services/integration/integration-service.ts @@ -150,12 +150,17 @@ export const integrationServiceFactory = ({ ); ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.Integrations); - ForbiddenError.from(permission).throwUnlessCan( - ProjectPermissionActions.Read, - subject(ProjectPermissionSub.Secrets, { environment, secretPath }) - ); + const newEnvironment = environment || integration.environment.slug; + const newSecretPath = secretPath || integration.secretPath; - const folder = await folderDAL.findBySecretPath(integration.projectId, environment, secretPath); + if (environment || secretPath) { + ForbiddenError.from(permission).throwUnlessCan( + ProjectPermissionActions.Read, + subject(ProjectPermissionSub.Secrets, { environment: newEnvironment, secretPath: newSecretPath }) + ); + } + + const folder = await folderDAL.findBySecretPath(integration.projectId, newEnvironment, newSecretPath); if (!folder) throw new NotFoundError({ message: "Folder path not found" }); const updatedIntegration = await integrationDAL.updateById(id, { @@ -174,7 +179,7 @@ export const integrationServiceFactory = ({ await secretQueueService.syncIntegrations({ environment: folder.environment.slug, - secretPath, + secretPath: newSecretPath, projectId: folder.projectId }); diff --git a/backend/src/services/integration/integration-types.ts b/backend/src/services/integration/integration-types.ts index 5c76159dec..a27c4f6acb 100644 --- a/backend/src/services/integration/integration-types.ts +++ b/backend/src/services/integration/integration-types.ts @@ -48,10 +48,10 @@ export type TUpdateIntegrationDTO = { app?: string; appId?: string; isActive?: boolean; - secretPath: string; - targetEnvironment: string; - owner: string; - environment: string; + secretPath?: string; + targetEnvironment?: string; + owner?: string; + environment?: string; metadata?: { secretPrefix?: string; secretSuffix?: string;