@@ -30,6 +30,10 @@ const PROJECT_MEMBER_ATTRIBUTES = _.without(
30
30
_ . keys ( models . ProjectMember . rawAttributes ) ,
31
31
'deletedAt' ,
32
32
) ;
33
+ const PROJECT_MEMBER_INVITE_ATTRIBUTES = _ . without (
34
+ _ . keys ( models . ProjectMemberInvite . rawAttributes ) ,
35
+ 'deletedAt'
36
+ ) ;
33
37
const PROJECT_ATTACHMENT_ATTRIBUTES = _ . without (
34
38
_ . keys ( models . ProjectAttachment . rawAttributes ) ,
35
39
'deletedAt' ,
@@ -126,6 +130,10 @@ const parseElasticSearchCriteria = (criteria, fields, order) => {
126
130
const memberFields = _ . get ( fields , 'project_members' ) ;
127
131
sourceInclude = sourceInclude . concat ( _ . map ( memberFields , single => `members.${ single } ` ) ) ;
128
132
}
133
+ if ( _ . get ( fields , 'project_member_invites' , null ) ) {
134
+ const memberFields = _ . get ( fields , 'project_member_invites' ) ;
135
+ sourceInclude = sourceInclude . concat ( _ . map ( memberFields , single => `invites.${ single } ` ) ) ;
136
+ }
129
137
if ( _ . get ( fields , 'project_phases' , null ) ) {
130
138
const phaseFields = _ . get ( fields , 'project_phases' ) ;
131
139
sourceInclude = sourceInclude . concat ( _ . map ( phaseFields , single => `phases.${ single } ` ) ) ;
@@ -249,6 +257,7 @@ const retrieveProjects = (req, criteria, sort, ffields) => {
249
257
fields = util . parseFields ( fields , {
250
258
projects : PROJECT_ATTRIBUTES ,
251
259
project_members : PROJECT_MEMBER_ATTRIBUTES ,
260
+ project_member_invites : PROJECT_MEMBER_INVITE_ATTRIBUTES ,
252
261
project_phases : PROJECT_PHASE_ATTRIBUTES ,
253
262
project_phases_products : PROJECT_PHASE_PRODUCTS_ATTRIBUTES ,
254
263
attachments : PROJECT_ATTACHMENT_ATTRIBUTES ,
@@ -321,16 +330,18 @@ module.exports = [
321
330
const getProjectIds = ! memberOnly && util . hasRole ( req , USER_ROLE . COPILOT ) ?
322
331
models . Project . getProjectIdsForCopilot ( req . authUser . userId ) :
323
332
models . ProjectMember . getProjectIdsForUser ( req . authUser . userId ) ;
333
+
324
334
return getProjectIds
325
335
. then ( ( accessibleProjectIds ) => {
326
- let allowedProjectIds = accessibleProjectIds ;
336
+ const allowedProjectIds = accessibleProjectIds ;
327
337
// get projects with pending invite for current user
328
338
const invites = models . ProjectMemberInvite . getProjectInvitesForUser (
329
339
req . authUser . email ,
330
340
req . authUser . userId ) ;
331
- if ( invites ) {
332
- allowedProjectIds = _ . union ( allowedProjectIds , invites ) ;
333
- }
341
+
342
+ return invites . then ( ( ids => _ . union ( allowedProjectIds , ids ) ) ) ;
343
+ } )
344
+ . then ( ( allowedProjectIds ) => {
334
345
// filter based on accessible
335
346
if ( _ . get ( criteria . filters , 'id' , null ) ) {
336
347
criteria . filters . id . $in = _ . intersection (
0 commit comments