Skip to content

Commit

Permalink
Fix lastUpdatedBy query to retrieve recent relationship activity for …
Browse files Browse the repository at this point in the history
…more than one user (#273)

* update gitignore

* update formatting

* fix bug in lastUpdatedBy query
  • Loading branch information
clemiller authored Aug 15, 2023
1 parent 25f010e commit f3dc190
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,4 @@ Temporary Items

# Directory holding files that are for local use only
/local-only
/certs
12 changes: 6 additions & 6 deletions app/lib/request-parameter-helper.js
Original file line number Diff line number Diff line change
@@ -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,
};
5 changes: 3 additions & 2 deletions app/services/attack-objects-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions app/services/relationships-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f3dc190

Please sign in to comment.