]> WPIA git - gigi.git/commitdiff
add: send mail notification to support after support action
authorINOPIAE <m.maengel@inopiae.de>
Thu, 14 Jul 2016 06:29:34 +0000 (08:29 +0200)
committerFelix Dörre <felix@dogcraft.de>
Mon, 18 Jul 2016 11:43:01 +0000 (13:43 +0200)
fixes issue #66

Change-Id: I2a29924f9754f68e0d7c470d3b99480774b70382

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

index df5b54e88d0c5d5753c7bcfa4c4acf2ae3390dad..7affe34caa18c35625e8a0cff56ab02d10248469 100644 (file)
@@ -1,9 +1,20 @@
 package org.cacert.gigi.dbObjects;
 
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Locale;
+
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
+import org.cacert.gigi.email.SendMail;
+import org.cacert.gigi.localisation.Language;
+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;
 
 public class SupportedUser {
 
@@ -89,4 +100,21 @@ public class SupportedUser {
         target.revokeGroup(supporter, toMod);
     }
 
+    public void sendSupportNotification(String subject, Outputable message) {
+        try {
+            StringWriter sw = new StringWriter();
+            PrintWriter outMail = new PrintWriter(sw);
+            outMail.print("Hi," + "\n\n");
+            SprintfCommand.createSimple("supporter {0} triggered:", supporter.getName().toString()).output(outMail, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+            outMail.print("\n\n");
+            message.output(outMail, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
+            outMail.print("\n\n");
+            outMail.print("RA DB");
+            outMail.close();
+            String supportemailaddress = "support@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
+            SendMail.getInstance().sendMail(supportemailaddress, "[" + this.getTicket() + "] RA DB " + subject, sw.toString(), supportemailaddress, null, null, null, null, false);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }
index 9c1f3f5be3ae726cd98cab710ac1be4dcd41695c..ff64c6f5b1d3d10e5b70aa6c4ca1c10097c4bf6b 100644 (file)
@@ -16,7 +16,9 @@ import org.cacert.gigi.dbObjects.SupportedUser;
 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.Template;
+import org.cacert.gigi.output.template.TranslateCommand;
 
 public class SupportRevokeCertificatesForm extends Form {
 
@@ -33,6 +35,9 @@ public class SupportRevokeCertificatesForm extends Form {
     public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
         if (user.getTicket() != null) {
             user.revokeAllCertificates();
+            String subject = "Revoke certificates";
+            Outputable message = new TranslateCommand("All certificates in the account have been revoked.");
+            user.sendSupportNotification(subject, message);
             return true;
         }
         return false;
index 15ed2818ba6b76cc2b113718e725af4d532f5525..75173e06a8ff6534b22fbad327a947cce88cb742 100644 (file)
@@ -17,7 +17,10 @@ import org.cacert.gigi.output.DateSelector;
 import org.cacert.gigi.output.GroupSelector;
 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;
 import org.cacert.gigi.pages.PasswordResetPage;
 
 public class SupportUserDetailsForm extends Form {
@@ -45,13 +48,18 @@ public class SupportUserDetailsForm extends Form {
             throw new GigiApiException("More than one action requested!");
         }
         if (req.getParameter("grant") != null || req.getParameter("deny") != null) {
+            String actionType = "granted";
             value.update(req);
             Group toMod = value.getGroup();
             if (req.getParameter("grant") != null) {
                 user.grant(toMod);
             } else {
+                actionType = "revoked";
                 user.revoke(toMod);
             }
+            String subject = "Change Group Permissions";
+            Outputable message = SprintfCommand.createSimple("The group permission {0} was {1}.", toMod.getDatabaseName(), actionType);
+            user.sendSupportNotification(subject, message);
             return true;
         }
         if (req.getParameter("resetPass") != null) {
@@ -63,6 +71,8 @@ public class SupportUserDetailsForm extends Form {
             String method = l.getTranslation("A password reset was triggered. Please enter the required text sent to you by support on this page:");
             String subject = l.getTranslation("Password reset by support.");
             PasswordResetPage.initPasswordResetProcess(out, user.getTargetUser(), req, aword, l, method, subject);
+            Outputable message = new TranslateCommand("A password reset was triggered and an email was sent to user.");
+            user.sendSupportNotification(subject, message);
             return true;
         }
         dobSelector.update(req);
@@ -82,6 +92,9 @@ public class SupportUserDetailsForm extends Form {
                 user.submitSupportAction();
             }
         }
+        String subject = "Change Account Data";
+        Outputable message = new TranslateCommand("The account data was changed.");
+        user.sendSupportNotification(subject, message);
         return true;
     }