Skip to content

Commit 7229cfc

Browse files
committed
feat: don't return "userId" for invites by email
1 parent 2f99384 commit 7229cfc

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/routes/projectMemberInvites/create.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,8 @@ describe('Project Member Invite create', () => {
445445
should.exist(resJson);
446446
resJson.role.should.equal('customer');
447447
resJson.projectId.should.equal(project2.id);
448-
resJson.userId.should.equal(12345);
449-
should.not.exist(resJson.email);
450-
should.not.exist(resJson.hashEmail);
448+
should.not.exist(resJson.userId);
449+
resJson.email.should.equal('hello@world.com');
451450
server.services.pubsub.publish.calledWith('project.member.invite.created').should.be.true;
452451
done();
453452
}

src/routes/projectMemberInvites/get.spec.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,7 @@ describe('GET Project Member Invite', () => {
206206
const resJson = res.body;
207207
should.exist(resJson);
208208
should.exist(resJson.projectId);
209-
should.not.exist(resJson.email);
210-
should.not.exist(resJson.hashEmail);
211209
resJson.id.should.be.eql(2);
212-
resJson.userId.should.be.eql(testUtil.userIds.copilot);
213210
resJson.status.should.be.eql(INVITE_STATUS.PENDING);
214211
done();
215212
}

src/util.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ _.assignIn(util, {
659659
const isAdmin = util.hasPermission({ topcoderRoles: [USER_ROLE.TOPCODER_ADMIN] }, req.authUser);
660660
const currentUserId = req.authUser.userId;
661661

662+
// admins can get data as it is
662663
if (isAdmin) {
663664
// even though we didn't make any changes to the data, return a clone here for consistency
664665
return dataClone;
@@ -668,18 +669,21 @@ _.assignIn(util, {
668669
if (!_.has(invite, 'email')) {
669670
return invite;
670671
}
671-
let email;
672-
if (!invite.userId) {
672+
673+
if (invite.email) {
673674
// mask email if non-admin or not own invite
674-
email = isAdmin || invite.createdBy === currentUserId ? invite.email : util.maskEmail(invite.email);
675-
} else {
676-
// userId is defined, no email field returned
677-
email = null;
678-
}
679-
_.assign(invite, { email });
680-
if (!invite.email && _.has(invite, 'hashEmail')) {
681-
_.assign(invite, { hashEmail: null });
675+
_.assign(invite, {
676+
email: isAdmin || invite.createdBy === currentUserId ? invite.email : util.maskEmail(invite.email),
677+
});
678+
679+
// for non-admin users don't return `userId` for invites created by `email`
680+
if (invite.userId && !isAdmin) {
681+
_.assign(invite, {
682+
userId: null,
683+
});
684+
}
682685
}
686+
683687
return invite;
684688
};
685689

0 commit comments

Comments
 (0)