]> WPIA git - gigi.git/commitdiff
upd: constrain API around Supported User.
authorFelix Dörre <felix@dogcraft.de>
Thu, 25 Aug 2016 22:00:19 +0000 (00:00 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 25 Aug 2016 23:09:47 +0000 (01:09 +0200)
Change-Id: I75c60ce9a3881d4ddf9153a8b7da9eb811045c96

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 e5daeb31bc0be4923418d595b006147068385f6b..6f013b1ab5e7da33dfd56a19a829db7e4833fe55 100644 (file)
@@ -1,9 +1,12 @@
 package org.cacert.gigi.dbObjects;
 
 import java.io.IOException;
 package org.cacert.gigi.dbObjects;
 
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.HashMap;
 import java.util.Locale;
 
 import java.util.HashMap;
 import java.util.Locale;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
@@ -11,6 +14,8 @@ 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.output.template.MailTemplate;
 import org.cacert.gigi.output.template.Outputable;
 import org.cacert.gigi.output.template.SprintfCommand;
+import org.cacert.gigi.output.template.TranslateCommand;
+import org.cacert.gigi.pages.PasswordResetPage;
 import org.cacert.gigi.util.DayDate;
 import org.cacert.gigi.util.ServerConstants;
 
 import org.cacert.gigi.util.DayDate;
 import org.cacert.gigi.util.ServerConstants;
 
@@ -34,6 +39,13 @@ public class SupportedUser {
         }
         writeSELog("SE dob change");
         target.setDoBAsSupport(dob);
         }
         writeSELog("SE dob change");
         target.setDoBAsSupport(dob);
+        String subject = "Change DoB Data";
+        // send notification to support
+        Outputable message = new TranslateCommand("The DoB was changed.");
+        sendSupportNotification(subject, message);
+        // send notification to user
+        message = SprintfCommand.createSimple("The DoB in your account was changed to {0}.", dob);
+        sendSupportUserNotification(subject, message);
         return true;
     }
 
         return true;
     }
 
@@ -46,6 +58,11 @@ public class SupportedUser {
                 certs[i].revoke();
             }
         }
                 certs[i].revoke();
             }
         }
