]> WPIA git - gigi.git/commitdiff
add: send notification to support and user after support actions
authorINOPIAE <m.maengel@inopiae.de>
Tue, 23 Aug 2016 16:43:31 +0000 (18:43 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 25 Aug 2016 08:35:52 +0000 (10:35 +0200)
notifications will be send to support and the user after revoking
certificates, changing DoB and support groups

Change-Id: Iccdcb2799fa617a98b140bbfe9531a882e61b1ae

src/org/cacert/gigi/dbObjects/SupportUserNotificationMail.templ [new file with mode: 0644]
src/org/cacert/gigi/dbObjects/SupportedUser.java
src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.java
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.java
tests/org/cacert/gigi/pages/admin/TestSEAdminNotificationMail.java

diff --git a/src/org/cacert/gigi/dbObjects/SupportUserNotificationMail.templ b/src/org/cacert/gigi/dbObjects/SupportUserNotificationMail.templ
new file mode 100644 (file)
index 0000000..6b69f18
--- /dev/null
@@ -0,0 +1,7 @@
+Subject: [<?=$ticket?>] Support action: <?=$subject?>
+
+<?=_Hi?>,
+
+<?=_support triggered:?>
+
+<?=$action?>
index a4a3ba121e2c7dbab18d1646a46f9a2575138bbc..e5daeb31bc0be4923418d595b006147068385f6b 100644 (file)
@@ -10,6 +10,7 @@ import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.MailTemplate;
 import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.SprintfCommand;
 import org.cacert.gigi.util.DayDate;
 import org.cacert.gigi.util.ServerConstants;
 
@@ -53,6 +54,14 @@ public class SupportedUser {
         if (cert.getStatus() == CertificateStatus.ISSUED) {
             writeSELog("SE Revoke certificate");
             cert.revoke().waitFor(60000);
+            // send notification to support
+            String subject = "Revoke certificate";
+            Outputable message = SprintfCommand.createSimple("Certificate with serial number {0} for {1} <{2}>, has been revoked.", cert.getSerial(), target.getPreferredName().toString(), target.getEmail());
+            sendSupportNotification(subject, message);
+            // send notification to user
+            subject = "Revoke certificate";
+            message = SprintfCommand.createSimple("Certificate with serial number {0} with subject distinguished name {1} has been revoked.", cert.getSerial(), cert.getDistinguishedName());
+            sendSupportUserNotification(subject, message);
         }
     }
 
@@ -109,4 +118,19 @@ public class SupportedUser {
             e.printStackTrace();
         }
     }
