@@ -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
@@ -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} ;
0 commit comments