@@ -7,7 +7,7 @@ let qs = require('qs');
7
7
let mongodb = require ( '../utils/mongodb' ) ;
8
8
let moment = require ( 'moment' ) ;
9
9
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' ) ;
11
11
const { userIsOnlyInRole } = require ( '../utils/auth-utils' ) ;
12
12
13
13
function isEmpty ( obj ) {
@@ -257,7 +257,7 @@ exports.addArrayCountField = addArrayCountField;
257
257
// of any individual where the birthdate is null or the individual
258
258
// is less then 19 years old. First step to do this is calculate their
259
259
// age
260
- const issuedToRedaction = function ( roles ) {
260
+ const issuedToRedaction = function ( roles ) {
261
261
// Skip redaction if the record.write array matches the limited admin user's role.
262
262
// Code would only reach this point if the user doesn't have any of the ApplicationAdminRoles.
263
263
// 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 (
527
527
// of any individual where the birthdate is null or the individual
528
528
// is less then 19 years old.
529
529
if ( ! roles . some ( r => ApplicationAdminRoles . indexOf ( r ) >= 0 ) && ! ( subset && subset . includes ( 'redactedRecord' ) ) ) {
530
- searchResultAggregation = searchResultAggregation . concat ( issuedToRedaction ( roles ) ) ;
530
+ searchResultAggregation = searchResultAggregation . concat ( issuedToRedaction ( roles ) ) ;
531
531
}
532
532
533
533
searchResultAggregation . push ( {
@@ -644,7 +644,7 @@ let searchCollection = async function (
644
644
}
645
645
}
646
646
const collection = db . collection ( collectionName ) ;
647
-
647
+
648
648
const data = await collection
649
649
. aggregate ( aggregation , {
650
650
allowDiskUse : true ,
@@ -663,6 +663,21 @@ exports.publicGet = async function (args, res, next) {
663
663
// if we are doing a public record search, we should use the redacted subset to avoid data leaks
664
664
// this subset cleans the data from any non publicly available information
665
665
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
+
666
681
executeQuery ( args , res , next ) ;
667
682
} ;
668
683
@@ -838,9 +853,9 @@ const executeQuery = async function (args, res, next) {
838
853
} , {
839
854
$addFields : {
840
855
'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 ] } ,
844
859
else : false
845
860
}
846
861
}
0 commit comments