+        // send notification to support
+        Outputable message = SprintfCommand.createSimple("All certificates in the account {0} <{1}> have been revoked.", target.getPreferredName().toString(), target.getEmail());
+        sendSupportNotification("Revoke certificates", message);
+        // send notification to user
+        sendSupportUserNotification("Revoke certificate", new TranslateCommand("All certificates in your account have been revoked."));
     }
 
     public void revokeCertificate(Certificate cert) throws GigiApiException {
     }
 
     public void revokeCertificate(Certificate cert) throws GigiApiException {
@@ -96,15 +113,29 @@ public class SupportedUser {
 
     public void grant(Group toMod) throws GigiApiException {
         target.grantGroup(supporter, toMod);
 
     public void grant(Group toMod) throws GigiApiException {
         target.grantGroup(supporter, toMod);
+        String subject = "Change Group Permissions";
+        // send notification to support
+        Outputable message = SprintfCommand.createSimple("The group permission '{0}' was granted.", toMod.getName());
+        sendSupportNotification(subject, message);
+        // send notification to user
+        message = SprintfCommand.createSimple("The group permission '{0}' was granted to your account.", toMod.getName());
+        sendSupportUserNotification(subject, message);
     }
 
     public void revoke(Group toMod) {
         target.revokeGroup(supporter, toMod);
     }
 
     public void revoke(Group toMod) {
         target.revokeGroup(supporter, toMod);
+        String subject = "Change Group Permissions";
+        // send notification to support
+        Outputable message = SprintfCommand.createSimple("The group permission '{0}' was revoked.", toMod.getName());
+        sendSupportNotification(subject, message);
+        // send notification to user
+        message = SprintfCommand.createSimple("The group permission '{0}' was revoked from your account.", toMod.getName());
+        sendSupportUserNotification(subject, message);
     }
 
     private static final MailTemplate supportNotification = new MailTemplate(SupportedUser.class.getResource("SupportNotificationMail.templ"));
 
     }
 
     private static final MailTemplate supportNotification = new MailTemplate(SupportedUser.class.getResource("SupportNotificationMail.templ"));
 
-    public void sendSupportNotification(String subject, Outputable message) {
+    private void sendSupportNotification(String subject, Outputable message) {
         try {
             HashMap<String, Object> vars = new HashMap<>();
             vars.put("supporter", supporter.getPreferredName().toString());
         try {
             HashMap<String, Object> vars = new HashMap<>();
             vars.put("supporter", supporter.getPreferredName().toString());
@@ -121,7 +152,7 @@ public class SupportedUser {
 
     private static final MailTemplate supportUserNotification = new MailTemplate(SupportedUser.class.getResource("SupportUserNotificationMail.templ"));
 
 
     private static final MailTemplate supportUserNotification = new MailTemplate(SupportedUser.class.getResource("SupportUserNotificationMail.templ"));
 
-    public void sendSupportUserNotification(String subject, Outputable message) {
+    private void sendSupportUserNotification(String subject, Outputable message) {
         try {
             HashMap<String, Object> vars = new HashMap<>();
             vars.put("action", message);
         try {
             HashMap<String, Object> vars = new HashMap<>();
             vars.put("action", message);
@@ -133,4 +164,13 @@ public class SupportedUser {
             e.printStackTrace();
         }
     }
             e.printStackTrace();
         }
     }
+
+    public void triggerPasswordReset(String aword, PrintWriter out, HttpServletRequest req) {
+        Language l = Language.getInstance(target.getPreferredLocale());
+        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, target, req, aword, l, method, subject);
+        Outputable message = new TranslateCommand("A password reset was triggered and an email was sent to user.");
+        sendSupportNotification(subject, message);
+    }
 }
 }
index 8c106dcb5d8d6bbd3cf5fdfd1e12e86dd2925cf7..9c1f3f5be3ae726cd98cab710ac1be4dcd41695c 100644 (file)
@@ -13,12 +13,9 @@ 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.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.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;
 
 public class SupportRevokeCertificatesForm extends Form {
 import org.cacert.gigi.output.template.Template;
 
 public class SupportRevokeCertificatesForm extends Form {
@@ -36,15 +33,6 @@ public class SupportRevokeCertificatesForm extends Form {
     public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
         if (user.getTicket() != null) {
             user.revokeAllCertificates();
     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 = 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;
             return true;
         }
         return false;
index 5738203661cb504326a19898e45f3905ed9d48d1..ac7ffd00bb68e69b22478c7fc378ed9215d5d482 100644 (file)
@@ -17,11 +17,7 @@ import org.cacert.gigi.output.DateSelector;
 import org.cacert.gigi.output.GroupIterator;
 import org.cacert.gigi.output.GroupSelector;
 import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.GroupIterator;
 import org.cacert.gigi.output.GroupSelector;
 import org.cacert.gigi.output.template.Form;
-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.Template;
-import org.cacert.gigi.output.template.TranslateCommand;
-import org.cacert.gigi.pages.PasswordResetPage;
 
 public class SupportUserDetailsForm extends Form {
 
 
 public class SupportUserDetailsForm extends Form {
 
@@ -50,21 +46,11 @@ public class SupportUserDetailsForm extends Form {
         if (req.getParameter("addGroup") != null || req.getParameter("removeGroup") != null) {
             value.update(req);
             Group toMod = value.getGroup();
         if (req.getParameter("addGroup") != null || req.getParameter("removeGroup") != null) {
             value.update(req);
             Group toMod = value.getGroup();
-            boolean grant;
             if (req.getParameter("addGroup") != null) {
             if (req.getParameter("addGroup") != null) {
-                grant = true;
                 user.grant(toMod);
             } else {
                 user.grant(toMod);
             } else {
-                grant = false;
                 user.revoke(toMod);
             }
                 user.revoke(toMod);
             }
-            String subject = "Change Group Permissions";
-            // 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) {
             return true;
         }
         if (req.getParameter("resetPass") != null) {
@@ -72,12 +58,7 @@ public class SupportUserDetailsForm extends Form {
             if (aword == null || aword.equals("")) {
                 throw new GigiApiException("An A-Word is required to perform a password reset.");
             }
             if (aword == null || aword.equals("")) {
                 throw new GigiApiException("An A-Word is required to perform a password reset.");
             }
-            Language l = Language.getInstance(user.getTargetUser().getPreferredLocale());
-            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);
+            user.triggerPasswordReset(aword, out, req);
             return true;
         }
         dobSelector.update(req);
             return true;
         }
         dobSelector.update(req);
@@ -85,14 +66,6 @@ public class SupportUserDetailsForm extends Form {
             throw new GigiApiException("Invalid date of birth!");
         }
         user.setDob(dobSelector.getDate());
             throw new GigiApiException("Invalid date of birth!");
         }
         user.setDob(dobSelector.getDate());
-
-        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;
     }
 
         return true;
     }