@@ -5,7 +5,7 @@ import { EVENT, BUS_API_EVENT, PROJECT_STATUS, PROJECT_PHASE_STATUS, PROJECT_MEM
5
5
from '../constants' ;
6
6
import { createEvent } from '../services/busApi' ;
7
7
import models from '../models' ;
8
- import getTopcoderProjectMembers from '../util' ;
8
+ import util from '../util' ;
9
9
10
10
/**
11
11
* Map of project status and event name sent to bus api
@@ -367,7 +367,7 @@ module.exports = (app, logger) => {
367
367
userId : req . authUser . userId ,
368
368
initiatorUserId : req . authUser . userId ,
369
369
allowedUsers : created . status === PROJECT_PHASE_STATUS . DRAFT ?
370
- getTopcoderProjectMembers ( project . members ) : null ,
370
+ util . getTopcoderProjectMembers ( project . members ) : null ,
371
371
} , logger ) ;
372
372
return sendPlanReadyEventIfNeeded ( req , project , created ) ;
373
373
} ) . catch ( err => null ) ; // eslint-disable-line no-unused-vars
@@ -393,7 +393,7 @@ module.exports = (app, logger) => {
393
393
userId : req . authUser . userId ,
394
394
initiatorUserId : req . authUser . userId ,
395
395
allowedUsers : deleted . status === PROJECT_PHASE_STATUS . DRAFT ?
396
- getTopcoderProjectMembers ( project . members ) : null ,
396
+ util . getTopcoderProjectMembers ( project . members ) : null ,
397
397
} , logger ) ;
398
398
} ) . catch ( err => null ) ; // eslint-disable-line no-unused-vars
399
399
} ) ;
@@ -446,7 +446,7 @@ module.exports = (app, logger) => {
446
446
userId : req . authUser . userId ,
447
447
initiatorUserId : req . authUser . userId ,
448
448
allowedUsers : updated . status === PROJECT_PHASE_STATUS . DRAFT ?
449
- getTopcoderProjectMembers ( project . members ) : null ,
449
+ util . getTopcoderProjectMembers ( project . members ) : null ,
450
450
} , logger ) ) ;
451
451
events . forEach ( ( event ) => { eventsMap [ event ] = true ; } ) ;
452
452
}
@@ -493,7 +493,7 @@ module.exports = (app, logger) => {
493
493
userId : req . authUser . userId ,
494
494
initiatorUserId : req . authUser . userId ,
495
495
allowedUsers : updated . status === PROJECT_PHASE_STATUS . DRAFT ?
496
- getTopcoderProjectMembers ( project . members ) : null ,
496
+ util . getTopcoderProjectMembers ( project . members ) : null ,
497
497
} , logger ) ;
498
498
}
499
499
} ) . catch ( err => null ) ; // eslint-disable-line no-unused-vars
@@ -700,63 +700,87 @@ module.exports = (app, logger) => {
700
700
app . on ( EVENT . ROUTING_KEY . PROJECT_MEMBER_INVITE_CREATED , ( { req, userId, email, status, role } ) => {
701
701
logger . debug ( 'receive PROJECT_MEMBER_INVITE_CREATED event' ) ;
702
702
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
722
737
} ) ;
723
738
724
739
app . on ( EVENT . ROUTING_KEY . PROJECT_MEMBER_INVITE_UPDATED , ( { req, userId, email, status, role, createdBy } ) => {
725
740
logger . debug ( 'receive PROJECT_MEMBER_INVITE_UPDATED event' ) ;
726
741
const projectId = _ . parseInt ( req . params . projectId ) ;
727
742
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
761
785
} ) ;
762
786
} ;
0 commit comments