From 6e992858aa754ed51f143b5998b0bf83422f30da Mon Sep 17 00:00:00 2001 From: nafees nazik Date: Wed, 27 Sep 2023 15:12:32 +0530 Subject: [PATCH 1/2] fix: add renamed fields to other models --- .../controllers/v2/environmentController.ts | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/backend/src/controllers/v2/environmentController.ts b/backend/src/controllers/v2/environmentController.ts index 72365d7da..d89e9b9b6 100644 --- a/backend/src/controllers/v2/environmentController.ts +++ b/backend/src/controllers/v2/environmentController.ts @@ -1,6 +1,7 @@ import { Request, Response } from "express"; import { Types } from "mongoose"; import { + Folder, Integration, Membership, Secret, @@ -21,9 +22,12 @@ import { getUserProjectPermissions } from "../../ee/services/ProjectRoleService"; import { ForbiddenError } from "@casl/ability"; +import { SecretImport } from "../../models"; +import { ServiceAccountWorkspacePermission } from "../../models"; +import { Webhook } from "../../models"; /** - * Create new workspace environment named [environmentName] + * Create new workspace environment named [environmentName] * with slug [environmentSlug] under workspace with id * @param req * @param res @@ -376,6 +380,27 @@ export const renameWorkspaceEnvironment = async (req: Request, res: Response) => { workspace: workspaceId, environment: oldEnvironmentSlug }, { environment: environmentSlug } ); + + await Folder.updateMany( + { workspace: workspaceId, environment: oldEnvironmentSlug }, + { environment: environmentSlug } + ); + + await SecretImport.updateMany( + { workspace: workspaceId, environment: oldEnvironmentSlug }, + { environment: environmentSlug } + ); + + await ServiceAccountWorkspacePermission.updateMany( + { workspace: workspaceId, environment: oldEnvironmentSlug }, + { environment: environmentSlug } + ); + + await Webhook.updateMany( + { workspace: workspaceId, environment: oldEnvironmentSlug }, + { environment: environmentSlug } + ); + await Membership.updateMany( { workspace: workspaceId, From 77ec17ccd409d58ba94bc1a86a24418b0853e657 Mon Sep 17 00:00:00 2001 From: nafees nazik Date: Wed, 27 Sep 2023 17:01:02 +0530 Subject: [PATCH 2/2] fix: update many query --- backend/src/controllers/v2/environmentController.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/controllers/v2/environmentController.ts b/backend/src/controllers/v2/environmentController.ts index d89e9b9b6..b111d4566 100644 --- a/backend/src/controllers/v2/environmentController.ts +++ b/backend/src/controllers/v2/environmentController.ts @@ -373,8 +373,12 @@ export const renameWorkspaceEnvironment = async (req: Request, res: Response) => { environment: environmentSlug } ); await ServiceTokenData.updateMany( - { workspace: workspaceId, environment: oldEnvironmentSlug }, - { environment: environmentSlug } + { + workspace: workspaceId, + "scopes.environment": oldEnvironmentSlug + }, + { $set: { "scopes.$[element].environment": environmentSlug } }, + { arrayFilters: [{ "element.environment": oldEnvironmentSlug }] } ); await Integration.updateMany( { workspace: workspaceId, environment: oldEnvironmentSlug },