]> WPIA git - gigi.git/commitdiff
add: notify board if a support role is granted or removed
authorINOPIAE <m.maengel@inopiae.de>
Sun, 28 Aug 2016 06:05:10 +0000 (08:05 +0200)
committerINOPIAE <m.maengel@inopiae.de>
Sun, 28 Aug 2016 06:28:14 +0000 (08:28 +0200)
The board mailing address needs to be defined in the future to the email
address for the recipient defined.

Change-Id: Id19ac9023aa199981f91cdcb25a63d26f5af5173

src/org/cacert/gigi/dbObjects/SupportedUser.java
src/org/cacert/gigi/util/ServerConstants.java
tests/org/cacert/gigi/pages/admin/TestSEAdminNotificationMail.java

index 18bfbee21fe345dbce3c3be8c640bbec0d05e72a..940e67fc89b689c7bfa8e8e2ecdda5100fbab81d 100644 (file)
@@ -120,6 +120,11 @@ public class SupportedUser {
         // send notification to user
         message = SprintfCommand.createSimple("The group permission '{0}' was granted to your account.", toMod.getName());
         sendSupportUserNotification(subject, message);
+        if (toMod == Group.SUPPORTER) {
+            subject = "Support role granted";
+            message = SprintfCommand.createSimple("The group permission '{0}' was granted for '{1}'.", toMod.getName(), target.getPreferredName().toString());
+            sendBoardNotification(subject, message);
+        }
     }
 
     public void revoke(Group toMod) {
@@ -131,6 +136,11 @@ public class SupportedUser {
         // send notification to user
         message = SprintfCommand.createSimple("The group permission '{0}' was revoked from your account.", toMod.getName());
         sendSupportUserNotification(subject, message);
+        if (toMod == Group.SUPPORTER) {
+            subject = "Support role revoked";
+            message = SprintfCommand.createSimple("The group permission '{0}' was revoked for '{1}'.", toMod.getName(), target.getPreferredName().toString());
+            sendBoardNotification(subject, message);
+        }
     }
 
     private static final MailTemplate supportNotification = new MailTemplate(SupportedUser.class.getResource("SupportNotificationMail.templ"));
@@ -173,4 +183,19 @@ public class SupportedUser {
         Outputable message = new TranslateCommand("A password reset was triggered and an email was sent to user.");
         sendSupportNotification(subject, message);
     }
+
+    private void sendBoardNotification(String subject, Outputable message) {
+        try {
+            HashMap<String, Object> vars = new HashMap<>();
+            vars.put("supporter", supporter.getPreferredName().toString());
+            vars.put("action", message);
+            vars.put("ticket", this.getTicket());
+            vars.put("subject", subject);
+
+            String boardemailaddress = ServerConstants.getBoardMailAddress();
+            supportNotification.sendMail(Language.getInstance(Locale.ENGLISH), vars, boardemailaddress);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }
index 09317c3ec643f8c53dfc16b3b27309b4b7ac2883..21bbce98f63e9f439f04e96d5415a79e04e874c9 100644 (file)
@@ -94,4 +94,8 @@ public class ServerConstants {
         return "support@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
     }
 
+    public static String getBoardMailAddress() {
+        return "board@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
+    }
+
 }
index dac9053e0eb1dd01da52eb3cddd502c053e77924..e0ca82897d553271bc967d3fbfc8ea27e0b1163d 100644 (file)
@@ -64,11 +64,44 @@ public class TestSEAdminNotificationMail extends ClientTest {
 
     @Test
     public void testGrantUserGroup() throws MalformedURLException, IOException {
+        executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=" + URLEncoder.encode(Group.CODESIGNING.getDatabaseName(), "UTF-8"), 0);
+
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+
+        // mail to support
+        String message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted."));
+        // mail to user
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
+    }
+
+    @Test
+    public void testRemoveUserGroup() throws MalformedURLException, IOException {
+        executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.CODESIGNING.getDatabaseName(), "UTF-8"), 0);
+
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        Group.CODESIGNING.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+
+        // mail to support
+        String message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked."));
+        // mail to user
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
+    }
+
+    @Test
+    public void testGrantSupporterGroup() throws MalformedURLException, IOException {
         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDatabaseName(), "UTF-8"), 0);
 
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         Group.SUPPORTER.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+        User target = User.getById(targetID);
 
         // mail to support
         String message = getMailReceiver().receive().getMessage();
@@ -76,15 +109,19 @@ public class TestSEAdminNotificationMail extends ClientTest {
         // mail to user
         message = getMailReceiver().receive().getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted to your account."));
+        // mail to board
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was granted for '" + target.getPreferredName().toString() + "'."));
     }
 
     @Test
-    public void testRemoveUserGroup() throws MalformedURLException, IOException {
+    public void testRemoveSupporterGroup() throws MalformedURLException, IOException {
         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "removeGroup&groupToModify=" + URLEncoder.encode(Group.SUPPORTER.getDatabaseName(), "UTF-8"), 0);
 
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         Group.SUPPORTER.getName().output(pw, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+        User target = User.getById(targetID);
 
         // mail to support
         String message = getMailReceiver().receive().getMessage();
@@ -92,6 +129,9 @@ public class TestSEAdminNotificationMail extends ClientTest {
         // mail to user
         message = getMailReceiver().receive().getMessage();
         assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked from your account."));
+        // mail to board
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The group permission '" + sw.toString() + "' was revoked for '" + target.getPreferredName().toString() + "'."));
     }
 
     @Test