// 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) {
// 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"));
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();
+ }
+ }
}
@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();
// 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();
// 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