@@ -128,6 +128,8 @@ public class UserResource implements GetResource<User>, DDLResource<User> {
128128
129129 private String domain ;
130130
131+ private String domainEnv ;
132+
131133 private String sendgridTemplateId ;
132134
133135 private String sendgridWelcomeTemplateId ;
@@ -1649,11 +1651,13 @@ public ApiResponse updateUser2fa(
16491651 throw new APIRuntimeException (SC_BAD_REQUEST , "You have multiple accounts registered with same email. Please contact with support." );
16501652 }
16511653 }
1654+ Boolean oldMfaStatus = user2faInDb .getMfaEnabled () == null ? false : user2faInDb .getMfaEnabled ();
1655+ Boolean oldDiceStatus = user2faInDb .getDiceEnabled () == null ? false : user2faInDb .getDiceEnabled ();
16521656 if (user2fa .getMfaEnabled () == null ) {
1653- user2fa .setMfaEnabled (user2faInDb . getMfaEnabled () == null ? false : user2faInDb . getMfaEnabled () );
1657+ user2fa .setMfaEnabled (oldMfaStatus );
16541658 }
16551659 if (user2fa .getDiceEnabled () == null ) {
1656- user2fa .setDiceEnabled (user2faInDb . getDiceEnabled () == null ? false : user2faInDb . getDiceEnabled () );
1660+ user2fa .setDiceEnabled (oldDiceStatus );
16571661 }
16581662 if (user2faInDb .getId () == null ) {
16591663 long newId = userDao .insertUser2fa (userId , user2fa .getMfaEnabled (), user2fa .getDiceEnabled (),
@@ -1665,6 +1669,9 @@ public ApiResponse updateUser2fa(
16651669 user2fa .getDiceEnabled (), Utils .toLongValue (authUser .getUserId ()));
16661670 user2faInDb = userDao .findUser2faById (user2faInDb .getId ());
16671671 }
1672+ if (!oldDiceStatus .equals (user2faInDb .getDiceEnabled ())) {
1673+ sendSlackNotification (user2faInDb .getHandle (), null , user2faInDb .getDiceEnabled () ? "DICE enabled" : "DICE disabled" );
1674+ }
16681675 return ApiResponseFactory .createResponse (user2faInDb );
16691676 }
16701677
@@ -1703,6 +1710,7 @@ public ApiResponse getDiceConnection(
17031710 diceConnection .setCreatedAt (diceAttributes .getDiceConnectionCreatedAt ());
17041711 diceConnection .setConnection (diceAuth .getDiceApiUrl () + "/web/connection/inviteurl/"
17051712 + diceAttributes .getDiceConnection ());
1713+ sendSlackNotification (diceAttributes .getHandle (), diceAttributes .getEmail (), "Reusing DICE connection" );
17061714 return ApiResponseFactory .createResponse (diceConnection );
17071715 }
17081716 }
@@ -1731,6 +1739,7 @@ public ApiResponse getDiceConnection(
17311739 diceConnection .setId (newId );
17321740 diceConnection .setConnection (diceAuth .getDiceApiUrl () + "/web/connection/inviteurl/" + connectionId );
17331741 diceConnection .setAccepted (false );
1742+ sendSlackNotification (diceAttributes .getHandle (), diceAttributes .getEmail (), "Created new DICE connection" );
17341743 return ApiResponseFactory .createResponse (diceConnection );
17351744 }
17361745
@@ -1847,6 +1856,7 @@ public ApiResponse issueCredentials(
18471856 response .getMessage ()));
18481857 }
18491858 userDao .updateDiceConnectionStatus (user .getDiceConnectionId (), true );
1859+ sendSlackNotification (user .getHandle (), user .getEmail (), "DICE connection accepted" );
18501860 return ApiResponseFactory .createResponse ("SUCCESS" );
18511861 }
18521862
@@ -2298,6 +2308,7 @@ public String getDomain() {
22982308
22992309 public void setDomain (String domain ) {
23002310 this .domain = domain ;
2311+ this .domainEnv = domain .toLowerCase ().contains ("dev" ) ? "DEV" : domain .toLowerCase ().contains ("qa" ) ? "QA" : "PROD" ;
23012312 }
23022313
23032314 public String getSendgridTemplateId () {
@@ -2455,6 +2466,21 @@ private void sendWelcomeEmailEvent(User user) {
24552466 logger .error ("Error occured while publishing the events to new kafka." );
24562467 }
24572468 }
2469+
2470+ private void sendSlackNotification (String handle , String email , String message ) {
2471+ ObjectMapper mapper = new ObjectMapper ();
2472+ ObjectNode body = mapper .createObjectNode ();
2473+ body .put ("channel" , diceAuth .getSlackChannelId ());
2474+ body .put ("text" , String .format ("[%s] %s%s : %s" , domainEnv , handle , email == null ? "" : String .format (" (%s)" , email ) , message ));
2475+ try {
2476+ new Request ("https://slack.com/api/chat.postMessage" , "POST" )
2477+ .header ("Authorization" , "Bearer " + diceAuth .getSlackKey ())
2478+ .json (mapper .writeValueAsString (body ))
2479+ .execute ();
2480+ } catch (Exception e ) {
2481+ logger .error ("Error when calling slack bot" , e );
2482+ }
2483+ }
24582484
24592485 protected NotificationPayload createActivationNotificationPayload (User user , String redirectUrl ) {
24602486 //If for Connect registration, send activation email with activation code only.
0 commit comments