mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
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:
@@ -615,9 +615,11 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
|
|
||||||
// set recipient
|
// 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)
|
if (to != null && to.length() != 0)
|
||||||
{
|
{
|
||||||
messageRef[0].setTo(to);
|
messageRef[0].setTo(to);
|
||||||
|
toRecipients = to;
|
||||||
|
|
||||||
// Note: there is no validation on the username to check that it actually is an email address.
|
// Note: there is no validation on the username to check that it actually is an email address.
|
||||||
// TODO Fix this.
|
// TODO Fix this.
|
||||||
@@ -778,6 +780,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
if(recipients.size() > 0)
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -925,7 +928,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build the email template model
|
// 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.
|
// Determine the locale to use to send the email.
|
||||||
Locale locale = recipient.getSecond();
|
Locale locale = recipient.getSecond();
|
||||||
@@ -1500,7 +1503,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
*
|
*
|
||||||
* @return Model map for email templates
|
* @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);
|
Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
|
||||||
|
|
||||||
@@ -1509,6 +1512,11 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
model.put("person", new TemplateNode(fromPerson, serviceRegistry, null));
|
model.put("person", new TemplateNode(fromPerson, serviceRegistry, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (toRecipents != null)
|
||||||
|
{
|
||||||
|
model.put("to", toRecipents);
|
||||||
|
}
|
||||||
|
|
||||||
if (ref != null)
|
if (ref != null)
|
||||||
{
|
{
|
||||||
model.put("document", new TemplateNode(ref, serviceRegistry, null));
|
model.put("document", new TemplateNode(ref, serviceRegistry, null));
|
||||||
|
@@ -792,17 +792,18 @@ public abstract class AbstractMailActionExecuterTest
|
|||||||
AUTHORITY_SERVICE.addAuthority(groupName, USER1);
|
AUTHORITY_SERVICE.addAuthority(groupName, USER1);
|
||||||
AUTHORITY_SERVICE.addAuthority(groupName, USER2);
|
AUTHORITY_SERVICE.addAuthority(groupName, USER2);
|
||||||
|
|
||||||
// Prepare email to be sent to group. Add also a template
|
// Create mail
|
||||||
final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
|
final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
|
||||||
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "some.body@example.com");
|
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "some.body@example.com");
|
||||||
mailAction.setParameterValue(MailActionExecuter.PARAM_TO_MANY, groupName);
|
mailAction.setParameterValue(MailActionExecuter.PARAM_TO_MANY, groupName);
|
||||||
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
|
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
|
||||||
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "Testing");
|
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "Testing");
|
||||||
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/test.txt.ftl");
|
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/testSentTo.txt.ftl");
|
||||||
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) getModel());
|
|
||||||
|
|
||||||
// Send email
|
RetryingTransactionHelper txHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
|
||||||
MimeMessage message = TRANSACTION_SERVICE.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<MimeMessage>()
|
|
||||||
|
// Send mail
|
||||||
|
MimeMessage message = txHelper.doInTransaction(new RetryingTransactionCallback<MimeMessage>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public MimeMessage execute() throws Throwable
|
public MimeMessage execute() throws Throwable
|
||||||
@@ -810,13 +811,12 @@ public abstract class AbstractMailActionExecuterTest
|
|||||||
ACTION_EXECUTER.executeImpl(mailAction, null);
|
ACTION_EXECUTER.executeImpl(mailAction, null);
|
||||||
return ACTION_EXECUTER.retrieveLastTestMessage();
|
return ACTION_EXECUTER.retrieveLastTestMessage();
|
||||||
}
|
}
|
||||||
});
|
}, true);
|
||||||
|
|
||||||
// Check that both users are displayed in TO field
|
// Check that both users are displayed in message body
|
||||||
Address[] addresses = message.getRecipients(Message.RecipientType.TO);
|
String recipients = USER1 + "@email.com" + "," + USER2 + "@email.com";
|
||||||
Assert.assertEquals("Expected both users to be in TO field", 2, addresses.length);
|
Assert.assertNotNull(message);
|
||||||
Assert.assertEquals(USER1 + "@email.com", addresses[0].toString());
|
Assert.assertEquals("This email was sent to " + recipients, (String) message.getContent());
|
||||||
Assert.assertEquals(USER2 + "@email.com", addresses[1].toString());
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
This email was sent to ${to}
|
Reference in New Issue
Block a user