@@ -5,7 +5,7 @@ import { EVENT, BUS_API_EVENT, PROJECT_STATUS, PROJECT_PHASE_STATUS, PROJECT_MEM
55 from '../constants' ;
66import { createEvent } from '../services/busApi' ;
77import 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
@@ -716,63 +716,87 @@ module.exports = (app, logger) => {
716716 app . on ( EVENT . ROUTING_KEY . PROJECT_MEMBER_INVITE_CREATED , ( { req, userId, email, status, role } ) => {
717717 logger . debug ( 'receive PROJECT_MEMBER_INVITE_CREATED event' ) ;
718718 const projectId = _ . parseInt ( req . params . projectId ) ;
719-
720- if ( status === INVITE_STATUS . REQUESTED ) {
721- createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_REQUESTED , {
722- projectId,
723- userId,
724- email,
725- role,
726- initiatorUserId : req . authUser . userId ,
727- } , logger ) ;
728- } else {
729- // send event to bus api
730- createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_CREATED , {
731- projectId,
732- userId,
733- email,
734- role,
735- initiatorUserId : req . authUser . userId ,
736- } , logger ) ;
737- }
719+ models . Project . findOne ( {
720+ where : { id : projectId } ,
721+ } )
722+ . then ( ( project ) => {
723+ logger . debug ( util . isSSO ) ;
724+ if ( status === INVITE_STATUS . REQUESTED ) {
725+ createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_REQUESTED , {
726+ projectId,
727+ userId,
728+ email,
729+ role,
730+ initiatorUserId : req . authUser . userId ,
731+ isSSO : util . isSSO ( project ) ,
732+ } , logger ) ;
733+ } else {
734+ // send event to bus api
735+ logger . debug ( JSON . stringify ( {
736+ projectId,
737+ userId,
738+ email,
739+ role,
740+ initiatorUserId : req . authUser . userId ,
741+ isSSO : util . isSSO ( project ) ,
742+ } ) ) ;
743+ createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_CREATED , {
744+ projectId,
745+ userId,
746+ email,
747+ role,
748+ initiatorUserId : req . authUser . userId ,
749+ isSSO : util . isSSO ( project ) ,
750+ } , logger ) ;
751+ }
752+ } ) . catch ( err => logger . error ( err ) ) ; // eslint-disable-line no-unused-vars
738753 } ) ;
739754
740755 app . on ( EVENT . ROUTING_KEY . PROJECT_MEMBER_INVITE_UPDATED , ( { req, userId, email, status, role, createdBy } ) => {
741756 logger . debug ( 'receive PROJECT_MEMBER_INVITE_UPDATED event' ) ;
742757 const projectId = _ . parseInt ( req . params . projectId ) ;
743758
744- if ( status === INVITE_STATUS . REQUEST_APPROVED ) {
745- // send event to bus api
746- createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_APPROVED , {
747- projectId,
748- userId,
749- originator : createdBy ,
750- email,
751- role,
752- status,
753- initiatorUserId : req . authUser . userId ,
754- } , logger ) ;
755- } else if ( status === INVITE_STATUS . REQUEST_REJECTED ) {
756- // send event to bus api
757- createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_REJECTED , {
758- projectId,
759- userId,
760- originator : createdBy ,
761- email,
762- role,
763- status,
764- initiatorUserId : req . authUser . userId ,
765- } , logger ) ;
766- } else {
767- // send event to bus api
768- createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_UPDATED , {
769- projectId,
770- userId,
771- email,
772- role,
773- status,
774- initiatorUserId : req . authUser . userId ,
775- } , logger ) ;
776- }
759+ models . Project . findOne ( {
760+ where : { id : projectId } ,
761+ } )
762+ . then ( ( project ) => {
763+ logger . debug ( util . isSSO ) ;
764+ if ( status === INVITE_STATUS . REQUEST_APPROVED ) {
765+ // send event to bus api
766+ createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_APPROVED , {
767+ projectId,
768+ userId,
769+ originator : createdBy ,
770+ email,
771+ role,
772+ status,
773+ initiatorUserId : req . authUser . userId ,
774+ isSSO : util . isSSO ( project ) ,
775+ } , logger ) ;
776+ } else if ( status === INVITE_STATUS . REQUEST_REJECTED ) {
777+ // send event to bus api
778+ createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_REJECTED , {
779+ projectId,
780+ userId,
781+ originator : createdBy ,
782+ email,
783+ role,
784+ status,
785+ initiatorUserId : req . authUser . userId ,
786+ isSSO : util . isSSO ( project ) ,
787+ } , logger ) ;
788+ } else {
789+ // send event to bus api
790+ createEvent ( BUS_API_EVENT . PROJECT_MEMBER_INVITE_UPDATED , {
791+ projectId,
792+ userId,
793+ email,
794+ role,
795+ status,
796+ initiatorUserId : req . authUser . userId ,
797+ isSSO : util . isSSO ( project ) ,
798+ } , logger ) ;
799+ }
800+ } ) . catch ( err => null ) ; // eslint-disable-line no-unused-vars
777801 } ) ;
778802} ;
0 commit comments