@@ -5,6 +5,7 @@ import models from '../../models';
5
5
import { INVITE_STATUS , PROJECT_MEMBER_NON_CUSTOMER_ROLES } from '../../constants' ;
6
6
import util from '../../util' ;
7
7
import { PERMISSION } from '../../permissions/constants' ;
8
+ import permissionUtils from '../../utils/permissions' ;
8
9
9
10
const ES_PROJECT_INDEX = config . get ( 'elasticsearchConfig.indexName' ) ;
10
11
const ES_PROJECT_TYPE = config . get ( 'elasticsearchConfig.docType' ) ;
@@ -654,17 +655,30 @@ module.exports = [
654
655
// so we don't want DB to return unrelated data, ref issue #450
655
656
if ( _ . intersection ( _ . keys ( filters ) , SUPPORTED_FILTERS ) . length > 0 ) {
656
657
req . log . debug ( 'Don\'t fallback to DB because some filters are defined.' ) ;
657
- return util . setPaginationHeaders ( req , res ,
658
- util . postProcessInvites ( '$.rows[*].invites[?(@.email)]' , result , req ) ) ;
658
+
659
+ return result ;
659
660
}
660
661
661
- return retrieveProjectsFromDB ( req , criteria , sort , req . query . fields )
662
- . then ( r => util . setPaginationHeaders ( req , res ,
663
- util . postProcessInvites ( '$.rows[*].invites[?(@.email)]' , r , req ) ) ) ;
662
+ return retrieveProjectsFromDB ( req , criteria , sort , req . query . fields ) ;
664
663
}
664
+
665
665
req . log . debug ( 'Projects found in ES' ) ;
666
- return util . setPaginationHeaders ( req , res ,
667
- util . postProcessInvites ( '$.rows[*].invites[?(@.email)]' , result , req ) ) ;
666
+
667
+ return result ;
668
+ } ) . then ( ( result ) => {
669
+ const postProcessedResult = util . postProcessInvites ( '$.rows[*].invites[?(@.email)]' , result , req ) ;
670
+
671
+ postProcessedResult . rows . forEach ( ( project ) => {
672
+ // filter out attachments which user cannot see
673
+ if ( project . attachments ) {
674
+ // eslint-disable-next-line no-param-reassign
675
+ project . attachments = project . attachments . filter ( attachment =>
676
+ permissionUtils . hasReadAccessToAttachment ( attachment , req ) ,
677
+ ) ;
678
+ }
679
+ } ) ;
680
+
681
+ return util . setPaginationHeaders ( req , res , postProcessedResult ) ;
668
682
} )
669
683
. catch ( err => next ( err ) ) ;
670
684
} ,
0 commit comments