From f3dc190ab2efb3228913e6454446ae64d6d239ed Mon Sep 17 00:00:00 2001 From: Charissa Miller <48832936+clemiller@users.noreply.github.com> Date: Tue, 15 Aug 2023 12:14:00 -0400 Subject: [PATCH] Fix lastUpdatedBy query to retrieve recent relationship activity for more than one user (#273) * update gitignore * update formatting * fix bug in lastUpdatedBy query --- .gitignore | 1 + app/lib/request-parameter-helper.js | 12 ++++++------ app/services/attack-objects-service.js | 5 +++-- app/services/relationships-service.js | 9 +++------ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 904589e2..aa128085 100644 --- a/.gitignore +++ b/.gitignore @@ -147,3 +147,4 @@ Temporary Items # Directory holding files that are for local use only /local-only +/certs diff --git a/app/lib/request-parameter-helper.js b/app/lib/request-parameter-helper.js index 6291decd..99bd9905 100644 --- a/app/lib/request-parameter-helper.js +++ b/app/lib/request-parameter-helper.js @@ -1,11 +1,11 @@ const lastUpdatedByQueryHelper = function (lastUpdatedByOption) { - if (Array.isArray(lastUpdatedByOption)) { - return { $in: lastUpdatedByOption }; - } else { - return lastUpdatedByOption; - } + if (Array.isArray(lastUpdatedByOption)) { + return { $in: lastUpdatedByOption }; + } else { + return lastUpdatedByOption; + } }; module.exports = { - lastUpdatedByQueryHelper, + lastUpdatedByQueryHelper, }; diff --git a/app/services/attack-objects-service.js b/app/services/attack-objects-service.js index 0c8ece95..90e203c2 100644 --- a/app/services/attack-objects-service.js +++ b/app/services/attack-objects-service.js @@ -6,7 +6,8 @@ const AttackObject = require('../models/attack-object-model'); const Relationship = require('../models/relationship-model'); const identitiesService = require('./identities-service'); const systemConfigurationService = require('./system-configuration-service'); -const {lastUpdatedByQueryHelper} = require('../lib/request-parameter-helper'); + +const { lastUpdatedByQueryHelper } = require('../lib/request-parameter-helper'); const regexValidator = require('../lib/regex'); @@ -52,7 +53,7 @@ exports.retrieveAll = async function(options) { } if (typeof options.lastUpdatedBy !== 'undefined') { - query['workspace.workflow.created_by_user_account'] = lastUpdatedByQueryHelper(options.lastUpdatedBy); + query['workspace.workflow.created_by_user_account'] = lastUpdatedByQueryHelper(options.lastUpdatedBy); } // Build the aggregation diff --git a/app/services/relationships-service.js b/app/services/relationships-service.js index 70a6812a..fbcfe70e 100644 --- a/app/services/relationships-service.js +++ b/app/services/relationships-service.js @@ -7,6 +7,8 @@ const identitiesService = require('./identities-service'); const attackObjectsService = require('./attack-objects-service'); const config = require('../config/config'); +const { lastUpdatedByQueryHelper } = require('../lib/request-parameter-helper'); + const errors = { missingParameter: 'Missing required parameter', badlyFormattedParameter: 'Badly formatted parameter', @@ -58,12 +60,7 @@ exports.retrieveAll = async function(options) { query['stix.relationship_type'] = options.relationshipType; } if (typeof options.lastUpdatedBy !== 'undefined') { - if (Array.isArray(options.attackId)) { - query['workspace.workflow.created_by_user_account'] = { $in: options.lastUpdatedBy }; - } - else { - query['workspace.workflow.created_by_user_account'] = options.lastUpdatedBy; - } + query['workspace.workflow.created_by_user_account'] = lastUpdatedByQueryHelper(options.lastUpdatedBy); } // Build the aggregation