From 6d1b746247f6e1eab7d1da17112beb9cf5abb089 Mon Sep 17 00:00:00 2001 From: INOPIAE Date: Sun, 28 Aug 2016 08:05:10 +0200 Subject: [PATCH] add: notify board if a support role is granted or removed The board mailing address needs to be defined in the future to the email address for the recipient defined. Change-Id: Id19ac9023aa199981f91cdcb25a63d26f5af5173 --- .../cacert/gigi/dbObjects/SupportedUser.java | 25 +++++++++++ src/org/cacert/gigi/util/ServerConstants.java | 4 ++ .../admin/TestSEAdminNotificationMail.java | 42 ++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/org/cacert/gigi/dbObjects/SupportedUser.java b/src/org/cacert/gigi/dbObjects/SupportedUser.java index 18bfbee2..940e67fc 100644 --- a/src/org/cacert/gigi/dbObjects/SupportedUser.java +++ b/src/org/cacert/gigi/dbObjects/SupportedUser.java @@ -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 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(); + } + } } diff --git a/src/org/cacert/gigi/util/ServerConstants.java b/src/org/cacert/gigi/util/ServerConstants.java index 09317c3e..21bbce98 100644 --- a/src/org/cacert/gigi/util/ServerConstants.java +++ b/src/org/cacert/gigi/util/ServerConstants.java @@ -94,4 +94,8 @@ public class ServerConstants { return "support@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", ""); } + public static String getBoardMailAddress() { + return "board@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", ""); + } + } diff --git a/tests/org/cacert/gigi/pages/admin/TestSEAdminNotificationMail.java b/tests/org/cacert/gigi/pages/admin/TestSEAdminNotificationMail.java index dac9053e..e0ca8289 100644 --- a/tests/org/cacert/gigi/pages/admin/TestSEAdminNotificationMail.java +++ b/tests/org/cacert/gigi/pages/admin/TestSEAdminNotificationMail.java @@ -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()); + + // 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()); + + // 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()); + 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()); + 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 -- 2.39.2