@@ -28,6 +28,7 @@ import {
28
28
VALUE_TYPE ,
29
29
ESTIMATION_TYPE ,
30
30
RESOURCES ,
31
+ USER_ROLE ,
31
32
} from './constants' ;
32
33
33
34
const tcCoreLibAuth = require ( 'tc-core-library-js' ) . auth ;
@@ -268,12 +269,18 @@ _.assignIn(util, {
268
269
* @return {object } the parsed array
269
270
*/
270
271
ignoreEmailField : ( req , fields ) => {
271
- if ( ! fields . project_members ) { return fields ; }
272
- const isAdmin = util . hasPermission ( { topcoderRoles : ADMIN_ROLES } , req . authUser ) ;
273
- if ( isAdmin ) {
272
+ if ( ! fields . project_members ) {
273
+ return fields ;
274
+ }
275
+
276
+ // Only Topcoder Admins can get all the fields
277
+ if ( util . hasPermission ( { topcoderRoles : [ USER_ROLE . TOPCODER_ADMIN ] } , req . authUser ) ) {
274
278
return fields ;
275
279
}
280
+
281
+ // for non topcoder admins remove emails from the field list
276
282
_ . assign ( fields , { project_members : _ . filter ( fields . project_members , f => f !== 'email' ) } ) ;
283
+
277
284
return fields ;
278
285
} ,
279
286
/**
@@ -628,7 +635,7 @@ _.assignIn(util, {
628
635
// uncomment code below, to enable masking emails again
629
636
630
637
/*
631
- const isAdmin = util.hasPermission({ topcoderRoles: ADMIN_ROLES }, req.authUser);
638
+ const isAdmin = util.hasPermission({ topcoderRoles: [USER_ROLE.TOPCODER_ADMIN] }, req.authUser);
632
639
if (isAdmin) {
633
640
return data;
634
641
}
@@ -660,6 +667,11 @@ _.assignIn(util, {
660
667
const memberTraitFields = [ 'photoURL' , 'workingHourStart' , 'workingHourEnd' , 'timeZone' ] ;
661
668
const memberDetailFields = [ 'handle' , 'firstName' , 'lastName' ] ;
662
669
670
+ // Only Topcoder admins can get emails for users
671
+ if ( util . hasPermission ( { topcoderRoles : [ USER_ROLE . TOPCODER_ADMIN ] } , req . authUser ) ) {
672
+ memberDetailFields . push ( 'email' ) ;
673
+ }
674
+
663
675
let allMemberDetails = [ ] ;
664
676
if ( _ . intersection ( fields , _ . union ( memberDetailFields , memberTraitFields ) ) . length > 0 ) {
665
677
const userIds = _ . reject ( _ . map ( members , 'userId' ) , _ . isNil ) ; // some invites may have no `userId`
@@ -711,15 +723,16 @@ _.assignIn(util, {
711
723
// pick valid fields from fetched member details
712
724
return _ . map ( members , ( member ) => {
713
725
let memberDetails = _ . find ( allMemberDetails , ( { userId } ) => userId === member . userId ) ;
714
- memberDetails = _ . assign ( { } , member , memberDetails ) ;
726
+ memberDetails = _ . assign ( { } , member , _ . pick ( memberDetails , _ . union ( memberDetailFields , memberTraitFields ) ) ) ;
715
727
// this case would be only valid for invites:
716
728
// don't return `email` for non-admins if invitation has `userId`
717
729
// if invitation doesn't have `userId` means it is invitation by email
718
730
// then we are still returning emails to all users
719
731
if (
732
+ memberDetails . status && // this is how we identify that the object is "invite" and not a "member"
720
733
memberDetails . email &&
721
734
memberDetails . userId &&
722
- ! util . hasPermission ( { topcoderRoles : ADMIN_ROLES } , req . authUser )
735
+ ! util . hasPermission ( { topcoderRoles : [ USER_ROLE . TOPCODER_ADMIN ] } , req . authUser )
723
736
) {
724
737
delete memberDetails . email ;
725
738
}
0 commit comments