diff --git a/backend/src/controllers/v2/secretsController.ts b/backend/src/controllers/v2/secretsController.ts index 5412549b32..c42dcb28be 100644 --- a/backend/src/controllers/v2/secretsController.ts +++ b/backend/src/controllers/v2/secretsController.ts @@ -43,17 +43,6 @@ export const batchSecrets = async (req: Request, res: Response) => { requests: BatchSecretRequest[]; }= req.body; - // construct object containing all secrets - const listedSecretsObj: { - [key: string]: { - version: number; - type: string; - } - } = req.secrets.reduce((obj: any, secret: ISecret) => ({ - ...obj, - [secret._id.toString()]: secret - }), {}); - const createSecrets: BatchSecret[] = []; const updateSecrets: BatchSecret[] = []; const deleteSecrets: Types.ObjectId[] = []; @@ -123,7 +112,20 @@ export const batchSecrets = async (req: Request, res: Response) => { // handle update secrets let updatedSecrets: ISecret[] = []; - if (updateSecrets.length > 0) { + if (updateSecrets.length > 0 && req.secrets) { + // construct object containing all secrets + let listedSecretsObj: { + [key: string]: { + version: number; + type: string; + } + } = {}; + + listedSecretsObj = req.secrets.reduce((obj: any, secret: ISecret) => ({ + ...obj, + [secret._id.toString()]: secret + }), {}); + const updateOperations = updateSecrets.map((u) => ({ updateOne: { filter: { _id: new Types.ObjectId(u._id) }, @@ -168,6 +170,14 @@ export const batchSecrets = async (req: Request, res: Response) => { } }); + const updateAction = await EELogService.createAction({ + name: ACTION_UPDATE_SECRETS, + userId: req.user._id, + workspaceId: new Types.ObjectId(workspaceId), + secretIds: updatedSecrets.map((u) => u._id) + }) as IAction; + actions.push(updateAction); + if (postHogClient) { postHogClient.capture({ event: 'secrets modified', @@ -218,7 +228,7 @@ export const batchSecrets = async (req: Request, res: Response) => { } } - if (actions.length > 1) { + if (actions.length > 0) { // (EE) create (audit) log await EELogService.createLog({ userId: req.user._id.toString(), diff --git a/backend/src/routes/v2/secrets.ts b/backend/src/routes/v2/secrets.ts index a60416ef50..51629b32d4 100644 --- a/backend/src/routes/v2/secrets.ts +++ b/backend/src/routes/v2/secrets.ts @@ -15,7 +15,6 @@ import { SECRET_PERSONAL, SECRET_SHARED } from '../../variables'; - import { BatchSecretRequest } from '../../types/secret';