Skip to content

Commit 30b5000

Browse files
authored
Merge pull request #311 from topcoder-platform/feature/sso-users-invites
set SSO flag for invite events
2 parents 84ce3c5 + c0016d1 commit 30b5000

File tree

6 files changed

+97
-59
lines changed

6 files changed

+97
-59
lines changed

config/custom-environment-variables.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@
4949
"connectUrl": "CONNECT_URL",
5050
"accountsAppUrl": "ACCOUNTS_APP_URL",
5151
"inviteEmailSubject": "INVITE_EMAIL_SUBJECT",
52-
"inviteEmailSectionTitle": "INVITE_EMAIL_SECTION_TITLE"
52+
"inviteEmailSectionTitle": "INVITE_EMAIL_SECTION_TITLE",
53+
"SSO_REFCODES": "SSO_REFCODES"
5354
}

config/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@
5858
"connectUrl":"https://connect.topcoder-dev.com",
5959
"accountsAppUrl": "https://accounts.topcoder-dev.com",
6060
"MAX_REVISION_NUMBER": 100,
61-
"UNIQUE_GMAIL_VALIDATION": false
61+
"UNIQUE_GMAIL_VALIDATION": false,
62+
"SSO_REFCODES": "[]"
6263
}

src/events/busApi.js

Lines changed: 81 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { EVENT, BUS_API_EVENT, PROJECT_STATUS, PROJECT_PHASE_STATUS, PROJECT_MEM
55
from '../constants';
66
import { createEvent } from '../services/busApi';
77
import models from '../models';
8-
import getTopcoderProjectMembers from '../util';
8+
import util from '../util';
99

1010
/**
1111
* Map of project status and event name sent to bus api
@@ -367,7 +367,7 @@ module.exports = (app, logger) => {
367367
userId: req.authUser.userId,
368368
initiatorUserId: req.authUser.userId,
369369
allowedUsers: created.status === PROJECT_PHASE_STATUS.DRAFT ?
370-
getTopcoderProjectMembers(project.members) : null,
370+
util.getTopcoderProjectMembers(project.members) : null,
371371
}, logger);
372372
return sendPlanReadyEventIfNeeded(req, project, created);
373373
}).catch(err => null); // eslint-disable-line no-unused-vars
@@ -393,7 +393,7 @@ module.exports = (app, logger) => {
393393
userId: req.authUser.userId,
394394
initiatorUserId: req.authUser.userId,
395395
allowedUsers: deleted.status === PROJECT_PHASE_STATUS.DRAFT ?
396-
getTopcoderProjectMembers(project.members) : null,
396+
util.getTopcoderProjectMembers(project.members) : null,
397397
}, logger);
398398
}).catch(err => null); // eslint-disable-line no-unused-vars
399399
});
@@ -446,7 +446,7 @@ module.exports = (app, logger) => {
446446
userId: req.authUser.userId,
447447
initiatorUserId: req.authUser.userId,
448448
allowedUsers: updated.status === PROJECT_PHASE_STATUS.DRAFT ?
449-
getTopcoderProjectMembers(project.members) : null,
449+
util.getTopcoderProjectMembers(project.members) : null,
450450
}, logger));
451451
events.forEach((event) => { eventsMap[event] = true; });
452452
}
@@ -493,7 +493,7 @@ module.exports = (app, logger) => {
493493
userId: req.authUser.userId,
494494
initiatorUserId: req.authUser.userId,
495495
allowedUsers: updated.status === PROJECT_PHASE_STATUS.DRAFT ?
496-
getTopcoderProjectMembers(project.members) : null,
496+
util.getTopcoderProjectMembers(project.members) : null,
497497
}, logger);
498498
}
499499
}).catch(err => null); // eslint-disable-line no-unused-vars
@@ -700,63 +700,87 @@ module.exports = (app, logger) => {
700700
app.on(EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_CREATED, ({ req, userId, email, status, role }) => {
701701
logger.debug('receive PROJECT_MEMBER_INVITE_CREATED event');
702702
const projectId = _.parseInt(req.params.projectId);
703-
704-
if (status === INVITE_STATUS.REQUESTED) {
705-
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_REQUESTED, {
706-
projectId,
707-
userId,
708-
email,
709-
role,
710-
initiatorUserId: req.authUser.userId,
711-
}, logger);
712-
} else {
713-
// send event to bus api
714-
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_CREATED, {
715-
projectId,
716-
userId,
717-
email,
718-
role,
719-
initiatorUserId: req.authUser.userId,
720-
}, logger);
721-
}
703+
models.Project.findOne({
704+
where: { id: projectId },
705+
})
706+
.then((project) => {
707+
logger.debug(util.isSSO);
708+
if (status === INVITE_STATUS.REQUESTED) {
709+
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_REQUESTED, {
710+
projectId,
711+
userId,
712+
email,
713+
role,
714+
initiatorUserId: req.authUser.userId,
715+
isSSO: util.isSSO(project),
716+
}, logger);
717+
} else {
718+
// send event to bus api
719+
logger.debug(JSON.stringify({
720+
projectId,
721+
userId,
722+
email,
723+
role,
724+
initiatorUserId: req.authUser.userId,
725+
isSSO: util.isSSO(project),
726+
}));
727+
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_CREATED, {
728+
projectId,
729+
userId,
730+
email,
731+
role,
732+
initiatorUserId: req.authUser.userId,
733+
isSSO: util.isSSO(project),
734+
}, logger);
735+
}
736+
}).catch(err => logger.error(err)); // eslint-disable-line no-unused-vars
722737
});
723738

724739
app.on(EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_UPDATED, ({ req, userId, email, status, role, createdBy }) => {
725740
logger.debug('receive PROJECT_MEMBER_INVITE_UPDATED event');
726741
const projectId = _.parseInt(req.params.projectId);
727742

728-
if (status === INVITE_STATUS.REQUEST_APPROVED) {
729-
// send event to bus api
730-
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_APPROVED, {
731-
projectId,
732-
userId,
733-
originator: createdBy,
734-
email,
735-
role,
736-
status,
737-
initiatorUserId: req.authUser.userId,
738-
}, logger);
739-
} else if (status === INVITE_STATUS.REQUEST_REJECTED) {
740-
// send event to bus api
741-
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_REJECTED, {
742-
projectId,
743-
userId,
744-
originator: createdBy,
745-
email,
746-
role,
747-
status,
748-
initiatorUserId: req.authUser.userId,
749-
}, logger);
750-
} else {
751-
// send event to bus api
752-
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_UPDATED, {
753-
projectId,
754-
userId,
755-
email,
756-
role,
757-
status,
758-
initiatorUserId: req.authUser.userId,
759-
}, logger);
760-
}
743+
models.Project.findOne({
744+
where: { id: projectId },
745+
})
746+
.then((project) => {
747+
logger.debug(util.isSSO);
748+
if (status === INVITE_STATUS.REQUEST_APPROVED) {
749+
// send event to bus api
750+
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_APPROVED, {
751+
projectId,
752+
userId,
753+
originator: createdBy,
754+
email,
755+
role,
756+
status,
757+
initiatorUserId: req.authUser.userId,
758+
isSSO: util.isSSO(project),
759+
}, logger);
760+
} else if (status === INVITE_STATUS.REQUEST_REJECTED) {
761+
// send event to bus api
762+
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_REJECTED, {
763+
projectId,
764+
userId,
765+
originator: createdBy,
766+
email,
767+
role,
768+
status,
769+
initiatorUserId: req.authUser.userId,
770+
isSSO: util.isSSO(project),
771+
}, logger);
772+
} else {
773+
// send event to bus api
774+
createEvent(BUS_API_EVENT.PROJECT_MEMBER_INVITE_UPDATED, {
775+
projectId,
776+
userId,
777+
email,
778+
role,
779+
status,
780+
initiatorUserId: req.authUser.userId,
781+
isSSO: util.isSSO(project),
782+
}, logger);
783+
}
784+
}).catch(err => null); // eslint-disable-line no-unused-vars
761785
});
762786
};

src/routes/projectMemberInvites/create.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ describe('Project Member Invite create', () => {
841841
projectId: project1.id,
842842
userId: 3,
843843
email: null,
844+
isSSO: false,
844845
})).should.be.true;
845846
done();
846847
});
@@ -888,6 +889,7 @@ describe('Project Member Invite create', () => {
888889
projectId: project1.id,
889890
userId: null,
890891
email: 'hello@world.com',
892+
isSSO: false,
891893
})).should.be.true;
892894
done();
893895
});

src/routes/projectMemberInvites/update.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ describe('Project member invite update', () => {
359359
userId: invite1.userId,
360360
status: INVITE_STATUS.ACCEPTED,
361361
email: null,
362+
isSSO: false,
362363
})).should.be.true;
363364
createEventSpy.secondCall.calledWith(BUS_API_EVENT.MEMBER_JOINED, sinon.match({
364365
projectId: project1.id,

src/util.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const m2m = tcCoreLibAuth.m2m(config);
2828

2929
const util = _.cloneDeep(require('tc-core-library-js').util(config));
3030

31+
const ssoRefCodes = JSON.parse(config.get('SSO_REFCODES'));
32+
3133
// the client modifies the config object, so always passed the cloned object
3234
let esClient = null;
3335

@@ -468,6 +470,13 @@ _.assignIn(util, {
468470
*/
469471
getTopcoderProjectMembers: members => _(members).filter(m => m.role !== PROJECT_MEMBER_ROLE.CUSTOMER),
470472

473+
/**
474+
* Check if project is for SSO users
475+
* @param {Object} project project
476+
* @return {Boolean} is SSO project
477+
*/
478+
isSSO: project => ssoRefCodes.indexOf(_.get(project, 'details.utm.code')) > -1,
479+
471480
/**
472481
* Check if the following model exist
473482
* @param {Object} keyInfo key information, it includes version and key

0 commit comments

Comments
 (0)