REPO-2868 / MNT-17970: List of recipients is not available in model in MailActionExecuter.when sending to groups

- added the "to" parameter to the Email Template Model. The list of persons to which the email is sent will be displayed in the email body if the template is configured to do so
     - added a Junit for the case where the email is sent to a group
This commit is contained in:
Andrei Forascu
2017-09-12 16:23:36 +03:00
parent 7e8ab7a777
commit ec93521c15
3 changed files with 27 additions and 18 deletions

View File

@@ -614,11 +614,13 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
}
// set recipient
String to = (String)ruleAction.getParameterValue(PARAM_TO);
String to = (String)ruleAction.getParameterValue(PARAM_TO);
String toRecipients = null;
if (to != null && to.length() != 0)
{
messageRef[0].setTo(to);
toRecipients = to;
// Note: there is no validation on the username to check that it actually is an email address.
// TODO Fix this.
@@ -777,7 +779,8 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
if(recipients.size() > 0)
{
messageRef[0].setTo(recipients.toArray(new String[recipients.size()]));
messageRef[0].setTo(recipients.toArray(new String[recipients.size()]));
toRecipients = String.join(",", recipients);
}
else
{
@@ -925,7 +928,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
}
// build the email template model
Map<String, Object> model = createEmailTemplateModel(actionedUponNodeRef, suppliedModel, fromPerson);
Map<String, Object> model = createEmailTemplateModel(actionedUponNodeRef, suppliedModel, fromPerson, toRecipients);
// Determine the locale to use to send the email.
Locale locale = recipient.getSecond();
@@ -1500,15 +1503,20 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
*
* @return Model map for email templates
*/
private Map<String, Object> createEmailTemplateModel(NodeRef ref, Map<String, Object> suppliedModel, NodeRef fromPerson)
private Map<String, Object> createEmailTemplateModel(NodeRef ref, Map<String, Object> suppliedModel, NodeRef fromPerson, String toRecipents)
{
Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
if (fromPerson != null)
{
model.put("person", new TemplateNode(fromPerson, serviceRegistry, null));
}
}
if (toRecipents != null)
{
model.put("to", toRecipents);
}
if (ref != null)
{
model.put("document", new TemplateNode(ref, serviceRegistry, null));