Skip to content

Commit f06e245

Browse files
author
Maksym Mykhailenko
committed
Merge branch 'develop' into feature/export-import
2 parents 740427d + 90802ab commit f06e245

File tree

7 files changed

+23
-14
lines changed

7 files changed

+23
-14
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:8.2.1
1+
FROM node:12.16.1
22
LABEL version="1.2"
33
LABEL description="Projects microservice"
44
RUN sed -i '/jessie-updates/d' /etc/apt/sources.list

src/routes/projectMemberInvites/delete.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = [
1616
(req, res, next) => {
1717
const projectId = _.parseInt(req.params.projectId);
1818
const inviteId = _.parseInt(req.params.inviteId);
19-
const email = req.authUser.email;
19+
const currentUserEmail = req.authUser.email ? req.authUser.email.toLowerCase() : req.authUser.email;
2020
const currentUserId = req.authUser.userId;
2121

2222
// get invite by id and project id
@@ -25,13 +25,13 @@ module.exports = [
2525
// if invite doesn't exist, return 404
2626
if (!invite) {
2727
const err = new Error(`invite not found for project id ${projectId}, inviteId ${inviteId},` +
28-
` email ${email} and userId ${currentUserId}`,
28+
` email ${currentUserEmail} and userId ${currentUserId}`,
2929
);
3030
err.status = 404;
3131
return next(err);
3232
}
3333
// check this invitation is for logged-in user or not
34-
const ownInvite = (!!invite && (invite.userId === currentUserId || invite.email === email));
34+
const ownInvite = (!!invite && (invite.userId === currentUserId || invite.email === currentUserEmail));
3535

3636
// check permission
3737
req.log.debug('Checking user permission for deleting invite');

src/routes/projectMemberInvites/get.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ describe('GET Project Member Invite', () => {
227227
should.exist(resJson);
228228
should.exist(resJson.projectId);
229229
resJson.id.should.be.eql(3);
230-
resJson.email.should.be.eql('t***t@t***r.com'); // masked
230+
// not masked, because user who is invited by email is the user who is calling this endpoint
231+
resJson.email.should.be.eql('test@topcoder.com');
231232
resJson.status.should.be.eql(INVITE_STATUS.PENDING);
232233
done();
233234
}

src/routes/projectMemberInvites/list.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = [
2727
(req, res, next) => {
2828
const projectId = _.parseInt(req.params.projectId);
2929
const currentUserId = req.authUser.userId;
30-
const email = req.authUser.email;
30+
const currentUserEmail = req.authUser.email ? req.authUser.email.toLowerCase() : req.authUser.email;
3131
const fields = req.query.fields ? req.query.fields.split(',') : null;
3232

3333
const esSearchParam = {
@@ -64,7 +64,7 @@ module.exports = [
6464
esSearchParam.query.nested.query.filtered.filter.bool.must.push({
6565
bool: {
6666
should: [
67-
{ term: { 'invites.email': email } },
67+
{ term: { 'invites.email': currentUserEmail } },
6868
{ term: { 'invites.userId': currentUserId } },
6969
],
7070
minimum_number_should_match: 1,
@@ -90,7 +90,7 @@ module.exports = [
9090
}
9191
// get invitation only for user
9292
return models.ProjectMemberInvite.getPendingOrRequestedProjectInvitesForUser(
93-
projectId, email, currentUserId);
93+
projectId, currentUserEmail, currentUserId);
9494
}
9595
req.log.debug('project member found in ES');
9696
return data[0].inner_hits.invites.hits.hits.map(hit => hit._source); // eslint-disable-line no-underscore-dangle

src/routes/projectMemberInvites/list.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ describe('GET Project Member Invites', () => {
252252
resJson.length.should.be.eql(1);
253253
// check invitations
254254
_.filter(resJson, inv => inv.id === 3).length.should.be.eql(1);
255-
resJson[0].email.should.be.eql('t***t@t***r.com'); // masked
255+
// not masked, because user who is invited by email is the user who is calling this endpoint
256+
resJson[0].email.should.be.eql('test@topcoder.com');
256257
done();
257258
}
258259
});

src/routes/projectMemberInvites/update.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = [
3636
}
3737
const projectId = _.parseInt(req.params.projectId);
3838
const inviteId = _.parseInt(req.params.inviteId);
39-
const email = req.authUser.email;
39+
const currentUserEmail = req.authUser.email ? req.authUser.email.toLowerCase() : req.authUser.email;
4040
const currentUserId = req.authUser.userId;
4141

4242
// get invite by id and project id
@@ -45,13 +45,13 @@ module.exports = [
4545
// if invite doesn't exist, return 404
4646
if (!invite) {
4747
const err = new Error(`invite not found for project id ${projectId}, inviteId ${inviteId},` +
48-
` email ${email} and userId ${currentUserId}`,
48+
` email ${currentUserEmail} and userId ${currentUserId}`,
4949
);
5050
err.status = 404;
5151
return next(err);
5252
}
5353
// check this invitation is for logged-in user or not
54-
const ownInvite = (!!invite && (invite.userId === currentUserId || invite.email === email));
54+
const ownInvite = (!!invite && (invite.userId === currentUserId || invite.email === currentUserEmail));
5555

5656
// check permission
5757
req.log.debug('Checking user permission for updating invite');
@@ -103,7 +103,7 @@ module.exports = [
103103
req.context.currentProjectMembers = members;
104104
let userId = updatedInvite.userId;
105105
// if the requesting user is updating his/her own invite
106-
if (!userId && email === updatedInvite.email) {
106+
if (!userId && currentUserEmail === updatedInvite.email) {
107107
userId = currentUserId;
108108
}
109109
// if we are not able to identify the user yet, it must be something wrong and we should not create

src/util.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ _.assignIn(util, {
654654

655655
const isAdmin = util.hasPermission({ topcoderRoles: [USER_ROLE.TOPCODER_ADMIN] }, req.authUser);
656656
const currentUserId = req.authUser.userId;
657+
const currentUserEmail = req.authUser.email;
657658

658659
// admins can get data as it is
659660
if (isAdmin) {
@@ -670,7 +671,13 @@ _.assignIn(util, {
670671
const canSeeEmail = (
671672
isAdmin || // admin
672673
invite.createdBy === currentUserId || // user who created invite
673-
invite.userId === currentUserId // user who is invited
674+
(invite.userId !== null && invite.userId === currentUserId) || // user who is invited by `handle`
675+
( // user who is invited by `email` (invite doesn't have `userId`)
676+
invite.userId === null &&
677+
invite.email &&
678+
currentUserEmail &&
679+
invite.email.toLowerCase() === currentUserEmail.toLowerCase()
680+
)
674681
);
675682
// mask email if user cannot see it
676683
_.assign(invite, {

0 commit comments

Comments
 (0)