Skip to content

Commit 1d741ca

Browse files
NRPT-712 public get controllers now determine target subset based on schemaName (#829)
1 parent f4ffbce commit 1d741ca

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

api/materialized_views/search/redactedRecordSubset.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const mongodb = require('../../src/utils/mongodb');
22

33
const { AUTHORIZED_PUBLISH_AGENCIES } = require('../../src/utils/constants/misc');
4+
const { SKIP_REDACTION_SCHEMA_NAMES } = require ('../../src/utils/constants/misc');
45

56
/**
67
* Updates the redactedRecord subset.
@@ -51,7 +52,7 @@ async function update(defaultLog) {
5152
skipRedact: {
5253
$cond: {
5354
if: {
54-
$in: [{ $arrayElemAt: ['$fullRecord._schemaName', 0] }, ['MineBCMI', 'CollectionBCMI', 'MapLayerInfo']]
55+
$in: [{ $arrayElemAt: ['$fullRecord._schemaName', 0] }, SKIP_REDACTION_SCHEMA_NAMES]
5556
},
5657
then: true,
5758
else: false

api/src/controllers/search.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let qs = require('qs');
77
let mongodb = require('../utils/mongodb');
88
let moment = require('moment');
99
let fuzzySearch = require('../utils/fuzzySearch');
10-
const { ApplicationAdminRoles, ApplicationLimitedAdminRoles } = require('../utils/constants/misc');
10+
const { ApplicationAdminRoles, ApplicationLimitedAdminRoles, SKIP_REDACTION_SCHEMA_NAMES } = require('../utils/constants/misc');
1111
const { userIsOnlyInRole } = require('../utils/auth-utils');
1212

1313
function isEmpty(obj) {
@@ -257,7 +257,7 @@ exports.addArrayCountField = addArrayCountField;
257257
// of any individual where the birthdate is null or the individual
258258
// is less then 19 years old. First step to do this is calculate their
259259
// age
260-
const issuedToRedaction = function(roles) {
260+
const issuedToRedaction = function (roles) {
261261
// Skip redaction if the record.write array matches the limited admin user's role.
262262
// Code would only reach this point if the user doesn't have any of the ApplicationAdminRoles.
263263
// Only skip redact if the current user's role matches what's on the records.write. If for
@@ -527,7 +527,7 @@ let searchCollection = async function (
527527
// of any individual where the birthdate is null or the individual
528528
// is less then 19 years old.
529529
if (!roles.some(r => ApplicationAdminRoles.indexOf(r) >= 0) && !(subset && subset.includes('redactedRecord'))) {
530-
searchResultAggregation = searchResultAggregation.concat(issuedToRedaction(roles));
530+
searchResultAggregation = searchResultAggregation.concat(issuedToRedaction(roles));
531531
}
532532

533533
searchResultAggregation.push({
@@ -644,7 +644,7 @@ let searchCollection = async function (
644644
}
645645
}
646646
const collection = db.collection(collectionName);
647-
647+
648648
const data = await collection
649649
.aggregate(aggregation, {
650650
allowDiskUse: true,
@@ -663,6 +663,21 @@ exports.publicGet = async function (args, res, next) {
663663
// if we are doing a public record search, we should use the redacted subset to avoid data leaks
664664
// this subset cleans the data from any non publicly available information
665665
args.swagger.params.subset.value = ['redactedRecord'];
666+
667+
// if we are searching for data that does not require redaction, we should search on the main database subset.
668+
if (args.swagger.params.dataset && args.swagger.params.dataset.value) {
669+
if(SKIP_REDACTION_SCHEMA_NAMES.includes(String(args.swagger.params.dataset.value))){
670+
args.swagger.params.subset.value = ['nrpti'];
671+
defaultLog.info(`Searching on non-redacted database despite public search query: '${args.swagger.params.dataset.value}' is not a redacted dataset. `);
672+
}
673+
}
674+
if (args.swagger.params._schemaName && args.swagger.params._schemaName.value) {
675+
if (SKIP_REDACTION_SCHEMA_NAMES.includes(String(args.swagger.params._schemaName.value))){
676+
args.swagger.params.subset.value = ['nrpti'];
677+
defaultLog.info(`Searching on non-redacted database despite public search query: '${args.swagger.params._schemaName.value}' is not a redacted schema. `);
678+
}
679+
}
680+
666681
executeQuery(args, res, next);
667682
};
668683

@@ -838,9 +853,9 @@ const executeQuery = async function (args, res, next) {
838853
}, {
839854
$addFields: {
840855
'collectionRecords.isLink': {
841-
$cond: {
842-
if: { $cond: [ {$ifNull: ['$collectionRecords.documents', false]}, true, false]},
843-
then: { $cond: [ {$ifNull: ['$collectionRecords.documents.key', false] }, false, true] },
856+
$cond: {
857+
if: { $cond: [{ $ifNull: ['$collectionRecords.documents', false] }, true, false] },
858+
then: { $cond: [{ $ifNull: ['$collectionRecords.documents.key', false] }, false, true] },
844859
else: false
845860
}
846861
}

api/src/utils/constants/misc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ exports.MASTER_SCHEMA_NAMES = [
9595
'Warning'
9696
];
9797

98+
exports.SKIP_REDACTION_SCHEMA_NAMES = [
99+
'MineBCMI',
100+
'CollectionBCMI',
101+
'MapLayerInfo',
102+
'ActivityLNG'
103+
];
104+
98105
exports.LNG_SCHEMA_NAMES = [
99106
'ActivityLNG',
100107
'AdministrativePenaltyLNG',

0 commit comments

Comments
 (0)