@@ -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 ;
@@ -1337,6 +1339,7 @@ public ApiResponse updateStatus(
13371339 if (MemberStatus .UNVERIFIED == MemberStatus .getByValue (oldStatus ) &&
13381340 MemberStatus .ACTIVE == MemberStatus .getByValue (user .getStatus ())) {
13391341 notifyWelcome (userInDB );
1342+ assignDefaultUserRole (userInDB );
13401343 }
13411344
13421345 return ApiResponseFactory .createResponse (userInDB );
@@ -1648,11 +1651,14 @@ public ApiResponse updateUser2fa(
16481651 throw new APIRuntimeException (SC_BAD_REQUEST , "You have multiple accounts registered with same email. Please contact with support." );
16491652 }
16501653 }
1654+ Boolean oldMfaStatus = user2faInDb .getMfaEnabled () == null ? false : user2faInDb .getMfaEnabled ();
1655+ Boolean oldDiceStatus = user2faInDb .getDiceEnabled () == null ? false : user2faInDb .getDiceEnabled ();
1656+ String handle = user2faInDb .getHandle ();
16511657 if (user2fa .getMfaEnabled () == null ) {
1652- user2fa .setMfaEnabled (user2faInDb . getMfaEnabled () == null ? false : user2faInDb . getMfaEnabled () );
1658+ user2fa .setMfaEnabled (oldMfaStatus );
16531659 }
16541660 if (user2fa .getDiceEnabled () == null ) {
1655- user2fa .setDiceEnabled (user2faInDb . getDiceEnabled () == null ? false : user2faInDb . getDiceEnabled () );
1661+ user2fa .setDiceEnabled (oldDiceStatus );
16561662 }
16571663 if (user2faInDb .getId () == null ) {
16581664 long newId = userDao .insertUser2fa (userId , user2fa .getMfaEnabled (), user2fa .getDiceEnabled (),
@@ -1664,6 +1670,9 @@ public ApiResponse updateUser2fa(
16641670 user2fa .getDiceEnabled (), Utils .toLongValue (authUser .getUserId ()));
16651671 user2faInDb = userDao .findUser2faById (user2faInDb .getId ());
16661672 }
1673+ if (!oldDiceStatus .equals (user2faInDb .getDiceEnabled ())) {
1674+ sendSlackNotification (handle , null , user2faInDb .getDiceEnabled () ? "DICE enabled :smile_cat:" : "DICE disabled :crying_cat_face:" );
1675+ }
16671676 return ApiResponseFactory .createResponse (user2faInDb );
16681677 }
16691678
@@ -1702,6 +1711,7 @@ public ApiResponse getDiceConnection(
17021711 diceConnection .setCreatedAt (diceAttributes .getDiceConnectionCreatedAt ());
17031712 diceConnection .setConnection (diceAuth .getDiceApiUrl () + "/web/connection/inviteurl/"
17041713 + diceAttributes .getDiceConnection ());
1714+ sendSlackNotification (diceAttributes .getHandle (), diceAttributes .getEmail (), "Reusing DICE connection" );
17051715 return ApiResponseFactory .createResponse (diceConnection );
17061716 }
17071717 }
@@ -1730,6 +1740,7 @@ public ApiResponse getDiceConnection(
17301740 diceConnection .setId (newId );
17311741 diceConnection .setConnection (diceAuth .getDiceApiUrl () + "/web/connection/inviteurl/" + connectionId );
17321742 diceConnection .setAccepted (false );
1743+ sendSlackNotification (diceAttributes .getHandle (), diceAttributes .getEmail (), "Created new DICE connection" );
17331744 return ApiResponseFactory .createResponse (diceConnection );
17341745 }
17351746
@@ -1846,6 +1857,7 @@ public ApiResponse issueCredentials(
18461857 response .getMessage ()));
18471858 }
18481859 userDao .updateDiceConnectionStatus (user .getDiceConnectionId (), true );
1860+ sendSlackNotification (user .getHandle (), user .getEmail (), "DICE connection accepted" );
18491861 return ApiResponseFactory .createResponse ("SUCCESS" );
18501862 }
18511863
@@ -2297,6 +2309,7 @@ public String getDomain() {
22972309
22982310 public void setDomain (String domain ) {
22992311 this .domain = domain ;
2312+ this .domainEnv = domain .toLowerCase ().contains ("dev" ) ? "DEV" : domain .toLowerCase ().contains ("qa" ) ? "QA" : "PROD" ;
23002313 }
23012314
23022315 public String getSendgridTemplateId () {
@@ -2454,6 +2467,21 @@ private void sendWelcomeEmailEvent(User user) {
24542467 logger .error ("Error occured while publishing the events to new kafka." );
24552468 }
24562469 }
2470+
2471+ private void sendSlackNotification (String handle , String email , String message ) {
2472+ ObjectMapper mapper = new ObjectMapper ();
2473+ ObjectNode body = mapper .createObjectNode ();
2474+ body .put ("channel" , diceAuth .getSlackChannelId ());
2475+ body .put ("text" , String .format ("[%s] %s%s : %s" , domainEnv , handle , email == null ? "" : String .format (" (%s)" , email ) , message ));
2476+ try {
2477+ new Request ("https://slack.com/api/chat.postMessage" , "POST" )
2478+ .header ("Authorization" , "Bearer " + diceAuth .getSlackKey ())
2479+ .json (mapper .writeValueAsString (body ))
2480+ .execute ();
2481+ } catch (Exception e ) {
2482+ logger .error ("Error when calling slack bot" , e );
2483+ }
2484+ }
24572485
24582486 protected NotificationPayload createActivationNotificationPayload (User user , String redirectUrl ) {
24592487 //If for Connect registration, send activation email with activation code only.
0 commit comments