+
+    private static final MailTemplate supportUserNotification = new MailTemplate(SupportedUser.class.getResource("SupportUserNotificationMail.templ"));
+
+    public void sendSupportUserNotification(String subject, Outputable message) {
+        try {
+            HashMap<String, Object> vars = new HashMap<>();
+            vars.put("action", message);
+            vars.put("ticket", this.getTicket());
+            vars.put("subject", subject);
+
+            supportUserNotification.sendMail(Language.getInstance(Locale.ENGLISH), vars, target.getEmail());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }
index ff64c6f5b1d3d10e5b70aa6c4ca1c10097c4bf6b..8c106dcb5d8d6bbd3cf5fdfd1e12e86dd2925cf7 100644 (file)
@@ -13,12 +13,13 @@ import org.cacert.gigi.dbObjects.Certificate;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
 import org.cacert.gigi.dbObjects.CertificateProfile;
 import org.cacert.gigi.dbObjects.SupportedUser;
+import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.template.IterableDataset;
 import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.SprintfCommand;
 import org.cacert.gigi.output.template.Template;
-import org.cacert.gigi.output.template.TranslateCommand;
 
 public class SupportRevokeCertificatesForm extends Form {
 
@@ -35,9 +36,15 @@ public class SupportRevokeCertificatesForm extends Form {
     public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
         if (user.getTicket() != null) {
             user.revokeAllCertificates();
+            User target = user.getTargetUser();
+            // send notification to support
             String subject = "Revoke certificates";
-            Outputable message = new TranslateCommand("All certificates in the account have been revoked.");
+            Outputable message = SprintfCommand.createSimple("All certificates in the account {0} <{1}> have been revoked.", target.getPreferredName().toString(), target.getEmail());
             user.sendSupportNotification(subject, message);
+            // send notification to user
+            subject = "Revoke certificate";
+            message = SprintfCommand.createSimple("All certificates in your account have been revoked.");
+            user.sendSupportUserNotification(subject, message);
             return true;
         }
         return false;
index ccfb3cc75518886ef8ec86f2bc7939f0aabcd01b..5738203661cb504326a19898e45f3905ed9d48d1 100644 (file)
@@ -48,18 +48,23 @@ public class SupportUserDetailsForm extends Form {
             throw new GigiApiException("More than one action requested!");
         }
         if (req.getParameter("addGroup") != null || req.getParameter("removeGroup") != null) {
-            String actionType = "granted";
             value.update(req);
             Group toMod = value.getGroup();
+            boolean grant;
             if (req.getParameter("addGroup") != null) {
+                grant = true;
                 user.grant(toMod);
             } else {
-                actionType = "revoked";
+                grant = false;
                 user.revoke(toMod);
             }
             String subject = "Change Group Permissions";
-            Outputable message = SprintfCommand.createSimple("The group permission {0} was {1}.", toMod.getDatabaseName(), actionType);
+            // send notification to support
+            Outputable message = SprintfCommand.createSimple(grant ? "The group permission '{0}' was granted." : "The group permission '{0}' was revoked.", toMod.getName());
             user.sendSupportNotification(subject, message);
+            // send notification to user
+            message = SprintfCommand.createSimple(grant ? "The group permission '{0}' was granted to your account." : "The group permission '{0}' was revoked from your account.", toMod.getName());
+            user.sendSupportUserNotification(subject, message);
             return true;
         }
         if (req.getParameter("resetPass") != null) {
@@ -81,9 +86,13 @@ public class SupportUserDetailsForm extends Form {
         }
         user.setDob(dobSelector.getDate());
 
-        String subject = "Change Account Data";
-        Outputable message = new TranslateCommand("The account data was changed.");
+        String subject = "Change DoB Data";
+        // send notification to support
+        Outputable message = new TranslateCommand("The DoB was changed.");
         user.sendSupportNotification(subject, message);
+        // send notification to user
+        message = SprintfCommand.createSimple("The DoB in your account was changed to {0}.", dobSelector.getDate());
+        user.sendSupportUserNotification(subject, message);
         return true;
     }
 
index c51e5cc46a6ae1aa31aeab212d22b6dd4c7ef9da..dac9053e0eb1dd01da52eb3cddd502c053e77924 100644 (file)
@@ -4,10 +4,17 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.net.MalformedURLException;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Locale;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Group;
+import org.cacert.gigi.dbObjects.User;
+import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage;
 import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage;
 import org.cacert.gigi.testUtils.ClientTest;
@@ -35,10 +42,13 @@ public class TestSEAdminNotificationMail extends ClientTest {
 
         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "dobd=1&dobm=2&doby=2000&detailupdate", 0);
 
+        // mail to support
         String message = getMailReceiver().receive().getMessage();
-        assertThat(message, containsString("The account data was changed."));
+        assertThat(message, containsString("The DoB was changed"));
         assertThat(message, containsString("supporter " + u.getPreferredName().toString() + " triggered:"));
-
+        // mail to user
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("The DoB in your account was changed to 2000-02-01."));
     }
 
     @Test
@@ -54,26 +64,46 @@ public class TestSEAdminNotificationMail extends ClientTest {
 
     @Test
     public void testGrantUserGroup() throws MalformedURLException, IOException {
-        executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "addGroup&groupToModify=supporter", 0);
+        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>());
 
+        // mail to support
         String message = getMailReceiver().receive().getMessage();
-        assertThat(message, containsString("The group permission supporter was granted."));
+        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=supporter", 0);
+        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>());
+
+        // mail to support
         String message = getMailReceiver().receive().getMessage();
-        assertThat(message, containsString("The group permission supporter was revoked."));
+        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 testRevokeCertificates() throws MalformedURLException, IOException {
+    public void testRevokeAllCertificates() throws MalformedURLException, IOException {
         executeBasicWebInteraction(cookie, SupportUserDetailsPage.PATH + targetID + "/", "revokeall", 1);
+        User user = User.getById(targetID);
 
+        // mail to support
         String message = getMailReceiver().receive().getMessage();
-        assertThat(message, containsString("All certificates in the account have been revoked."));
-
+        assertThat(message, containsString("All certificates in the account " + user.getPreferredName().toString()));
+        // mail to user
+        message = getMailReceiver().receive().getMessage();
+        assertThat(message, containsString("All certificates in your account have been revoked."));
     }
 }