mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
129048 cpopa: SHA-1627 : CLONE - Create email template - Hooked a new step into the invite moderated workflow, so as to notify by email all site managers of site join requests. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -653,6 +653,12 @@
|
|||||||
<prop key="messages">alfresco/messages/bootstrap-spaces</prop>
|
<prop key="messages">alfresco/messages/bootstrap-spaces</prop>
|
||||||
</props>
|
</props>
|
||||||
|
|
||||||
|
<props>
|
||||||
|
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.templates.email.childname}/${spaces.templates.email.invite.childname}</prop>
|
||||||
|
<prop key="location">alfresco/templates/invite-moderated-email-templates.xml</prop>
|
||||||
|
<prop key="messages">alfresco/messages/bootstrap-spaces</prop>
|
||||||
|
</props>
|
||||||
|
|
||||||
<props>
|
<props>
|
||||||
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.templates.email.childname}/${spaces.templates.email.notify.childname}</prop>
|
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.templates.email.childname}/${spaces.templates.email.notify.childname}</prop>
|
||||||
<prop key="location">alfresco/templates/notify_email_templates.xml</prop>
|
<prop key="location">alfresco/templates/notify_email_templates.xml</prop>
|
||||||
|
@@ -109,4 +109,7 @@
|
|||||||
<bean id="SendNominatedInviteAddDirectDelegate" parent="baseInvitationDelegate"
|
<bean id="SendNominatedInviteAddDirectDelegate" parent="baseInvitationDelegate"
|
||||||
class="org.alfresco.repo.invitation.activiti.SendNominatedInviteAddDirectDelegate" />
|
class="org.alfresco.repo.invitation.activiti.SendNominatedInviteAddDirectDelegate" />
|
||||||
|
|
||||||
|
<bean id="SendModeratedInviteDelegate" parent="baseInvitationDelegate"
|
||||||
|
class="org.alfresco.repo.invitation.activiti.SendModeratedInviteDelegate" />
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -104,6 +104,8 @@ spaces.templates.email.notify.description=Notify Email Templates
|
|||||||
spaces.templates.email.generate_the_invite_email.description=Email template used to generate the invite email for Alfresco Share
|
spaces.templates.email.generate_the_invite_email.description=Email template used to generate the invite email for Alfresco Share
|
||||||
spaces.templates.email.generate_the_invite_email_add_direct.description=Email template used to generate the user added to site email for Alfresco Share
|
spaces.templates.email.generate_the_invite_email_add_direct.description=Email template used to generate the user added to site email for Alfresco Share
|
||||||
|
|
||||||
|
spaces.templates.email.generate_the_invite_email_moderated.description=Email template used to generate the request to join site email for Alfresco Share
|
||||||
|
|
||||||
spaces.templates.email.generate_the_wf_notification_email.description=Email template for notifying users of new a workflow task
|
spaces.templates.email.generate_the_wf_notification_email.description=Email template for notifying users of new a workflow task
|
||||||
|
|
||||||
email.template.email_template_for_notifying_users=Email template for notifying users from a rule or action
|
email.template.email_template_for_notifying_users=Email template for notifying users from a rule or action
|
||||||
|
@@ -23,6 +23,8 @@ invitation.invitesender.email.role.SiteConsumer=Site Consumer
|
|||||||
|
|
||||||
invitation.invitesender.emailAddDirect.subject=Alfresco {0}: You have been added to the {1} site
|
invitation.invitesender.emailAddDirect.subject=Alfresco {0}: You have been added to the {1} site
|
||||||
|
|
||||||
|
invitation.moderated.email.subject=A new user wants to join {0}
|
||||||
|
|
||||||
# Invitation workflow task description
|
# Invitation workflow task description
|
||||||
invitation.nominated.workflow.description=Invitation to join {0} site
|
invitation.nominated.workflow.description=Invitation to join {0} site
|
||||||
invitation.moderated.workflow.description=Request to join {0} site
|
invitation.moderated.workflow.description=Request to join {0} site
|
||||||
|
@@ -84,3 +84,10 @@ templates.invite-email-add-direct.html.navigate=Go to {0}
|
|||||||
templates.invite-email-add-direct.html.closing=Sincerely,<br />Alfresco {0}
|
templates.invite-email-add-direct.html.closing=Sincerely,<br />Alfresco {0}
|
||||||
templates.invite-email-add-direct.html.leave=<span>Don''t want to be a part of this site?</span><br/><a href=\"{0}\">Leave site</a>
|
templates.invite-email-add-direct.html.leave=<span>Don''t want to be a part of this site?</span><br/><a href=\"{0}\">Leave site</a>
|
||||||
templates.invite-email-add-direct.html.alfresco_info=To find out more about Alfresco {0} visit <a href=\"http://www.alfresco.com\">http://www.alfresco.com</a>
|
templates.invite-email-add-direct.html.alfresco_info=To find out more about Alfresco {0} visit <a href=\"http://www.alfresco.com\">http://www.alfresco.com</a>
|
||||||
|
|
||||||
|
#invite-email-moderated.ftl
|
||||||
|
templates.invite-email-moderated.html.header=A new user wants to join ''{0}''
|
||||||
|
templates.invite-email-moderated.html.info={0} requested to join the ''{1}'' site on {2}.
|
||||||
|
templates.invite-email-moderated.html.see_pending=See Pending Requests
|
||||||
|
|
||||||
|
templates.invite-email.html.salutation_generic=Hi,
|
||||||
|
@@ -0,0 +1,80 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body bgcolor="#dddddd">
|
||||||
|
<table width="100%" cellpadding="20" cellspacing="0" border="0" bgcolor="#dddddd">
|
||||||
|
<tr>
|
||||||
|
<td width="100%" align="center">
|
||||||
|
<table width="70%" cellpadding="0" cellspacing="0" bgcolor="white" style="background-color: white; border: 1px solid #aaaaaa;">
|
||||||
|
<tr>
|
||||||
|
<td width="100%">
|
||||||
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 10px 30px 0px;">
|
||||||
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<table cellpadding="0" cellspacing="0" border="0">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<img src="${shareUrl}/res/components/site-finder/images/site-64.png" alt="" title="" width="64" height="64" border="0" style="padding-right: 20px;" />
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div style="font-size: 22px; padding-bottom: 4px;">
|
||||||
|
${message("templates.invite-email-moderated.html.header", siteName)}
|
||||||
|
</div>
|
||||||
|
<div style="font-size: 13px;">
|
||||||
|
${date?datetime?string.full}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div style="font-size: 14px; margin: 12px 0px 24px 0px; padding-top: 10px; border-top: 1px solid #aaaaaa;">
|
||||||
|
<p>${message("templates.invite-email.html.salutation_generic")}</p>
|
||||||
|
|
||||||
|
<p>${message("templates.invite-email-moderated.html.info", inviteeName, siteName, date?string["dd MMM yyyy"])}</p>
|
||||||
|
|
||||||
|
<a href="${shareUrl}/${sharePendingInvitesLink}" target="_parent">
|
||||||
|
<div style="background-color: #008CBA; border: none; color: white; padding: 10px 15px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px;">
|
||||||
|
${message("templates.invite-email-moderated.html.see_pending")}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<p>${message("templates.invite-email-add-direct.html.closing", productName!"")}</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div style="border-top: 1px solid #aaaaaa;"> </div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 0px 30px; font-size: 13px;">
|
||||||
|
${message("templates.invite-email-add-direct.html.alfresco_info", productName!"")}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div style="border-bottom: 1px solid #aaaaaa;"> </div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 10px 30px;">
|
||||||
|
<img src="${shareUrl}/themes/default/images/app-logo.png" alt="" title="" width="117" height="48" border="0" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<view:view xmlns:view="http://www.alfresco.org/view/repository/1.0">
|
||||||
|
<view:metadata>
|
||||||
|
<view:exportOf>/app:company_home/app:dictionary/app:email_templates/cm:invite</view:exportOf>
|
||||||
|
</view:metadata>
|
||||||
|
|
||||||
|
<!-- Start of Add Direct Templates -->
|
||||||
|
|
||||||
|
<cm:content xmlns="" xmlns:rn="http://www.alfresco.org/model/rendition/1.0" xmlns:sys="http://www.alfresco.org/model/system/1.0" xmlns:lnk="http://www.alfresco.org/model/linksmodel/1.0" xmlns:ver="http://www.alfresco.org/model/versionstore/1.0" xmlns:cmiscustom="http://www.alfresco.org/model/cmis/custom" xmlns:emailserver="http://www.alfresco.org/model/emailserver/1.0" xmlns:fm="http://www.alfresco.org/model/forum/1.0" xmlns:ia="http://www.alfresco.org/model/calendar" xmlns:rule="http://www.alfresco.org/model/rule/1.0" xmlns:dl="http://www.alfresco.org/model/datalist/1.0" xmlns:st="http://www.alfresco.org/model/site/1.0" xmlns:usr="http://www.alfresco.org/model/user/1.0" xmlns:custom="custom.model" xmlns:exif="http://www.alfresco.org/model/exif/1.0" xmlns:app="http://www.alfresco.org/model/application/1.0" xmlns:module="http://www.alfresco.org/system/modules/1.0" xmlns:d="http://www.alfresco.org/model/dictionary/1.0" xmlns:blg="http://www.alfresco.org/model/blogintegration/1.0" xmlns:alf="http://www.alfresco.org" xmlns:cmis="http://www.alfresco.org/model/cmis/1.0/cs01" xmlns:bpm="http://www.alfresco.org/model/bpm/1.0" xmlns:inwf="http://www.alfresco.org/model/workflow/invite/nominated/1.0" xmlns:imap="http://www.alfresco.org/model/imap/1.0" xmlns:cm="http://www.alfresco.org/model/content/1.0" xmlns:reg="http://www.alfresco.org/system/registry/1.0" xmlns:ver2="http://www.alfresco.org/model/versionstore/2.0" xmlns:stcp="http://www.alfresco.org/model/sitecustomproperty/1.0" xmlns:view="http://www.alfresco.org/view/repository/1.0" xmlns:imwf="http://www.alfresco.org/model/workflow/invite/moderated/1.0" xmlns:act="http://www.alfresco.org/model/action/1.0" xmlns:wf="http://www.alfresco.org/model/workflow/1.0" xmlns:trx="http://www.alfresco.org/model/transfer/1.0" view:childName="cm:invite-email-moderated.html.ftl">
|
||||||
|
<view:aspects>
|
||||||
|
<cm:auditable></cm:auditable>
|
||||||
|
<sys:referenceable></sys:referenceable>
|
||||||
|
<app:inlineeditable></app:inlineeditable>
|
||||||
|
</view:aspects>
|
||||||
|
<view:acl></view:acl>
|
||||||
|
<view:properties>
|
||||||
|
<app:editInline>true</app:editInline>
|
||||||
|
<cm:name>invite-email-moderated.html.ftl</cm:name>
|
||||||
|
<cm:title>invite-email-moderated.html.ftl</cm:title>
|
||||||
|
<cm:description>${spaces.templates.email.generate_the_invite_email_moderated.description} - ${version.default}</cm:description>
|
||||||
|
<cm:content>contentUrl=classpath:alfresco/templates/invite-email-templates/invite-email-moderated.html.ftl|mimetype=text/plain|size=5301|encoding=UTF-8</cm:content>
|
||||||
|
</view:properties>
|
||||||
|
</cm:content>
|
||||||
|
|
||||||
|
</view:view>
|
@@ -8,7 +8,11 @@
|
|||||||
|
|
||||||
<startEvent id="start" activiti:formKey="imwf:moderatedInvitationSubmitTask" />
|
<startEvent id="start" activiti:formKey="imwf:moderatedInvitationSubmitTask" />
|
||||||
|
|
||||||
<sequenceFlow id="flow1" sourceRef="start" targetRef="reviewTask" />
|
<sequenceFlow id="flow1" sourceRef="start" targetRef="sendInvite" />
|
||||||
|
|
||||||
|
<serviceTask id="sendInvite" name="Send Invite" activiti:delegateExpression="${SendModeratedInviteDelegate}"></serviceTask>
|
||||||
|
|
||||||
|
<sequenceFlow id="flow2" sourceRef="sendInvite" targetRef="reviewTask" />
|
||||||
|
|
||||||
<userTask id="reviewTask" name="Review Task"
|
<userTask id="reviewTask" name="Review Task"
|
||||||
activiti:formKey="imwf:activitiModeratedInvitationReviewTask">
|
activiti:formKey="imwf:activitiModeratedInvitationReviewTask">
|
||||||
@@ -41,21 +45,21 @@
|
|||||||
</potentialOwner>
|
</potentialOwner>
|
||||||
</userTask>
|
</userTask>
|
||||||
|
|
||||||
<sequenceFlow id="flow2" sourceRef="reviewTask" targetRef="reviewDecision" />
|
<sequenceFlow id="flow3" sourceRef="reviewTask" targetRef="reviewDecision" />
|
||||||
|
|
||||||
<exclusiveGateway id="reviewDecision" name="Review Decision" />
|
<exclusiveGateway id="reviewDecision" name="Review Decision" />
|
||||||
|
|
||||||
<sequenceFlow id="flow3" sourceRef="reviewDecision" targetRef="approved">
|
<sequenceFlow id="flow4" sourceRef="reviewDecision" targetRef="approved">
|
||||||
<conditionExpression xsi:type="tFormalExpression">${imwf_reviewOutcome=='approve'}</conditionExpression>
|
<conditionExpression xsi:type="tFormalExpression">${imwf_reviewOutcome=='approve'}</conditionExpression>
|
||||||
</sequenceFlow>
|
</sequenceFlow>
|
||||||
|
|
||||||
<serviceTask id="approved" name="Approved" activiti:delegateExpression="${ApproveModeratedInviteDelegate}" />
|
<serviceTask id="approved" name="Approved" activiti:delegateExpression="${ApproveModeratedInviteDelegate}" />
|
||||||
<sequenceFlow id="flow5" sourceRef="approved" targetRef="end" />
|
<sequenceFlow id="flow5" sourceRef="approved" targetRef="end" />
|
||||||
|
|
||||||
<sequenceFlow id="flow4" sourceRef="reviewDecision" targetRef="rejected" />
|
<sequenceFlow id="flow6" sourceRef="reviewDecision" targetRef="rejected" />
|
||||||
|
|
||||||
<serviceTask id="rejected" name="Rejected" activiti:delegateExpression="${RejectModeratedInviteDelegate}" />
|
<serviceTask id="rejected" name="Rejected" activiti:delegateExpression="${RejectModeratedInviteDelegate}" />
|
||||||
<sequenceFlow id='flow6' sourceRef='rejected' targetRef='end' />
|
<sequenceFlow id='flow7' sourceRef='rejected' targetRef='end' />
|
||||||
|
|
||||||
<endEvent id="end" />
|
<endEvent id="end" />
|
||||||
</process>
|
</process>
|
||||||
|
@@ -53,6 +53,8 @@ import org.alfresco.repo.action.executer.MailActionExecuter;
|
|||||||
import org.alfresco.repo.admin.SysAdminParams;
|
import org.alfresco.repo.admin.SysAdminParams;
|
||||||
import org.alfresco.repo.i18n.MessageService;
|
import org.alfresco.repo.i18n.MessageService;
|
||||||
import org.alfresco.repo.invitation.activiti.SendNominatedInviteDelegate;
|
import org.alfresco.repo.invitation.activiti.SendNominatedInviteDelegate;
|
||||||
|
import org.alfresco.repo.invitation.site.InviteNominatedSender;
|
||||||
|
import org.alfresco.repo.invitation.site.InviteModeratedSender;
|
||||||
import org.alfresco.repo.invitation.site.InviteSender;
|
import org.alfresco.repo.invitation.site.InviteSender;
|
||||||
import org.alfresco.repo.jscript.ScriptNode;
|
import org.alfresco.repo.jscript.ScriptNode;
|
||||||
import org.alfresco.repo.model.Repository;
|
import org.alfresco.repo.model.Repository;
|
||||||
@@ -126,7 +128,7 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
private static final Log logger = LogFactory.getLog(InvitationServiceImpl.class);
|
private static final Log logger = LogFactory.getLog(InvitationServiceImpl.class);
|
||||||
private static final String REJECT_TEMPLATE = "/alfresco/bootstrap/invite/moderated-reject-email.ftl";
|
private static final String REJECT_TEMPLATE = "/alfresco/bootstrap/invite/moderated-reject-email.ftl";
|
||||||
private static final String MSG_NOT_SITE_MANAGER = "invitation.cancel.not_site_manager";
|
private static final String MSG_NOT_SITE_MANAGER = "invitation.cancel.not_site_manager";
|
||||||
private static final Collection<String> sendInvitePropertyNames = Arrays.asList(wfVarInviteeUserName,//
|
private static final List<String> SEND_INVITE_NOMINATED_PROP_NAMES = Arrays.asList(wfVarInviteeUserName,//
|
||||||
wfVarResourceName,//
|
wfVarResourceName,//
|
||||||
wfVarInviterUserName,//
|
wfVarInviterUserName,//
|
||||||
wfVarInviteeUserName,//
|
wfVarInviteeUserName,//
|
||||||
@@ -137,7 +139,15 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
wfVarServerPath,//
|
wfVarServerPath,//
|
||||||
wfVarAcceptUrl,//
|
wfVarAcceptUrl,//
|
||||||
wfVarRejectUrl,
|
wfVarRejectUrl,
|
||||||
InviteSender.WF_INSTANCE_ID);
|
InviteNominatedSender.WF_INSTANCE_ID);
|
||||||
|
|
||||||
|
private static final List<String> SEND_INVITE_MODERATED_PROP_NAMES = Arrays.asList(
|
||||||
|
WorkflowModelModeratedInvitation.wfVarInviteeUserName,
|
||||||
|
WorkflowModelModeratedInvitation.wfVarInviteeRole,
|
||||||
|
WorkflowModelModeratedInvitation.wfVarResourceName,
|
||||||
|
WorkflowModelModeratedInvitation.bpmGroupAssignee,
|
||||||
|
WorkflowModelModeratedInvitation.wfVarResourceType);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Services
|
* Services
|
||||||
@@ -161,7 +171,8 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
private Repository repositoryHelper;
|
private Repository repositoryHelper;
|
||||||
private ServiceRegistry serviceRegistry;
|
private ServiceRegistry serviceRegistry;
|
||||||
private MessageService messageService;
|
private MessageService messageService;
|
||||||
private InviteSender inviteSender;
|
private InviteNominatedSender inviteNominatedSender;
|
||||||
|
private InviteModeratedSender inviteModeratedSender;
|
||||||
|
|
||||||
// maximum number of tries to generate a invitee user name which
|
// maximum number of tries to generate a invitee user name which
|
||||||
// does not already belong to an existing person
|
// does not already belong to an existing person
|
||||||
@@ -243,7 +254,8 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
PropertyCheck.mandatory(this, "PolicyComponent", policyComponent);
|
PropertyCheck.mandatory(this, "PolicyComponent", policyComponent);
|
||||||
PropertyCheck.mandatory(this, "templateService", templateService);
|
PropertyCheck.mandatory(this, "templateService", templateService);
|
||||||
|
|
||||||
this.inviteSender = new InviteSender(serviceRegistry, repositoryHelper, messageService);
|
this.inviteNominatedSender = new InviteNominatedSender(serviceRegistry, repositoryHelper, messageService);
|
||||||
|
this.inviteModeratedSender = new InviteModeratedSender(serviceRegistry, repositoryHelper, messageService);
|
||||||
|
|
||||||
//
|
//
|
||||||
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
|
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
|
||||||
@@ -2010,21 +2022,40 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
@Override
|
@Override
|
||||||
public void sendNominatedInvitation(String inviteId, String emailTemplateXpath,
|
public void sendNominatedInvitation(String inviteId, String emailTemplateXpath,
|
||||||
String emailSubjectKey, Map<String, Object> executionVariables)
|
String emailSubjectKey, Map<String, Object> executionVariables)
|
||||||
|
{
|
||||||
|
sendInviteEmail(inviteNominatedSender, SEND_INVITE_NOMINATED_PROP_NAMES, inviteId, emailTemplateXpath, emailSubjectKey, executionVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendInviteEmail(InviteSender inviteSender, List<String> invitePropNames, String inviteId, String emailTemplateXpath, String emailSubjectKey, Map<String, Object> executionVariables)
|
||||||
{
|
{
|
||||||
if (isSendEmails())
|
if (isSendEmails())
|
||||||
{
|
{
|
||||||
Map<String, String> properties = makePropertiesFromContextVariables(executionVariables, sendInvitePropertyNames);
|
Map<String, String> properties = makePropertiesFromContextVariables(executionVariables, invitePropNames);
|
||||||
|
|
||||||
String packageName = WorkflowModel.ASSOC_PACKAGE.toPrefixString(namespaceService).replace(":", "_");
|
String packageRef = getPackageRef(executionVariables);
|
||||||
ScriptNode packageNode = (ScriptNode) executionVariables.get(packageName);
|
properties.put(InviteNominatedSender.WF_PACKAGE, packageRef);
|
||||||
String packageRef = packageNode.getNodeRef().toString();
|
|
||||||
properties.put(InviteSender.WF_PACKAGE, packageRef);
|
|
||||||
|
|
||||||
properties.put(InviteSender.WF_INSTANCE_ID, inviteId);
|
properties.put(InviteNominatedSender.WF_INSTANCE_ID, inviteId);
|
||||||
|
|
||||||
inviteSender.sendMail(emailTemplateXpath, emailSubjectKey, properties);
|
inviteSender.sendMail(emailTemplateXpath, emailSubjectKey, properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendModeratedInvitation(String inviteId, String emailTemplateXpath, String emailSubjectKey, Map<String, Object> executionVariables)
|
||||||
|
{
|
||||||
|
sendInviteEmail(inviteModeratedSender, SEND_INVITE_MODERATED_PROP_NAMES, inviteId, emailTemplateXpath, emailSubjectKey, executionVariables);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPackageRef(Map<String, Object> executionVariables)
|
||||||
|
{
|
||||||
|
String packageName = WorkflowModel.ASSOC_PACKAGE.toPrefixString(namespaceService).replace(":", "_");
|
||||||
|
ScriptNode packageNode = (ScriptNode) executionVariables.get(packageName);
|
||||||
|
String packageRef = packageNode.getNodeRef().toString();
|
||||||
|
return packageRef;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelInvitation(String siteName, String invitee, String inviteId, String currentInviteId)
|
public void cancelInvitation(String siteName, String invitee, String inviteId, String currentInviteId)
|
||||||
|
@@ -76,4 +76,5 @@ public interface WorkflowModelModeratedInvitation
|
|||||||
public static final String wfVarResourceType = "imwf_resourceType";
|
public static final String wfVarResourceType = "imwf_resourceType";
|
||||||
public static final String wfVarReviewer = "imwf_reviewer";
|
public static final String wfVarReviewer = "imwf_reviewer";
|
||||||
public static final String wfVarReviewComments = "imwf_reviewComments";
|
public static final String wfVarReviewComments = "imwf_reviewComments";
|
||||||
|
public static final String bpmGroupAssignee = "bpm_groupAssignee";
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.invitation.activiti;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.activiti.engine.delegate.DelegateExecution;
|
||||||
|
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activiti delegate that is executed when a invitation request has been sent.
|
||||||
|
*
|
||||||
|
* @author Constantin Popa
|
||||||
|
*/
|
||||||
|
public class SendModeratedInviteDelegate extends AbstractInvitationDelegate
|
||||||
|
{
|
||||||
|
public static final String EMAIL_TEMPLATE_XPATH =
|
||||||
|
"app:company_home/app:dictionary/app:email_templates/cm:invite/cm:invite-email-moderated.html.ftl";
|
||||||
|
public static final String EMAIL_SUBJECT_KEY =
|
||||||
|
"invitation.moderated.email.subject";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(DelegateExecution execution) throws Exception
|
||||||
|
{
|
||||||
|
String invitationId = ActivitiConstants.ENGINE_ID + "$" + execution.getProcessInstanceId();
|
||||||
|
Map<String, Object> variables = execution.getVariables();
|
||||||
|
invitationService.sendModeratedInvitation(invitationId, EMAIL_TEMPLATE_XPATH, EMAIL_SUBJECT_KEY, variables);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.invitation.site;
|
||||||
|
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelModeratedInvitation.bpmGroupAssignee;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||||
|
import org.alfresco.repo.i18n.MessageService;
|
||||||
|
import org.alfresco.repo.invitation.WorkflowModelModeratedInvitation;
|
||||||
|
import org.alfresco.repo.model.Repository;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.TemplateService;
|
||||||
|
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||||
|
import org.alfresco.util.ModelUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is responsible for sending email notifications to site managers informing about users requesting access.
|
||||||
|
*
|
||||||
|
* @author Constantin Popa
|
||||||
|
*/
|
||||||
|
public class InviteModeratedSender extends InviteSender
|
||||||
|
{
|
||||||
|
public static final String WF_PACKAGE = "wf_package";
|
||||||
|
public static final String SHARE_PENDING_INVITES_LINK = "page/site/{0}/pending-invites";
|
||||||
|
|
||||||
|
private static final List<String> INVITE_MODERATED_EXPECTED_PROPERTIES = Arrays.asList(
|
||||||
|
WorkflowModelModeratedInvitation.wfVarInviteeUserName,
|
||||||
|
WorkflowModelModeratedInvitation.wfVarInviteeRole,
|
||||||
|
WorkflowModelModeratedInvitation.wfVarResourceName,
|
||||||
|
WorkflowModelModeratedInvitation.bpmGroupAssignee,
|
||||||
|
WorkflowModelModeratedInvitation.wfVarResourceType);
|
||||||
|
|
||||||
|
|
||||||
|
public InviteModeratedSender(ServiceRegistry services, Repository repository, MessageService messageService)
|
||||||
|
{
|
||||||
|
super(services, repository, messageService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMail(String emailTemplateXpath, String emailSubjectKey, Map<String, String> properties)
|
||||||
|
{
|
||||||
|
checkProperties(properties);
|
||||||
|
NodeRef invitee = personService.getPerson(properties.get(WorkflowModelModeratedInvitation.wfVarInviteeUserName));
|
||||||
|
Action mail = actionService.createAction(MailActionExecuter.NAME);
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_FROM, (String) nodeService.getProperty(invitee, ContentModel.PROP_EMAIL));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_TO_MANY, properties.get(bpmGroupAssignee));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT, emailSubjectKey);
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT_PARAMS, new Object[] { getSiteName(properties) });
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, getEmailTemplateNodeRef(emailTemplateXpath));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) buildMailTextModel(properties));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_IGNORE_SEND_FAILURE, true);
|
||||||
|
actionService.executeAction(mail, new NodeRef(properties.get(WF_PACKAGE)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, Serializable> buildMailTextModel(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
NodeRef invitee = personService.getPerson(properties.get(WorkflowModelModeratedInvitation.wfVarInviteeUserName));
|
||||||
|
Map<String, Serializable> model = new HashMap<String, Serializable>();
|
||||||
|
model.put(TemplateService.KEY_COMPANY_HOME, repository.getCompanyHome());
|
||||||
|
model.put(TemplateService.KEY_USER_HOME, repository.getUserHome(repository.getPerson()));
|
||||||
|
model.put(TemplateService.KEY_PRODUCT_NAME, ModelUtil.getProductName(repoAdminService));
|
||||||
|
|
||||||
|
PersonInfo inviteePerson = personService.getPerson(invitee);
|
||||||
|
model.put("inviteeName", StringUtils.join(new String[] { inviteePerson.getFirstName(), inviteePerson.getLastName() }, " "));
|
||||||
|
model.put("siteName", getSiteName(properties));
|
||||||
|
model.put("sharePendingInvitesLink", MessageFormat.format(SHARE_PENDING_INVITES_LINK, properties.get(WorkflowModelModeratedInvitation.wfVarResourceName)));
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getRequiredProperties()
|
||||||
|
{
|
||||||
|
return INVITE_MODERATED_EXPECTED_PROPERTIES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getWorkflowPropForSiteName()
|
||||||
|
{
|
||||||
|
return WorkflowModelModeratedInvitation.wfVarResourceName;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,240 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.invitation.site;
|
||||||
|
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarAcceptUrl;
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteTicket;
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteeGenPassword;
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteeUserName;
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviterUserName;
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarRejectUrl;
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarResourceName;
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarRole;
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarServerPath;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||||
|
import org.alfresco.repo.i18n.MessageService;
|
||||||
|
import org.alfresco.repo.invitation.activiti.SendNominatedInviteDelegate;
|
||||||
|
import org.alfresco.repo.model.Repository;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.TemplateService;
|
||||||
|
import org.alfresco.util.ModelUtil;
|
||||||
|
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||||
|
import org.springframework.extensions.surf.util.URLEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is responsible for sending email invitations, allowing nominated
|
||||||
|
* user's to join a Site.
|
||||||
|
*
|
||||||
|
* @author Nick Smith
|
||||||
|
*/
|
||||||
|
public class InviteNominatedSender extends InviteSender
|
||||||
|
{
|
||||||
|
public static final String WF_INSTANCE_ID = "wf_instanceId";
|
||||||
|
public static final String WF_PACKAGE = "wf_package";
|
||||||
|
public static final String SITE_LEAVE_HASH = "#leavesite";
|
||||||
|
private static final String SITE_DASHBOARD_ENDPOINT_PATTERN = "/page/site/{0}/dashboard";
|
||||||
|
|
||||||
|
private static final List<String> INVITE_NOMINATED_EXPECTED_PROPERTIES = Arrays.asList(wfVarInviteeUserName,//
|
||||||
|
wfVarResourceName,//
|
||||||
|
wfVarInviterUserName,//
|
||||||
|
wfVarInviteeUserName,//
|
||||||
|
wfVarRole,//
|
||||||
|
wfVarInviteeGenPassword,//
|
||||||
|
wfVarResourceName,//
|
||||||
|
wfVarInviteTicket,//
|
||||||
|
wfVarServerPath,//
|
||||||
|
wfVarAcceptUrl,//
|
||||||
|
wfVarRejectUrl, WF_INSTANCE_ID,//
|
||||||
|
WF_PACKAGE);
|
||||||
|
|
||||||
|
public InviteNominatedSender(ServiceRegistry services, Repository repository, MessageService messageService)
|
||||||
|
{
|
||||||
|
super(services, repository, messageService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implemented for backwards compatibility
|
||||||
|
*
|
||||||
|
* @param properties
|
||||||
|
* @deprecated
|
||||||
|
* @see {@link #sendMail(String, String, Map)}
|
||||||
|
*/
|
||||||
|
public void sendMail(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
sendMail(SendNominatedInviteDelegate.EMAIL_TEMPLATE_XPATH, SendNominatedInviteDelegate.EMAIL_SUBJECT_KEY, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMail(String emailTemplateXpath, String emailSubjectKey, Map<String, String> properties)
|
||||||
|
{
|
||||||
|
checkProperties(properties);
|
||||||
|
ParameterCheck.mandatory("Properties", properties);
|
||||||
|
NodeRef inviter = personService.getPerson(properties.get(wfVarInviterUserName));
|
||||||
|
String inviteeName = properties.get(wfVarInviteeUserName);
|
||||||
|
NodeRef invitee = personService.getPerson(inviteeName);
|
||||||
|
Action mail = actionService.createAction(MailActionExecuter.NAME);
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_FROM, getEmail(inviter));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_TO, getEmail(invitee));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT, emailSubjectKey);
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT_PARAMS, new Object[] { ModelUtil.getProductName(repoAdminService), getSiteName(properties) });
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, getEmailTemplateNodeRef(emailTemplateXpath));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) buildMailTextModel(properties));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_IGNORE_SEND_FAILURE, true);
|
||||||
|
actionService.executeAction(mail, getWorkflowPackage(properties));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, Serializable> buildMailTextModel(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
NodeRef inviter = personService.getPerson(properties.get(wfVarInviterUserName));
|
||||||
|
NodeRef invitee = personService.getPerson(properties.get(wfVarInviteeUserName));
|
||||||
|
// Set the core model parts
|
||||||
|
// Note - the user part is skipped, as that's implied via the run-as
|
||||||
|
Map<String, Serializable> model = new HashMap<String, Serializable>();
|
||||||
|
model.put(TemplateService.KEY_COMPANY_HOME, repository.getCompanyHome());
|
||||||
|
model.put(TemplateService.KEY_USER_HOME, repository.getUserHome(repository.getPerson()));
|
||||||
|
model.put(TemplateService.KEY_PRODUCT_NAME, ModelUtil.getProductName(repoAdminService));
|
||||||
|
|
||||||
|
// Build up the args for rendering inside the template
|
||||||
|
Map<String, String> args = buildArgs(properties, inviter, invitee);
|
||||||
|
model.put("args", (Serializable) args);
|
||||||
|
|
||||||
|
// All done
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> buildArgs(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
||||||
|
{
|
||||||
|
String params = buildUrlParamString(properties);
|
||||||
|
String acceptLink = makeLink(properties.get(wfVarServerPath), properties.get(wfVarAcceptUrl), params, null);
|
||||||
|
String rejectLink = makeLink(properties.get(wfVarServerPath), properties.get(wfVarRejectUrl), params, null);
|
||||||
|
|
||||||
|
String siteDashboardEndpoint = getSiteDashboardEndpoint(properties);
|
||||||
|
String siteDashboardLink = makeLink(properties.get(wfVarServerPath), siteDashboardEndpoint, null, null);
|
||||||
|
String siteLeaveLink = makeLink(properties.get(wfVarServerPath), siteDashboardEndpoint, null, SITE_LEAVE_HASH);
|
||||||
|
|
||||||
|
Map<String, String> args = new HashMap<String, String>();
|
||||||
|
args.put("inviteePersonRef", invitee.toString());
|
||||||
|
args.put("inviterPersonRef", inviter.toString());
|
||||||
|
args.put("siteName", getSiteName(properties));
|
||||||
|
args.put("inviteeSiteRole", getRoleName(properties));
|
||||||
|
args.put("inviteeUserName", properties.get(wfVarInviteeUserName));
|
||||||
|
args.put("inviteeGenPassword", properties.get(wfVarInviteeGenPassword));
|
||||||
|
args.put("acceptLink", acceptLink);
|
||||||
|
args.put("rejectLink", rejectLink);
|
||||||
|
args.put("siteDashboardLink", siteDashboardLink);
|
||||||
|
args.put("siteLeaveLink", siteLeaveLink);
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String makeLink(String location, String endpoint, String queryParams, String hashParam)
|
||||||
|
{
|
||||||
|
location = location.endsWith("/") ? location : location + "/";
|
||||||
|
endpoint = endpoint.startsWith("/") ? endpoint.substring(1) : endpoint;
|
||||||
|
if (queryParams != null)
|
||||||
|
{
|
||||||
|
queryParams = queryParams.startsWith("?") ? queryParams : "?" + queryParams;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
queryParams = "";
|
||||||
|
}
|
||||||
|
if (hashParam != null)
|
||||||
|
{
|
||||||
|
hashParam = hashParam.startsWith("#") ? hashParam : "#" + hashParam;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hashParam = "";
|
||||||
|
}
|
||||||
|
return location + endpoint + queryParams + hashParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRoleName(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
String roleName = properties.get(wfVarRole);
|
||||||
|
String role = messageService.getMessage("invitation.invitesender.email.role." + roleName);
|
||||||
|
if (role == null)
|
||||||
|
{
|
||||||
|
role = roleName;
|
||||||
|
}
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getEmail(NodeRef person)
|
||||||
|
{
|
||||||
|
return (String) nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private NodeRef getWorkflowPackage(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
String packageRef = properties.get(WF_PACKAGE);
|
||||||
|
return new NodeRef(packageRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildUrlParamString(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
StringBuilder params = new StringBuilder("?inviteId=");
|
||||||
|
params.append(properties.get(WF_INSTANCE_ID));
|
||||||
|
params.append("&inviteeUserName=");
|
||||||
|
params.append(URLEncoder.encode(properties.get(wfVarInviteeUserName)));
|
||||||
|
params.append("&siteShortName=");
|
||||||
|
params.append(properties.get(wfVarResourceName));
|
||||||
|
params.append("&inviteTicket=");
|
||||||
|
params.append(properties.get(wfVarInviteTicket));
|
||||||
|
return params.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSiteDashboardEndpoint(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
String siteName = properties.get(wfVarResourceName);
|
||||||
|
return MessageFormat.format(SITE_DASHBOARD_ENDPOINT_PATTERN, siteName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getRequiredProperties()
|
||||||
|
{
|
||||||
|
return INVITE_NOMINATED_EXPECTED_PROPERTIES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getWorkflowPropForSiteName()
|
||||||
|
{
|
||||||
|
return wfVarResourceName;
|
||||||
|
}
|
||||||
|
}
|
@@ -26,85 +26,46 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.invitation.site;
|
package org.alfresco.repo.invitation.site;
|
||||||
|
|
||||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarAcceptUrl;
|
|
||||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteTicket;
|
|
||||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteeGenPassword;
|
|
||||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteeUserName;
|
|
||||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviterUserName;
|
|
||||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarRejectUrl;
|
|
||||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarResourceName;
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarResourceName;
|
||||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarRole;
|
|
||||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarServerPath;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
|
||||||
import org.alfresco.repo.action.executer.MailActionExecuter;
|
|
||||||
import org.alfresco.repo.i18n.MessageService;
|
import org.alfresco.repo.i18n.MessageService;
|
||||||
import org.alfresco.repo.invitation.activiti.SendNominatedInviteDelegate;
|
|
||||||
import org.alfresco.repo.model.Repository;
|
import org.alfresco.repo.model.Repository;
|
||||||
import org.alfresco.service.ServiceRegistry;
|
import org.alfresco.service.ServiceRegistry;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
|
||||||
import org.alfresco.service.cmr.action.ActionService;
|
import org.alfresco.service.cmr.action.ActionService;
|
||||||
import org.alfresco.service.cmr.admin.RepoAdminService;
|
import org.alfresco.service.cmr.admin.RepoAdminService;
|
||||||
import org.alfresco.service.cmr.invitation.InvitationException;
|
import org.alfresco.service.cmr.invitation.InvitationException;
|
||||||
import org.alfresco.service.cmr.model.FileFolderService;
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.repository.TemplateService;
|
|
||||||
import org.alfresco.service.cmr.search.SearchService;
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.alfresco.service.cmr.site.SiteInfo;
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
import org.alfresco.service.cmr.site.SiteService;
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.util.ModelUtil;
|
|
||||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
|
||||||
import org.springframework.extensions.surf.util.URLEncoder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is responsible for sending email invitations, allowing nominated
|
* Notifies the necessary user(s) of a pending site membership invitation/request.
|
||||||
* user's to join a Site.
|
|
||||||
*
|
*
|
||||||
* @author Nick Smith
|
* @author Nick Smith
|
||||||
*/
|
*/
|
||||||
public class InviteSender
|
public abstract class InviteSender
|
||||||
{
|
{
|
||||||
public static final String WF_INSTANCE_ID = "wf_instanceId";
|
protected final ActionService actionService;
|
||||||
public static final String WF_PACKAGE = "wf_package";
|
protected final NodeService nodeService;
|
||||||
public static final String SITE_LEAVE_HASH = "#leavesite";
|
protected final PersonService personService;
|
||||||
private static final String SITE_DASHBOARD_ENDPOINT_PATTERN = "/page/site/{0}/dashboard";
|
protected final SearchService searchService;
|
||||||
|
protected final SiteService siteService;
|
||||||
private static final List<String> expectedProperties = Arrays.asList(wfVarInviteeUserName,//
|
protected final Repository repository;
|
||||||
wfVarResourceName,//
|
protected final MessageService messageService;
|
||||||
wfVarInviterUserName,//
|
protected final FileFolderService fileFolderService;
|
||||||
wfVarInviteeUserName,//
|
protected final RepoAdminService repoAdminService;
|
||||||
wfVarRole,//
|
protected final NamespaceService namespaceService;
|
||||||
wfVarInviteeGenPassword,//
|
|
||||||
wfVarResourceName,//
|
|
||||||
wfVarInviteTicket,//
|
|
||||||
wfVarServerPath,//
|
|
||||||
wfVarAcceptUrl,//
|
|
||||||
wfVarRejectUrl, WF_INSTANCE_ID,//
|
|
||||||
WF_PACKAGE);
|
|
||||||
|
|
||||||
private final ActionService actionService;
|
|
||||||
private final NodeService nodeService;
|
|
||||||
private final PersonService personService;
|
|
||||||
private final SearchService searchService;
|
|
||||||
private final SiteService siteService;
|
|
||||||
private final Repository repository;
|
|
||||||
private final MessageService messageService;
|
|
||||||
private final FileFolderService fileFolderService;
|
|
||||||
// private final SysAdminParams sysAdminParams;
|
|
||||||
private final RepoAdminService repoAdminService;
|
|
||||||
private final NamespaceService namespaceService;
|
|
||||||
|
|
||||||
public InviteSender(ServiceRegistry services, Repository repository, MessageService messageService)
|
public InviteSender(ServiceRegistry services, Repository repository, MessageService messageService)
|
||||||
{
|
{
|
||||||
@@ -114,25 +75,12 @@ public class InviteSender
|
|||||||
this.searchService = services.getSearchService();
|
this.searchService = services.getSearchService();
|
||||||
this.siteService = services.getSiteService();
|
this.siteService = services.getSiteService();
|
||||||
this.fileFolderService = services.getFileFolderService();
|
this.fileFolderService = services.getFileFolderService();
|
||||||
// this.sysAdminParams = services.getSysAdminParams();
|
|
||||||
this.repoAdminService = services.getRepoAdminService();
|
this.repoAdminService = services.getRepoAdminService();
|
||||||
this.namespaceService = services.getNamespaceService();
|
this.namespaceService = services.getNamespaceService();
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.messageService = messageService;
|
this.messageService = messageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implemented for backwards compatibility
|
|
||||||
*
|
|
||||||
* @param properties
|
|
||||||
* @deprecated
|
|
||||||
* @see {@link #sendMail(String, String, Map)}
|
|
||||||
*/
|
|
||||||
public void sendMail(Map<String, String> properties)
|
|
||||||
{
|
|
||||||
sendMail(SendNominatedInviteDelegate.EMAIL_TEMPLATE_XPATH, SendNominatedInviteDelegate.EMAIL_SUBJECT_KEY, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an invitation email.
|
* Sends an invitation email.
|
||||||
*
|
*
|
||||||
@@ -140,128 +88,27 @@ public class InviteSender
|
|||||||
* @param emailSubjectKey the subject of the email
|
* @param emailSubjectKey the subject of the email
|
||||||
* @param properties A Map containing the properties needed to send the email.
|
* @param properties A Map containing the properties needed to send the email.
|
||||||
*/
|
*/
|
||||||
public void sendMail(String emailTemplateXpath, String emailSubjectKey, Map<String, String> properties)
|
public abstract void sendMail(String emailTemplateXpath, String emailSubjectKey, Map<String, String> properties);
|
||||||
{
|
|
||||||
checkProperties(properties);
|
protected abstract Map<String, Serializable> buildMailTextModel(Map<String, String> properties);
|
||||||
ParameterCheck.mandatory("Properties", properties);
|
|
||||||
NodeRef inviter = personService.getPerson(properties.get(wfVarInviterUserName));
|
protected abstract List<String> getRequiredProperties();
|
||||||
String inviteeName = properties.get(wfVarInviteeUserName);
|
|
||||||
NodeRef invitee = personService.getPerson(inviteeName);
|
|
||||||
Action mail = actionService.createAction(MailActionExecuter.NAME);
|
|
||||||
mail.setParameterValue(MailActionExecuter.PARAM_FROM, getEmail(inviter));
|
|
||||||
mail.setParameterValue(MailActionExecuter.PARAM_TO, getEmail(invitee));
|
|
||||||
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT, emailSubjectKey);
|
|
||||||
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT_PARAMS, new Object[] {ModelUtil.getProductName(repoAdminService), getSiteName(properties)});
|
|
||||||
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, getEmailTemplateNodeRef(emailTemplateXpath));
|
|
||||||
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL,
|
|
||||||
(Serializable)buildMailTextModel(properties, inviter, invitee));
|
|
||||||
mail.setParameterValue(MailActionExecuter.PARAM_IGNORE_SEND_FAILURE, true);
|
|
||||||
actionService.executeAction(mail, getWorkflowPackage(properties));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param properties Map<String, String>
|
* @param properties Map<String, String>
|
||||||
*/
|
*/
|
||||||
private void checkProperties(Map<String, String> properties)
|
protected void checkProperties(Map<String, String> properties)
|
||||||
{
|
{
|
||||||
Set<String> keys = properties.keySet();
|
Set<String> keys = properties.keySet();
|
||||||
if (!keys.containsAll(expectedProperties))
|
if (!keys.containsAll(getRequiredProperties()))
|
||||||
{
|
{
|
||||||
LinkedList<String> missingProperties = new LinkedList<String>(expectedProperties);
|
LinkedList<String> missingProperties = new LinkedList<String>(getRequiredProperties());
|
||||||
missingProperties.removeAll(keys);
|
missingProperties.removeAll(keys);
|
||||||
throw new InvitationException("The following mandatory properties are missing:\n" + missingProperties);
|
throw new InvitationException("The following mandatory properties are missing:\n" + missingProperties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Serializable> buildMailTextModel(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
protected NodeRef getEmailTemplateNodeRef(String emailTemplateXPath)
|
||||||
{
|
|
||||||
// Set the core model parts
|
|
||||||
// Note - the user part is skipped, as that's implied via the run-as
|
|
||||||
Map<String, Serializable> model = new HashMap<String, Serializable>();
|
|
||||||
model.put(TemplateService.KEY_COMPANY_HOME, repository.getCompanyHome());
|
|
||||||
model.put(TemplateService.KEY_USER_HOME, repository.getUserHome(repository.getPerson()));
|
|
||||||
model.put(TemplateService.KEY_PRODUCT_NAME, ModelUtil.getProductName(repoAdminService));
|
|
||||||
|
|
||||||
// Build up the args for rendering inside the template
|
|
||||||
Map<String, String> args = buildArgs(properties, inviter, invitee);
|
|
||||||
model.put("args", (Serializable)args);
|
|
||||||
|
|
||||||
// All done
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> buildArgs(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
|
||||||
{
|
|
||||||
String params = buildUrlParamString(properties);
|
|
||||||
String acceptLink = makeLink(properties.get(wfVarServerPath), properties.get(wfVarAcceptUrl), params, null);
|
|
||||||
String rejectLink = makeLink(properties.get(wfVarServerPath), properties.get(wfVarRejectUrl), params, null);
|
|
||||||
|
|
||||||
String siteDashboardEndpoint = getSiteDashboardEndpoint(properties);
|
|
||||||
String siteDashboardLink = makeLink(properties.get(wfVarServerPath),
|
|
||||||
siteDashboardEndpoint, null, null);
|
|
||||||
String siteLeaveLink = makeLink(properties.get(wfVarServerPath),
|
|
||||||
siteDashboardEndpoint, null, SITE_LEAVE_HASH);
|
|
||||||
|
|
||||||
Map<String, String> args = new HashMap<String, String>();
|
|
||||||
args.put("inviteePersonRef", invitee.toString());
|
|
||||||
args.put("inviterPersonRef", inviter.toString());
|
|
||||||
args.put("siteName", getSiteName(properties));
|
|
||||||
args.put("inviteeSiteRole", getRoleName(properties));
|
|
||||||
args.put("inviteeUserName", properties.get(wfVarInviteeUserName));
|
|
||||||
args.put("inviteeGenPassword", properties.get(wfVarInviteeGenPassword));
|
|
||||||
args.put("acceptLink", acceptLink);
|
|
||||||
args.put("rejectLink", rejectLink);
|
|
||||||
args.put("siteDashboardLink", siteDashboardLink);
|
|
||||||
args.put("siteLeaveLink", siteLeaveLink);
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String makeLink(String location, String endpoint, String queryParams, String hashParam)
|
|
||||||
{
|
|
||||||
location = location.endsWith("/") ? location : location + "/";
|
|
||||||
endpoint = endpoint.startsWith("/") ? endpoint.substring(1) : endpoint;
|
|
||||||
if (queryParams != null)
|
|
||||||
{
|
|
||||||
queryParams = queryParams.startsWith("?") ? queryParams : "?" + queryParams;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
queryParams = "";
|
|
||||||
}
|
|
||||||
if (hashParam != null)
|
|
||||||
{
|
|
||||||
hashParam = hashParam.startsWith("#") ? hashParam : "#" + hashParam;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hashParam = "";
|
|
||||||
}
|
|
||||||
return location + endpoint + queryParams + hashParam;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRoleName(Map<String, String> properties)
|
|
||||||
{
|
|
||||||
String roleName = properties.get(wfVarRole);
|
|
||||||
String role = messageService.getMessage("invitation.invitesender.email.role." + roleName);
|
|
||||||
if (role == null)
|
|
||||||
{
|
|
||||||
role = roleName;
|
|
||||||
}
|
|
||||||
return role;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getEmail(NodeRef person)
|
|
||||||
{
|
|
||||||
return (String) nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
private NodeRef getWorkflowPackage(Map<String, String> properties)
|
|
||||||
{
|
|
||||||
String packageRef = properties.get(WF_PACKAGE);
|
|
||||||
return new NodeRef(packageRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
private NodeRef getEmailTemplateNodeRef(String emailTemplateXPath)
|
|
||||||
{
|
{
|
||||||
List<NodeRef> nodeRefs = searchService.selectNodes(repository.getRootHome(),
|
List<NodeRef> nodeRefs = searchService.selectNodes(repository.getRootHome(),
|
||||||
emailTemplateXPath, null,
|
emailTemplateXPath, null,
|
||||||
@@ -280,22 +127,9 @@ public class InviteSender
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildUrlParamString(Map<String, String> properties)
|
protected String getSiteName(Map<String, String> properties)
|
||||||
{
|
{
|
||||||
StringBuilder params = new StringBuilder("?inviteId=");
|
String siteFullName = properties.get(getWorkflowPropForSiteName());
|
||||||
params.append(properties.get(WF_INSTANCE_ID));
|
|
||||||
params.append("&inviteeUserName=");
|
|
||||||
params.append(URLEncoder.encode(properties.get(wfVarInviteeUserName)));
|
|
||||||
params.append("&siteShortName=");
|
|
||||||
params.append(properties.get(wfVarResourceName));
|
|
||||||
params.append("&inviteTicket=");
|
|
||||||
params.append(properties.get(wfVarInviteTicket));
|
|
||||||
return params.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getSiteName(Map<String, String> properties)
|
|
||||||
{
|
|
||||||
String siteFullName = properties.get(wfVarResourceName);
|
|
||||||
SiteInfo site = siteService.getSite(siteFullName);
|
SiteInfo site = siteService.getSite(siteFullName);
|
||||||
if (site == null)
|
if (site == null)
|
||||||
throw new InvitationException("The site " + siteFullName + " could not be found.");
|
throw new InvitationException("The site " + siteFullName + " could not be found.");
|
||||||
@@ -309,9 +143,6 @@ public class InviteSender
|
|||||||
return siteName;
|
return siteName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSiteDashboardEndpoint(Map<String, String> properties)
|
protected abstract String getWorkflowPropForSiteName();
|
||||||
{
|
|
||||||
String siteName = properties.get(wfVarResourceName);
|
|
||||||
return MessageFormat.format(SITE_DASHBOARD_ENDPOINT_PATTERN, siteName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -326,4 +326,15 @@ public interface InvitationService
|
|||||||
@NotAuditable
|
@NotAuditable
|
||||||
boolean isSendEmails();
|
boolean isSendEmails();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Sends the site join request notification email using the given template, subject localization key, and variables.
|
||||||
|
*
|
||||||
|
* @param invitationId
|
||||||
|
* @param emailTemplateXpath
|
||||||
|
* @param emailSubjectKey
|
||||||
|
* @param variables
|
||||||
|
*/
|
||||||
|
@Auditable(parameters = { "inviteId" })
|
||||||
|
public void sendModeratedInvitation(String invitationId, String emailTemplateXpath, String emailSubjectKey, Map<String, Object> variables);
|
||||||
}
|
}
|
||||||
|
@@ -64,6 +64,7 @@ public class AllUnitTestsSuite extends TestSuite
|
|||||||
suite.addTestSuite(org.alfresco.repo.forms.processor.workflow.TaskFormProcessorTest.class);
|
suite.addTestSuite(org.alfresco.repo.forms.processor.workflow.TaskFormProcessorTest.class);
|
||||||
suite.addTestSuite(org.alfresco.repo.forms.processor.workflow.WorkflowFormProcessorTest.class);
|
suite.addTestSuite(org.alfresco.repo.forms.processor.workflow.WorkflowFormProcessorTest.class);
|
||||||
suite.addTestSuite(org.alfresco.repo.invitation.site.InviteSenderTest.class);
|
suite.addTestSuite(org.alfresco.repo.invitation.site.InviteSenderTest.class);
|
||||||
|
suite.addTestSuite(org.alfresco.repo.invitation.site.InviteModeratedSenderTest.class);
|
||||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.lock.LockUtilsTest.class));
|
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.lock.LockUtilsTest.class));
|
||||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.lock.mem.LockStoreImplTest.class));
|
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.lock.mem.LockStoreImplTest.class));
|
||||||
suite.addTestSuite(org.alfresco.repo.module.ModuleDetailsImplTest.class);
|
suite.addTestSuite(org.alfresco.repo.module.ModuleDetailsImplTest.class);
|
||||||
|
@@ -0,0 +1,269 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.repo.invitation.site;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||||
|
import org.alfresco.repo.admin.SysAdminParams;
|
||||||
|
import org.alfresco.repo.admin.SysAdminParamsImpl;
|
||||||
|
import org.alfresco.repo.i18n.MessageService;
|
||||||
|
import org.alfresco.repo.invitation.WorkflowModelModeratedInvitation;
|
||||||
|
import org.alfresco.repo.invitation.activiti.SendModeratedInviteDelegate;
|
||||||
|
import org.alfresco.repo.model.Repository;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.action.ActionService;
|
||||||
|
import org.alfresco.service.cmr.admin.RepoAdminService;
|
||||||
|
import org.alfresco.service.cmr.admin.RepoUsage;
|
||||||
|
import org.alfresco.service.cmr.admin.RepoUsage.LicenseMode;
|
||||||
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.alfresco.service.cmr.search.QueryParameterDefinition;
|
||||||
|
import org.alfresco.service.cmr.search.ResultSet;
|
||||||
|
import org.alfresco.service.cmr.search.SearchParameters;
|
||||||
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
|
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||||
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
|
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Constantin Popa
|
||||||
|
*/
|
||||||
|
public class InviteModeratedSenderTest extends TestCase
|
||||||
|
{
|
||||||
|
private static final StoreRef testStore = new StoreRef(StoreRef.PROTOCOL_TEST, "test");
|
||||||
|
|
||||||
|
private static final String requesterFirstName = "FirstName";
|
||||||
|
private static final String requesterLastName = "LastName";
|
||||||
|
private static final String requesterUserName = "JustAUserName";
|
||||||
|
private static final String requesterRole = "SiteConsumer";
|
||||||
|
private static final String requesterMail = "req@mail.alf";
|
||||||
|
private static final NodeRef requesterNodeRef = new NodeRef(testStore, requesterUserName);
|
||||||
|
|
||||||
|
private static final String SiteManagerGroup = "Group_site_manager";
|
||||||
|
|
||||||
|
private static final NodeRef emailTemplateNodeRef = new NodeRef(testStore, "emailTemplate");
|
||||||
|
|
||||||
|
private static final String fullSiteName = "Full Site Name";
|
||||||
|
private static final String shortSiteName = "site-name";
|
||||||
|
|
||||||
|
private static final String packageId = testStore + "/Package";
|
||||||
|
private static final String pendingInvitesLink = MessageFormat.format("page/site/{0}/pending-invites", shortSiteName);
|
||||||
|
|
||||||
|
private final MessageService messageService = mock(MessageService.class);
|
||||||
|
|
||||||
|
private Action mailAction;
|
||||||
|
private SiteInfo siteInfo = mock(SiteInfo.class);
|
||||||
|
private InviteModeratedSender inviteModeratedSender;
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
/**
|
||||||
|
* Test that the mail action is correctly constructed when sending notifications emails about users requesting access to a specific site
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void testSendModeratedEmail() throws Exception
|
||||||
|
{
|
||||||
|
Map<String, String> properties = buildDefaultProperties();
|
||||||
|
inviteModeratedSender.sendMail(SendModeratedInviteDelegate.EMAIL_TEMPLATE_XPATH, SendModeratedInviteDelegate.EMAIL_SUBJECT_KEY, properties);
|
||||||
|
|
||||||
|
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_FROM), eq(requesterMail));
|
||||||
|
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TO_MANY), eq(SiteManagerGroup));
|
||||||
|
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_SUBJECT), eq(SendModeratedInviteDelegate.EMAIL_SUBJECT_KEY));
|
||||||
|
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_SUBJECT_PARAMS), eq(new Object[]{fullSiteName}));
|
||||||
|
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TEMPLATE), eq(emailTemplateNodeRef));
|
||||||
|
|
||||||
|
ArgumentCaptor<Map> modelC = ArgumentCaptor.forClass(Map.class);
|
||||||
|
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TEMPLATE_MODEL), (Serializable)modelC.capture());
|
||||||
|
|
||||||
|
// Check the model
|
||||||
|
Map model = modelC.getValue();
|
||||||
|
assertNotNull(model);
|
||||||
|
assertEquals(false, model.isEmpty());
|
||||||
|
assertNotNull(model.get("productName"));
|
||||||
|
assertEquals(model.get("inviteeName"), requesterFirstName + " " + requesterLastName);
|
||||||
|
assertEquals(model.get("siteName"), fullSiteName);
|
||||||
|
assertEquals(model.get("sharePendingInvitesLink"), pendingInvitesLink);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> buildDefaultProperties()
|
||||||
|
{
|
||||||
|
Map<String, String> properties = new HashMap<String, String>();
|
||||||
|
properties.put(WorkflowModelModeratedInvitation.wfVarInviteeUserName, requesterUserName);
|
||||||
|
properties.put(WorkflowModelModeratedInvitation.wfVarInviteeRole, requesterRole);
|
||||||
|
properties.put(WorkflowModelModeratedInvitation.wfVarResourceName, shortSiteName);
|
||||||
|
properties.put(WorkflowModelModeratedInvitation.bpmGroupAssignee, SiteManagerGroup);
|
||||||
|
properties.put(WorkflowModelModeratedInvitation.wfVarResourceType, "website");
|
||||||
|
properties.put(InviteNominatedSender.WF_PACKAGE, packageId);
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
ServiceRegistry services = mockServices();
|
||||||
|
Repository repository = mockRepository();
|
||||||
|
inviteModeratedSender = new InviteModeratedSender(services, repository, messageService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up a Repository that will return the inviter as the current user.
|
||||||
|
*
|
||||||
|
* @return Repository
|
||||||
|
*/
|
||||||
|
private Repository mockRepository()
|
||||||
|
{
|
||||||
|
Repository repository = mock(Repository.class);
|
||||||
|
when(repository.getPerson()).thenReturn(requesterNodeRef);
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ServiceRegistry
|
||||||
|
*/
|
||||||
|
private ServiceRegistry mockServices()
|
||||||
|
{
|
||||||
|
ActionService mockActionService = mockActionService();
|
||||||
|
NodeService mockNodeService = mockNodeService();
|
||||||
|
PersonService mockPersonService = mockPersonService();
|
||||||
|
SearchService mockSearchService = mockSearchService();
|
||||||
|
SiteService mockSiteService = mockSiteService();
|
||||||
|
FileFolderService mockFileFolderService = mockFileFolderService();
|
||||||
|
|
||||||
|
ServiceRegistry services = mock(ServiceRegistry.class);
|
||||||
|
when(services.getActionService()).thenReturn(mockActionService);
|
||||||
|
when(services.getNodeService()).thenReturn(mockNodeService);
|
||||||
|
when(services.getPersonService()).thenReturn(mockPersonService);
|
||||||
|
when(services.getSearchService()).thenReturn(mockSearchService);
|
||||||
|
when(services.getSiteService()).thenReturn(mockSiteService);
|
||||||
|
when(services.getFileFolderService()).thenReturn(mockFileFolderService);
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileFolderService mockFileFolderService()
|
||||||
|
{
|
||||||
|
FileFolderService fileFolderService = mock(FileFolderService.class);
|
||||||
|
when(fileFolderService.getLocalizedSibling(emailTemplateNodeRef)).thenReturn(emailTemplateNodeRef);
|
||||||
|
return fileFolderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up a SiteService that returns appropriate SiteInfo.
|
||||||
|
*
|
||||||
|
* @return SiteService
|
||||||
|
*/
|
||||||
|
private SiteService mockSiteService()
|
||||||
|
{
|
||||||
|
SiteService siteService = mock(SiteService.class);
|
||||||
|
when(siteInfo.getTitle()).thenReturn(fullSiteName);
|
||||||
|
when(siteService.getSite(shortSiteName)).thenReturn(siteInfo);
|
||||||
|
return siteService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up a SearchService that will return the template NodeRef when* queried.
|
||||||
|
*
|
||||||
|
* @return SearchService
|
||||||
|
*/
|
||||||
|
private SearchService mockSearchService()
|
||||||
|
{
|
||||||
|
SearchService searchService = mock(SearchService.class);
|
||||||
|
ResultSet results = mock(ResultSet.class);
|
||||||
|
List<NodeRef> nodeRefs = Arrays.asList(emailTemplateNodeRef);
|
||||||
|
when(results.getNodeRefs()).thenReturn(nodeRefs);
|
||||||
|
when(searchService.query((SearchParameters) any())).thenReturn(results);
|
||||||
|
when(searchService.selectNodes(any(NodeRef.class), any(String.class),
|
||||||
|
any(QueryParameterDefinition[].class), any(NamespacePrefixResolver.class), eq(false)))
|
||||||
|
.thenReturn(nodeRefs);
|
||||||
|
return searchService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up a PersonService that returns the correct NodeRef when given a* user name.
|
||||||
|
*
|
||||||
|
* @return PersonService
|
||||||
|
*/
|
||||||
|
private PersonService mockPersonService()
|
||||||
|
{
|
||||||
|
PersonService personService = mock(PersonService.class);
|
||||||
|
|
||||||
|
when(personService.getPerson(requesterUserName)).thenReturn(requesterNodeRef);
|
||||||
|
when(personService.getPerson(requesterNodeRef)).thenReturn(new PersonInfo(requesterNodeRef, requesterUserName, requesterFirstName, requesterLastName));
|
||||||
|
return personService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up NodeService to return email adresses for requester
|
||||||
|
*
|
||||||
|
* @return NodeService
|
||||||
|
*/
|
||||||
|
private NodeService mockNodeService()
|
||||||
|
{
|
||||||
|
NodeService nodeService = mock(NodeService.class);
|
||||||
|
when(nodeService.getProperty(requesterNodeRef, ContentModel.PROP_EMAIL)).thenReturn(requesterMail);
|
||||||
|
return nodeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up an ActionService which returns the mailAction field when
|
||||||
|
* createAction() is called.
|
||||||
|
*
|
||||||
|
* @return ActionService
|
||||||
|
*/
|
||||||
|
private ActionService mockActionService()
|
||||||
|
{
|
||||||
|
mailAction = mock(Action.class);
|
||||||
|
|
||||||
|
ActionService actionService = mock(ActionService.class);
|
||||||
|
when(actionService.createAction(MailActionExecuter.NAME)).thenReturn(mailAction);
|
||||||
|
return actionService;
|
||||||
|
}
|
||||||
|
}
|
@@ -115,7 +115,7 @@ public class InviteSenderTest extends TestCase
|
|||||||
private final MessageService messageService = mock(MessageService.class);
|
private final MessageService messageService = mock(MessageService.class);
|
||||||
private Action mailAction;
|
private Action mailAction;
|
||||||
private SiteInfo siteInfo = mock(SiteInfo.class);
|
private SiteInfo siteInfo = mock(SiteInfo.class);
|
||||||
private InviteSender sender;
|
private InviteNominatedSender sender;
|
||||||
private Map<String,Serializable> lastSetMailModel;
|
private Map<String,Serializable> lastSetMailModel;
|
||||||
|
|
||||||
protected void testSendMailWorkingPath(
|
protected void testSendMailWorkingPath(
|
||||||
@@ -355,8 +355,8 @@ public class InviteSenderTest extends TestCase
|
|||||||
properties.put(wfVarInviteeGenPassword, password);
|
properties.put(wfVarInviteeGenPassword, password);
|
||||||
properties.put(wfVarInviteTicket, ticket);
|
properties.put(wfVarInviteTicket, ticket);
|
||||||
properties.put(wfVarServerPath, path);
|
properties.put(wfVarServerPath, path);
|
||||||
properties.put(InviteSender.WF_PACKAGE, packageId);
|
properties.put(InviteNominatedSender.WF_PACKAGE, packageId);
|
||||||
properties.put(InviteSender.WF_INSTANCE_ID, instanceId);
|
properties.put(InviteNominatedSender.WF_INSTANCE_ID, instanceId);
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +366,7 @@ public class InviteSenderTest extends TestCase
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
ServiceRegistry services = mockServices();
|
ServiceRegistry services = mockServices();
|
||||||
Repository repository = mockRepository();
|
Repository repository = mockRepository();
|
||||||
sender = new InviteSender(services, repository, messageService);
|
sender = new InviteNominatedSender(services, repository, messageService);
|
||||||
lastSetMailModel = null;
|
lastSetMailModel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user