Skip to content

Commit b3a128a

Browse files
committed
fix: return emails for members
- return email for members, but only to Topcoder Admins - fix logic for not returning emails in invites by handle - emails are returned only to Topcoder Admins but not Connect Admins
1 parent 4331abc commit b3a128a

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/util.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
VALUE_TYPE,
2929
ESTIMATION_TYPE,
3030
RESOURCES,
31+
USER_ROLE,
3132
} from './constants';
3233

3334
const tcCoreLibAuth = require('tc-core-library-js').auth;
@@ -268,12 +269,18 @@ _.assignIn(util, {
268269
* @return {object} the parsed array
269270
*/
270271
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)) {
274278
return fields;
275279
}
280+
281+
// for non topcoder admins remove emails from the field list
276282
_.assign(fields, { project_members: _.filter(fields.project_members, f => f !== 'email') });
283+
277284
return fields;
278285
},
279286
/**
@@ -628,7 +635,7 @@ _.assignIn(util, {
628635
// uncomment code below, to enable masking emails again
629636

630637
/*
631-
const isAdmin = util.hasPermission({ topcoderRoles: ADMIN_ROLES }, req.authUser);
638+
const isAdmin = util.hasPermission({ topcoderRoles: [USER_ROLE.TOPCODER_ADMIN] }, req.authUser);
632639
if (isAdmin) {
633640
return data;
634641
}
@@ -660,6 +667,11 @@ _.assignIn(util, {
660667
const memberTraitFields = ['photoURL', 'workingHourStart', 'workingHourEnd', 'timeZone'];
661668
const memberDetailFields = ['handle', 'firstName', 'lastName'];
662669

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+
663675
let allMemberDetails = [];
664676
if (_.intersection(fields, _.union(memberDetailFields, memberTraitFields)).length > 0) {
665677
const userIds = _.reject(_.map(members, 'userId'), _.isNil); // some invites may have no `userId`
@@ -711,15 +723,16 @@ _.assignIn(util, {
711723
// pick valid fields from fetched member details
712724
return _.map(members, (member) => {
713725
let memberDetails = _.find(allMemberDetails, ({ userId }) => userId === member.userId);
714-
memberDetails = _.assign({}, member, memberDetails);
726+
memberDetails = _.assign({}, member, _.pick(memberDetails, _.union(memberDetailFields, memberTraitFields)));
715727
// this case would be only valid for invites:
716728
// don't return `email` for non-admins if invitation has `userId`
717729
// if invitation doesn't have `userId` means it is invitation by email
718730
// then we are still returning emails to all users
719731
if (
732+
memberDetails.status && // this is how we identify that the object is "invite" and not a "member"
720733
memberDetails.email &&
721734
memberDetails.userId &&
722-
!util.hasPermission({ topcoderRoles: ADMIN_ROLES }, req.authUser)
735+
!util.hasPermission({ topcoderRoles: [USER_ROLE.TOPCODER_ADMIN] }, req.authUser)
723736
) {
724737
delete memberDetails.email;
725738
}

0 commit comments

Comments
 (0)