diff --git a/config/alfresco/invitation-service-context.xml b/config/alfresco/invitation-service-context.xml
index 7ce94a0488..3fa9e6c854 100644
--- a/config/alfresco/invitation-service-context.xml
+++ b/config/alfresco/invitation-service-context.xml
@@ -24,6 +24,10 @@
+
+
+
+
@@ -78,16 +82,10 @@
-
-
-
-
-
-
-
+
sendInvitePropertyNames = Arrays.asList(wfVarInviteeUserName,//
+ wfVarResourceName,//
+ wfVarInviterUserName,//
+ wfVarInviteeUserName,//
+ wfVarRole,//
+ wfVarInviteeGenPassword,//
+ wfVarResourceName,//
+ wfVarInviteTicket,//
+ wfVarServerPath,//
+ wfVarAcceptUrl,//
+ wfVarRejectUrl,
+ InviteSender.WF_INSTANCE_ID);
+
/**
* Services
*/
@@ -117,6 +150,11 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
private PasswordGenerator passwordGenerator;
private PolicyComponent policyComponent;
private SysAdminParams sysAdminParams;
+ private TemplateService templateService;
+ private Repository repositoryHelper;
+ private ServiceRegistry serviceRegistry;
+ private MessageService messageService;
+ private InviteSender inviteSender;
// maximum number of tries to generate a invitee user name which
// does not already belong to an existing person
@@ -196,7 +234,10 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
PropertyCheck.mandatory(this, "UserNameGenerator", usernameGenerator);
PropertyCheck.mandatory(this, "PasswordGenerator", passwordGenerator);
PropertyCheck.mandatory(this, "PolicyComponent", policyComponent);
-
+ PropertyCheck.mandatory(this, "templateService", templateService);
+
+ this.inviteSender = new InviteSender(serviceRegistry, repositoryHelper, messageService);
+
//
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
SiteModel.TYPE_SITE, new JavaBehaviour(this, "beforeDeleteNode"));
@@ -1763,4 +1804,221 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
{
this.sysAdminParams = sysAdminParams;
}
+
+ public void setTemplateService(TemplateService templateService)
+ {
+ this.templateService = templateService;
+ }
+
+ /**
+ * @param messageService the messageService to set
+ */
+ public void setMessageService(MessageService messageService)
+ {
+ this.messageService = messageService;
+ }
+
+ /**
+ * @param repositoryHelper the repositoryHelper to set
+ */
+ public void setRepositoryHelper(Repository repositoryHelper)
+ {
+ this.repositoryHelper = repositoryHelper;
+ }
+
+ /**
+ * @param serviceRegistry the serviceRegistry to set
+ */
+ public void setServiceRegistry(ServiceRegistry serviceRegistry)
+ {
+ this.serviceRegistry = serviceRegistry;
+ }
+
+ @Override
+ public void acceptNominatedInvitation(String siteName, final String invitee, String role, String inviter)
+ {
+ AuthenticationUtil.runAsSystem(new RunAsWork()
+ {
+ public Void doWork() throws Exception
+ {
+ if (authenticationService.isAuthenticationMutable(invitee))
+ {
+ authenticationService.setAuthenticationEnabled(invitee, true);
+ }
+ return null;
+ }
+ });
+ addSiteMembership(invitee, siteName, role, inviter, false);
+ }
+
+ @Override
+ public void approveModeratedInvitation(String siteName, String invitee, String role, String reviewer)
+ {
+ addSiteMembership(invitee, siteName, role, reviewer, false);
+ }
+
+ /**
+ * Add Invitee to Site with the site role that the inviter "started" the invite process with
+ * @param invitee
+ * @param siteName
+ * @param role
+ * @param runAsUser
+ * @param siteService
+ * @param overrideExisting
+ */
+ public void addSiteMembership(final String invitee, final String siteName, final String role, final String runAsUser, final boolean overrideExisting)
+ {
+ AuthenticationUtil.runAs(new RunAsWork()
+ {
+ public Void doWork() throws Exception
+ {
+ if (overrideExisting || !siteService.isMember(siteName, invitee))
+ {
+ siteService.setMembership(siteName, invitee, role);
+ }
+ return null;
+ }
+
+ }, runAsUser);
+ }
+
+ @Override
+ public void rejectModeratedInvitation(String siteName, String invitee, String role, String reviewer, String resourceType, String reviewComments)
+ {
+ // Do nothing if emails disabled.
+ if (isSendEmails() == false)
+ {
+ return;
+ }
+
+ // send email to the invitee if possible - but don't fail the rejection if email cannot be sent
+ try
+ {
+ // Build our model
+ Map model = new HashMap(8, 1.0f);
+ model.put("resourceName", siteName);
+ model.put("resourceType", resourceType);
+ model.put("inviteeRole", role);
+ model.put("reviewComments", reviewComments);
+ model.put("reviewer", reviewer);
+ model.put("inviteeUserName", invitee);
+
+ // Process the template
+ // Note - because we use a classpath template, rather than a Data Dictionary
+ // one, we can't have the MailActionExecutor do the template for us
+ String emailMsg = templateService.processTemplate("freemarker", REJECT_TEMPLATE, model);
+
+ // Send
+ Action emailAction = actionService.createAction("mail");
+ emailAction.setParameterValue(MailActionExecuter.PARAM_TO, nodeService.getProperty(personService.getPerson(invitee), ContentModel.PROP_EMAIL));
+ emailAction.setParameterValue(MailActionExecuter.PARAM_FROM, nodeService.getProperty(personService.getPerson(reviewer), ContentModel.PROP_EMAIL));
+ // TODO Localize this.
+ emailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Rejected invitation to web site:" + siteName);
+ emailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, emailMsg);
+ emailAction.setExecuteAsynchronously(true);
+ actionService.executeAction(emailAction, null);
+ }
+ catch (Exception e)
+ {
+ // Swallow exception
+ logger.error("unable to send reject email", e);
+ }
+ }
+
+ @Override
+ public void deleteAuthenticationIfUnused(final String invitee, final String currentInviteId)
+ {
+ AuthenticationUtil.runAs(new RunAsWork