@@ -1649,11 +1649,13 @@ public ApiResponse updateUser2fa(
16491649 throw new APIRuntimeException (SC_BAD_REQUEST , "You have multiple accounts registered with same email. Please contact with support." );
16501650 }
16511651 }
1652+ Boolean oldMfaStatus = user2faInDb .getMfaEnabled () == null ? false : user2faInDb .getMfaEnabled ();
1653+ Boolean oldDiceStatus = user2faInDb .getDiceEnabled () == null ? false : user2faInDb .getDiceEnabled ();
16521654 if (user2fa .getMfaEnabled () == null ) {
1653- user2fa .setMfaEnabled (user2faInDb . getMfaEnabled () == null ? false : user2faInDb . getMfaEnabled () );
1655+ user2fa .setMfaEnabled (oldMfaStatus );
16541656 }
16551657 if (user2fa .getDiceEnabled () == null ) {
1656- user2fa .setDiceEnabled (user2faInDb . getDiceEnabled () == null ? false : user2faInDb . getDiceEnabled () );
1658+ user2fa .setDiceEnabled (oldDiceStatus );
16571659 }
16581660 if (user2faInDb .getId () == null ) {
16591661 long newId = userDao .insertUser2fa (userId , user2fa .getMfaEnabled (), user2fa .getDiceEnabled (),
@@ -1665,6 +1667,9 @@ public ApiResponse updateUser2fa(
16651667 user2fa .getDiceEnabled (), Utils .toLongValue (authUser .getUserId ()));
16661668 user2faInDb = userDao .findUser2faById (user2faInDb .getId ());
16671669 }
1670+ if (!oldDiceStatus .equals (user2faInDb .getDiceEnabled ())) {
1671+ sendSlackNotification (user2faInDb .getHandle (), null , user2faInDb .getDiceEnabled () ? "DICE enabled" : "DICE disabled" );
1672+ }
16681673 return ApiResponseFactory .createResponse (user2faInDb );
16691674 }
16701675
@@ -1703,6 +1708,7 @@ public ApiResponse getDiceConnection(
17031708 diceConnection .setCreatedAt (diceAttributes .getDiceConnectionCreatedAt ());
17041709 diceConnection .setConnection (diceAuth .getDiceApiUrl () + "/web/connection/inviteurl/"
17051710 + diceAttributes .getDiceConnection ());
1711+ sendSlackNotification (diceAttributes .getHandle (), diceAttributes .getEmail (), "Reusing DICE connection" );
17061712 return ApiResponseFactory .createResponse (diceConnection );
17071713 }
17081714 }
@@ -1731,6 +1737,7 @@ public ApiResponse getDiceConnection(
17311737 diceConnection .setId (newId );
17321738 diceConnection .setConnection (diceAuth .getDiceApiUrl () + "/web/connection/inviteurl/" + connectionId );
17331739 diceConnection .setAccepted (false );
1740+ sendSlackNotification (diceAttributes .getHandle (), diceAttributes .getEmail (), "Created new DICE connection" );
17341741 return ApiResponseFactory .createResponse (diceConnection );
17351742 }
17361743
@@ -1847,6 +1854,7 @@ public ApiResponse issueCredentials(
18471854 response .getMessage ()));
18481855 }
18491856 userDao .updateDiceConnectionStatus (user .getDiceConnectionId (), true );
1857+ sendSlackNotification (user .getHandle (), user .getEmail (), "DICE connection accepted" );
18501858 return ApiResponseFactory .createResponse ("SUCCESS" );
18511859 }
18521860
@@ -2455,6 +2463,21 @@ private void sendWelcomeEmailEvent(User user) {
24552463 logger .error ("Error occured while publishing the events to new kafka." );
24562464 }
24572465 }
2466+
2467+ private void sendSlackNotification (String handle , String email , String message ) {
2468+ ObjectMapper mapper = new ObjectMapper ();
2469+ ObjectNode body = mapper .createObjectNode ();
2470+ body .put ("channel" , diceAuth .getSlackChannelId ());
2471+ body .put ("text" , String .format ("%s%s : %s" , handle , email == null ? "" : String .format (" (%s)" , email ) , message ));
2472+ try {
2473+ new Request ("https://slack.com/api/chat.postMessage" , "POST" )
2474+ .header ("Authorization" , "Bearer " + diceAuth .getSlackKey ())
2475+ .json (mapper .writeValueAsString (body ))
2476+ .execute ();
2477+ } catch (Exception e ) {
2478+ logger .error ("Error when calling slack bot" , e );
2479+ }
2480+ }
24582481
24592482 protected NotificationPayload createActivationNotificationPayload (User user , String redirectUrl ) {
24602483 //If for Connect registration, send activation email with activation code only.
0 commit comments