Skip to content

Commit cc63fe8

Browse files
author
Vikas Agarwal
committed
Merge branch 'develop' into hotfix/user_level_reports
2 parents 29b71ea + 70921a5 commit cc63fe8

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

src/routes/projects/list.spec.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -442,31 +442,32 @@ describe('LIST Project', () => {
442442
const resJson = res.body;
443443
should.exist(resJson);
444444
resJson.should.have.lengthOf(3);
445-
resJson[0].should.have.property('attachments');
446-
resJson[0].attachments.should.have.lengthOf(2);
447-
resJson[0].attachments[0].should.have.property('id');
448-
resJson[0].attachments[0].should.have.property('projectId');
449-
resJson[0].attachments[0].should.have.property('title');
450-
resJson[0].attachments[0].should.have.property('description');
451-
resJson[0].attachments[0].should.have.property('path');
452-
resJson[0].attachments[0].should.have.property('type');
453-
resJson[0].attachments[0].should.have.property('tags');
454-
resJson[0].attachments[0].should.have.property('contentType');
455-
resJson[0].attachments[0].should.have.property('createdBy');
456-
resJson[0].attachments[0].should.have.property('updatedBy');
445+
const project = _.find(resJson, { id: project1.id });
446+
project.should.have.property('attachments');
447+
project.attachments.should.have.lengthOf(2);
448+
project.attachments[0].should.have.property('id');
449+
project.attachments[0].should.have.property('projectId');
450+
project.attachments[0].should.have.property('title');
451+
project.attachments[0].should.have.property('description');
452+
project.attachments[0].should.have.property('path');
453+
project.attachments[0].should.have.property('type');
454+
project.attachments[0].should.have.property('tags');
455+
project.attachments[0].should.have.property('contentType');
456+
project.attachments[0].should.have.property('createdBy');
457+
project.attachments[0].should.have.property('updatedBy');
457458

458-
resJson[0].attachments[1].should.have.property('id');
459-
resJson[0].attachments[1].should.have.property('projectId');
460-
resJson[0].attachments[1].should.have.property('title');
461-
resJson[0].attachments[1].should.have.property('description');
462-
resJson[0].attachments[1].should.have.property('path');
463-
resJson[0].attachments[1].should.have.property('type');
464-
resJson[0].attachments[1].should.have.property('tags');
465-
resJson[0].attachments[1].should.have.property('createdBy');
466-
resJson[0].attachments[1].should.have.property('updatedBy');
459+
project.attachments[1].should.have.property('id');
460+
project.attachments[1].should.have.property('projectId');
461+
project.attachments[1].should.have.property('title');
462+
project.attachments[1].should.have.property('description');
463+
project.attachments[1].should.have.property('path');
464+
project.attachments[1].should.have.property('type');
465+
project.attachments[1].should.have.property('tags');
466+
project.attachments[1].should.have.property('createdBy');
467+
project.attachments[1].should.have.property('updatedBy');
467468

468-
resJson[0].should.have.property('description');
469-
resJson[0].should.have.property('billingAccountId');
469+
project.should.have.property('description');
470+
project.should.have.property('billingAccountId');
470471
done();
471472
}
472473
});
@@ -1112,7 +1113,6 @@ describe('LIST Project', () => {
11121113
resJson[0].name.should.equal('test1');
11131114
resJson[0].invites.should.have.lengthOf(2);
11141115
resJson[0].invites[0].should.have.property('email');
1115-
should.not.exist(resJson[0].invites[0].userId);
11161116
resJson[0].invites[1].email.should.equal('h***o@w***d.com');
11171117
done();
11181118
}

src/util.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,12 @@ _.assignIn(util, {
636636
}
637637
},
638638
/**
639-
* Post-process given invite(s) with following constraints:
640-
* - email field will be omitted from invite if the invite has defined userId
641-
* - email field (if existed) will be masked UNLESS current user has admin permissions OR current user created this invite
639+
* Post-process given invite(s)
640+
* Mask `email` and hide `userId` to prevent leaking Personally Identifiable Information (PII)
642641
*
643-
* Email to be masked is found in the fields defined by `jsonPath` in the `data`.
644642
* Immutable - doesn't modify data, but creates a clone.
645643
*
646-
* @param {String} jsonPath jsonpath string
644+
* @param {String} jsonPath jsonpath string
647645
* @param {Object} data the data which need to process
648646
* @param {Object} req The request object
649647
*
@@ -668,13 +666,21 @@ _.assignIn(util, {
668666
}
669667

670668
if (invite.email) {
671-
// mask email if non-admin or not own invite
669+
const canSeeEmail = (
670+
isAdmin || // admin
671+
invite.createdBy === currentUserId || // user who created invite
672+
invite.userId === currentUserId // user who is invited
673+
);
674+
// mask email if user cannot see it
672675
_.assign(invite, {
673-
email: isAdmin || invite.createdBy === currentUserId ? invite.email : util.maskEmail(invite.email),
676+
email: canSeeEmail ? invite.email : util.maskEmail(invite.email),
674677
});
675678

676-
// for non-admin users don't return `userId` for invites created by `email`
677-
if (invite.userId && !isAdmin) {
679+
const canGetUserId = (
680+
isAdmin || // admin
681+
invite.userId === currentUserId // user who is invited
682+
);
683+
if (invite.userId && !canGetUserId) {
678684
_.assign(invite, {
679685
userId: null,
680686
});

0 commit comments

Comments
 (0)