diff --git a/backend/src/controllers/v2/environmentController.ts b/backend/src/controllers/v2/environmentController.ts index 72365d7da..b111d4566 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 @@ -369,13 +373,38 @@ 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 }, { 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,