diff --git a/config/alfresco/templates/activities/org/alfresco/comments/comment-created.atomentry.ftl b/config/alfresco/templates/activities/org/alfresco/comments/comment-created.atomentry.ftl index af4f3c930b..d0d522d4fe 100644 --- a/config/alfresco/templates/activities/org/alfresco/comments/comment-created.atomentry.ftl +++ b/config/alfresco/templates/activities/org/alfresco/comments/comment-created.atomentry.ftl @@ -3,12 +3,12 @@ <#assign username = firstName + " " + lastName> - New comment for ${(itemTitle!'')?html?xml} + ${username?html?xml} commented on ${(itemTitle!'')?html?xml} ${id} ${xmldate(date)} - ${(itemTitle!'unknown')?html}]]> + ${(itemTitle!'unknown')?html}]]> ${userId!""} diff --git a/config/alfresco/templates/activities/org/alfresco/comments/comment-deleted.atomentry.ftl b/config/alfresco/templates/activities/org/alfresco/comments/comment-deleted.atomentry.ftl index eb4db3277d..ec7cfc82db 100644 --- a/config/alfresco/templates/activities/org/alfresco/comments/comment-deleted.atomentry.ftl +++ b/config/alfresco/templates/activities/org/alfresco/comments/comment-deleted.atomentry.ftl @@ -3,12 +3,12 @@ <#assign username = firstName + " " + lastName> - Comment deleted + ${username} deleted comment ${id} ${xmldate(date)} - ${(itemTitle!'unknown')?html}]]> + ${(itemTitle!'unknown')?html}]]> ${userId!""} diff --git a/config/alfresco/templates/activities/org/alfresco/comments/comment-updated.atomentry.ftl b/config/alfresco/templates/activities/org/alfresco/comments/comment-updated.atomentry.ftl index d5941efaa3..aaab34ffe1 100644 --- a/config/alfresco/templates/activities/org/alfresco/comments/comment-updated.atomentry.ftl +++ b/config/alfresco/templates/activities/org/alfresco/comments/comment-updated.atomentry.ftl @@ -3,12 +3,12 @@ <#assign username = firstName + " " + lastName> - Comment updated + ${username?html?xml} updated comment ${id} ${xmldate(date)} - ${(itemTitle!'unknown')?html}]]> + ${(itemTitle!'unknown')?html}]]> ${userId!""} diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite-by-ticket.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite-by-ticket.get.desc.xml new file mode 100644 index 0000000000..a55ddf8227 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite-by-ticket.get.desc.xml @@ -0,0 +1,8 @@ + + Invite by ticket + Returns invite information for a given inviteId and inviteTicket. No authentication is required + /api/invite/{inviteId}/{inviteTicket} + + none + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite-by-ticket.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite-by-ticket.get.json.ftl new file mode 100644 index 0000000000..2e92640872 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite-by-ticket.get.json.ftl @@ -0,0 +1,4 @@ +<#import "invite.lib.ftl" as inviteLib/> +{ + "invite" : <@inviteLib.inviteJSON invite=invite/> +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite.get.json.ftl index 3055f92b61..c0ba334809 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite.get.json.ftl @@ -3,6 +3,9 @@ <#if inviteId??> "inviteId" : "${inviteId}", + <#if inviteTicket??> + "inviteTicket" : "${inviteTicket}", + <#if inviteeUserName??> "inviteeUserName" : "${inviteeUserName}", diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite.lib.ftl index 7a84a78770..fe67edc529 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/invite.lib.ftl @@ -32,7 +32,12 @@ }, "role" : "${invite.role}", - "siteShortName" : "${invite.siteShortName!''}", + "site" : { + "shortName" : "${invite.siteShortName!''}" + <#if invite.siteInfo??> + , "title" : "${invite.siteInfo.title}" + + }, "invitationStatus" : "${invite.invitationStatus}", "sentInviteDate" : "${invite.sentInviteDate?string("MMM dd yyyy HH:mm:ss 'GMT'Z '('zzz')'")}" } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.delete.desc.xml new file mode 100644 index 0000000000..5e999e0e3f --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.delete.desc.xml @@ -0,0 +1,8 @@ + + Invite reject + Rejects an invite + /api/invite/{inviteId}/{inviteTicket} + + none + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.delete.json.ftl similarity index 100% rename from config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.get.json.ftl rename to config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.delete.json.ftl diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.get.desc.xml deleted file mode 100644 index 7e3dfd7acb..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.get.desc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - Invite Response - Processes invite response from Invitee ({response} is either 'accept' or 'reject' ) - /api/inviteresponse/{response}?inviteId={inviteId}&inviteeUserName={inviteeUserName}&siteShortName={siteShortName} - - none - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.get.html.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.get.html.ftl deleted file mode 100644 index dcda51d9c1..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.get.html.ftl +++ /dev/null @@ -1,7 +0,0 @@ -<#if response == "accept"> -

Your acceptance to join site ${siteShortName} has been processed

-<#elseif response == "reject"> -

Your rejection to join site ${siteShortName} has been processed

-<#else> -

Error: unknown invite response ${response}

- diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.put.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.put.desc.xml new file mode 100644 index 0000000000..abcea279d2 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.put.desc.xml @@ -0,0 +1,8 @@ + + Invite accept + Accepts an invite + /api/invite/{inviteId}/{inviteTicket} + + none + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.put.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.put.json.ftl new file mode 100644 index 0000000000..c0adf83a3a --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/invite/inviteresponse.put.json.ftl @@ -0,0 +1,4 @@ +{ + "response" : "${response}", + "siteShortName" : "${siteShortName}" +} diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/memberships.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/memberships.get.js index c1ff2089ef..8324da8ff0 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/memberships.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/memberships.get.js @@ -16,11 +16,13 @@ for (userName in memberships) } // also copy over the memberships. -var mems = []; +var mems = {}; +var pos = 0; // memberships[userName] won't return the correct value if userName is a digit-only value for (userName in memberships) { - var membershipType = memberships[userName]; + var membershipType = memberships[pos]; mems["_" + userName] = membershipType; // make sure the keys are strings + pos++; } // Pass the information to the template diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 82e57294a7..ee76393ec3 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -294,7 +294,6 @@ - @@ -302,18 +301,29 @@ - - + - + + + + + + + + + + + - @@ -326,11 +336,22 @@ class="org.alfresco.repo.web.scripts.invite.Invites" parent="webscript"> - - + + + + + + + + + + + diff --git a/source/java/org/alfresco/repo/web/scripts/invite/Invite.java b/source/java/org/alfresco/repo/web/scripts/invite/Invite.java index 551164f5db..0b0e873e7d 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/Invite.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/Invite.java @@ -45,9 +45,6 @@ import org.alfresco.service.cmr.workflow.WorkflowDefinition; import org.alfresco.service.cmr.workflow.WorkflowPath; import org.alfresco.service.cmr.workflow.WorkflowService; import org.alfresco.service.cmr.workflow.WorkflowTask; -import org.alfresco.service.cmr.workflow.WorkflowTaskQuery; -import org.alfresco.service.cmr.workflow.WorkflowTaskState; -import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.GUID; import org.alfresco.web.scripts.DeclarativeWebScript; @@ -67,10 +64,10 @@ public class Invite extends DeclarativeWebScript { private static final String ACTION_START = "start"; private static final String ACTION_CANCEL = "cancel"; - private static final String TRANSITION_SEND_INVITE = "sendInvite"; private static final String MODEL_PROP_KEY_ACTION = "action"; private static final String MODEL_PROP_KEY_INVITE_ID = "inviteId"; + private static final String MODEL_PROP_KEY_INVITE_TICKET = "inviteTicket"; private static final String MODEL_PROP_KEY_INVITEE_USER_NAME = "inviteeUserName"; private static final String MODEL_PROP_KEY_INVITEE_FIRSTNAME = "inviteeFirstName"; private static final String MODEL_PROP_KEY_INVITEE_LASTNAME = "inviteeLastName"; @@ -93,30 +90,12 @@ public class Invite extends DeclarativeWebScript private PersonService personService; private AuthenticationService authenticationService; private MutableAuthenticationDao mutableAuthenticationDao; - private NamespaceService namespaceService; private SiteService siteService; private NodeService nodeService; // user name and password generation beans private UserNameGenerator usernameGenerator; private PasswordGenerator passwordGenerator; - - // workflow properties - public static final String WF_PROP_SERVER_PATH = "wf:serverPath"; - public static final String WF_PROP_ACCEPT_URL = "wf:acceptUrl"; - public static final String WF_PROP_REJECT_URL = "wf:rejectUrl"; - public static final String WF_PROP_INVITE_TICKET = "wf:inviteTicket"; - public static final String WF_PROP_INVITER_USER_NAME = "wf:inviterUserName"; - public static final String WF_PROP_INVITEE_USER_NAME = "wf:inviteeUserName"; - public static final String WF_PROP_INVITEE_FIRSTNAME = "wf:inviteeFirstName"; - public static final String WF_PROP_INVITEE_LASTNAME = "wf:inviteeLastName"; - public static final String WF_PROP_SITE_SHORT_NAME = "wf:siteShortName"; - public static final String WF_PROP_INVITEE_SITE_ROLE = "wf:inviteeSiteRole"; - public static final String WF_PROP_SENT_INVITE_DATE = "wf:sentInviteDate"; - private static final String WF_PROP_INVITEE_GEN_PASSWORD = "wf:inviteeGenPassword"; - - public static final String WF_INVITE_TASK_INVITE_TO_SITE = "wf:inviteToSiteTask"; - public static final String WORKFLOW_DEFINITION_NAME = "jbpm$wf:invite"; // maximum number of tries to generate a invitee user name which // does not already belong to an existing person @@ -168,17 +147,6 @@ public class Invite extends DeclarativeWebScript this.mutableAuthenticationDao = mutableAuthenticationDao; } - /** - * Set the namespace service - * - * @param namespaceService the namespace service to set - */ - public void setNamespaceService( - NamespaceService namespaceService) - { - this.namespaceService = namespaceService; - } - /** * Set the user name generator service * @@ -454,7 +422,7 @@ public class Invite extends DeclarativeWebScript * @param siteShortName * @return whether there is an invite in progress */ - private boolean isInviteAlreadyInProgress(String inviteeUserName, String siteShortName) + /*private boolean isInviteAlreadyInProgress(String inviteeUserName, String siteShortName) { // create workflow task query WorkflowTaskQuery wfTaskQuery = new WorkflowTaskQuery(); @@ -462,16 +430,15 @@ public class Invite extends DeclarativeWebScript // set query properties to look up task instances of inviteToSite task // in active invite workflow instances wfTaskQuery.setActive(Boolean.TRUE); - wfTaskQuery.setProcessName(QName.createQName("wf:invite", this.namespaceService)); + wfTaskQuery.setProcessName(InviteWorkflowModel.WF_PROCESS_INVITE); wfTaskQuery.setTaskState(WorkflowTaskState.COMPLETED); - wfTaskQuery.setTaskName(QName.createQName(Invite.WF_INVITE_TASK_INVITE_TO_SITE, - this.namespaceService)); + wfTaskQuery.setTaskName(InviteWorkflowModel.WF_INVITE_TASK_INVITE_TO_SITE); // set query process custom properties HashMap wfQueryProps = new HashMap(2, 1.0f); - wfQueryProps.put(QName.createQName(Invite.WF_PROP_INVITEE_USER_NAME, this.namespaceService), + wfQueryProps.put(InviteWorkflowModel.WF_PROP_INVITEE_USER_NAME, inviteeUserName); - wfQueryProps.put(QName.createQName(Invite.WF_PROP_SITE_SHORT_NAME, this.namespaceService), + wfQueryProps.put(InviteWorkflowModel.WF_PROP_SITE_SHORT_NAME, siteShortName); wfTaskQuery.setTaskCustomProps(wfQueryProps); @@ -483,7 +450,7 @@ public class Invite extends DeclarativeWebScript // throw web script exception if person (having the given invitee email address) already // has an invitation in progress for the given site short name return (inviteTasksInProgress.size() > 0); - } + }*/ /** * Starts the Invite workflow @@ -585,40 +552,40 @@ public class Invite extends DeclarativeWebScript // WorkflowDefinition wfDefinition = this.workflowService - .getDefinitionByName(WORKFLOW_DEFINITION_NAME); + .getDefinitionByName(InviteWorkflowModel.WORKFLOW_DEFINITION_NAME); // handle workflow definition does not exist if (wfDefinition == null) { throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Workflow definition " + "for name " - + WORKFLOW_DEFINITION_NAME + " does not exist"); + + InviteWorkflowModel.WORKFLOW_DEFINITION_NAME + " does not exist"); } // create workflow properties Map workflowProps = new HashMap( 7); - workflowProps.put(QName.createQName(WF_PROP_INVITER_USER_NAME, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_INVITER_USER_NAME, inviterUserName); - workflowProps.put(QName.createQName(WF_PROP_INVITEE_USER_NAME, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_INVITEE_USER_NAME, inviteeUserName); - workflowProps.put(QName.createQName(WF_PROP_INVITEE_FIRSTNAME, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_INVITEE_FIRSTNAME, inviteeFirstName); - workflowProps.put(QName.createQName(WF_PROP_INVITEE_LASTNAME, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_INVITEE_LASTNAME, inviteeLastName); - workflowProps.put(QName.createQName(WF_PROP_INVITEE_GEN_PASSWORD, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_INVITEE_GEN_PASSWORD, inviteePassword); - workflowProps.put(QName.createQName(WF_PROP_SITE_SHORT_NAME, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_SITE_SHORT_NAME, siteShortName); - workflowProps.put(QName.createQName(WF_PROP_INVITEE_SITE_ROLE, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_INVITEE_SITE_ROLE, inviteeSiteRole); - workflowProps.put(QName.createQName(WF_PROP_SERVER_PATH, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_SERVER_PATH, serverPath); - workflowProps.put(QName.createQName(WF_PROP_ACCEPT_URL, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_ACCEPT_URL, acceptUrl); - workflowProps.put(QName.createQName(WF_PROP_REJECT_URL, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_REJECT_URL, rejectUrl); - workflowProps.put(QName.createQName(WF_PROP_INVITE_TICKET, this.namespaceService), + workflowProps.put(InviteWorkflowModel.WF_PROP_INVITE_TICKET, inviteTicket); // start the workflow @@ -644,11 +611,11 @@ public class Invite extends DeclarativeWebScript // first task in workflow task list associated with the workflow path id above // should be "wf:inviteToSiteTask", otherwise throw web script exception String wfTaskTitle = wfTasks.get(0).title; - if (!wfTaskTitle.equals(WF_INVITE_TASK_INVITE_TO_SITE)) + if (!wfTaskTitle.equals("wf:inviteToSiteTask")) { throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "First workflow task found on workflow path ID: " + wfPathId - + " should be " + WF_INVITE_TASK_INVITE_TO_SITE); + + " should be " + "wf:inviteToSiteTask"); } // get "inviteToSite" task @@ -660,11 +627,12 @@ public class Invite extends DeclarativeWebScript Map wfTaskProps = new HashMap(1, 1.0f); wfTaskProps.put(WorkflowModel.ASSOC_PACKAGE, wfPackage); this.workflowService.updateTask(wfStartTask.id, wfTaskProps, null, null); - this.workflowService.endTask(wfStartTask.id, TRANSITION_SEND_INVITE); + this.workflowService.endTask(wfStartTask.id, InviteWorkflowModel.WF_TRANSITION_SEND_INVITE); // add model properties for template to render model.put(MODEL_PROP_KEY_ACTION, ACTION_START); model.put(MODEL_PROP_KEY_INVITE_ID, workflowId); + model.put(MODEL_PROP_KEY_INVITE_TICKET, inviteTicket); model.put(MODEL_PROP_KEY_INVITEE_USER_NAME, inviteeUserName); model.put(MODEL_PROP_KEY_INVITEE_FIRSTNAME, inviteeFirstName); model.put(MODEL_PROP_KEY_INVITEE_LASTNAME, inviteeLastName); diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteByTicket.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteByTicket.java new file mode 100644 index 0000000000..38f1712a70 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteByTicket.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.invite; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.site.SiteService; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.workflow.WorkflowService; +import org.alfresco.service.cmr.workflow.WorkflowTask; +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; + +/** + * Web Script which returns invite information given an inviteId and inviteTicket. + * + * Note: This Web Script is accessible without authentication. + * + * @author glen dot johnson at alfresco dot com + */ +public class InviteByTicket extends DeclarativeWebScript +{ + + // service instances + private WorkflowService workflowService; + private ServiceRegistry serviceRegistry; + private SiteService siteService; + + /** + * Set the workflow service property + * + * @param workflowService + * the workflow service to set + */ + public void setWorkflowService(WorkflowService workflowService) + { + this.workflowService = workflowService; + } + + public void setServiceRegistry(ServiceRegistry serviceRegistry) { + this.serviceRegistry = serviceRegistry; + } + + public void setSiteService(SiteService siteService) { + this.siteService = siteService; + } + + /* + * (non-Javadoc) + * + * @see + * org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco + * .web.scripts.WebScriptRequest, + * org.alfresco.web.scripts.WebScriptResponse) + */ + @Override + protected Map executeImpl(WebScriptRequest req, + Status status) + { + // initialise model to pass on for template to render + Map model = new HashMap(); + + // Extract inviteId and inviteTicket + String extPath = req.getExtensionPath(); + int separatorIndex = extPath.indexOf('/'); + if (separatorIndex < 0) + { + // should not happen as descriptor would not match + throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, + "Parameters missing"); + } + String inviteId = extPath.substring(0, separatorIndex); + String inviteTicket = extPath.substring(separatorIndex + 1); + + // authenticate as system for the rest of the webscript + AuthenticationUtil.setSystemUserAsCurrentUser(); + + // find the workflow for the given id + WorkflowTask workflowTask = InviteHelper.findInviteStartTask(inviteId, workflowService); + if (workflowTask == null) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "No invite found for given id"); + } + + // check whether tickets match, throw error otherwise + String ticket = (String) workflowTask.properties.get( + InviteWorkflowModel.WF_PROP_INVITE_TICKET); + if (ticket == null || (! ticket.equals(inviteTicket))) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "Ticket mismatch"); + } + + // return the invite info + InviteInfo inviteInfo = InviteHelper.getPendingInviteInfo(workflowTask, serviceRegistry, siteService); + model.put("invite", inviteInfo); + return model; + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteHelper.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteHelper.java index a3547968b0..8c78e559ad 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteHelper.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteHelper.java @@ -24,8 +24,15 @@ */ package org.alfresco.repo.web.scripts.invite; +import java.util.Date; import java.util.List; +import org.alfresco.repo.jscript.ScriptNode; +import org.alfresco.repo.site.SiteInfo; +import org.alfresco.repo.site.SiteService; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.workflow.WorkflowService; import org.alfresco.service.cmr.workflow.WorkflowTask; import org.alfresco.service.cmr.workflow.WorkflowTaskQuery; @@ -38,58 +45,98 @@ import org.alfresco.service.namespace.QName; * more than one Invite Service Web Script */ public class InviteHelper -{ +{ /** - * Gets the invitee site role from the invite - * workflow instance associated with the given invite ID. - * i.e. if the inviter 'starts' an invite (which is allocated some invite ID - * '12345' when it is processed), and that invite is requesting an invitee to - * to join some site under a given site role, then that site role is returned - * by this method when invite ID '12345' is passed in. + * Find an invite start task given the task id. * - * @param inviteId the ID of the invitation (invite workflow instance) - * from which to retrieve the invitee site role - * @return the site role under which the invitee was invited to - * join the site. Returns
null
if no invite - * workflow instance was found matching the given invite ID + * @return a WorkflowTask or null if not found. */ - static String getInviteeSiteRoleFromInvite(String inviteId, WorkflowService workflowService, - NamespaceService namespaceService) + public static WorkflowTask findInviteStartTask(String inviteId, WorkflowService workflowService) { // create workflow task query WorkflowTaskQuery wfTaskQuery = new WorkflowTaskQuery(); - + wfTaskQuery.setProcessId(inviteId); // set process name to "wf:invite" so that only tasks associated with // invite workflow instances are returned by query - wfTaskQuery.setProcessName(QName.createQName("wf:invite", namespaceService)); + wfTaskQuery.setProcessName(QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "invite")); // pick up the start task because it has the "wf:inviteeSiteRole" property set with the // site role value that we want to retrieve wfTaskQuery.setTaskState(WorkflowTaskState.COMPLETED); - wfTaskQuery.setTaskName(QName.createQName(Invite.WF_INVITE_TASK_INVITE_TO_SITE, namespaceService)); + wfTaskQuery.setTaskName(InviteWorkflowModel.WF_INVITE_TASK_INVITE_TO_SITE); // query for invite workflow task associate List inviteStartTasks = workflowService .queryTasks(wfTaskQuery); - // if no results were returned for given inviteID, then return - // site role as null - if (inviteStartTasks.size() == 0) + // should also be 0 or 1 + if (inviteStartTasks.size() < 1) { return null; } else { - // there should be only one start task returned for the given invite ID - // so just take the first one in the list - WorkflowTask inviteStartTask = inviteStartTasks.get(0); - - String inviteeSiteRole = (String) inviteStartTask.properties.get( - QName.createQName(Invite.WF_PROP_INVITEE_SITE_ROLE, namespaceService)); - - return inviteeSiteRole; + return inviteStartTasks.get(0); } } + + /** + * Returns an InviteInfo object usable for rendering the response. + * + * @return object containing invite information + */ + public static InviteInfo getPendingInviteInfo(WorkflowTask workflowTask, + ServiceRegistry serviceRegistry, SiteService siteService) + { + PersonService personService = serviceRegistry.getPersonService(); + + // get the inviter, invitee, role and site short name + String inviterUserNameProp = (String) workflowTask.properties.get( + InviteWorkflowModel.WF_PROP_INVITER_USER_NAME); + String inviteeUserNameProp = (String) workflowTask.properties.get( + InviteWorkflowModel.WF_PROP_INVITEE_USER_NAME); + String role = (String) workflowTask.properties.get( + InviteWorkflowModel.WF_PROP_INVITEE_SITE_ROLE); + String siteShortNameProp = (String) workflowTask.properties.get( + InviteWorkflowModel.WF_PROP_SITE_SHORT_NAME); + + // fetch the site object + SiteInfo siteInfo = siteService.getSite(siteShortNameProp); + + // get workflow instance id (associated with workflow task) to place + // as "inviteId" onto model + String workflowId = workflowTask.path.instance.id; + + // set the invite start date to the time the workflow instance + // (associated with the task) was started + Date sentInviteDate = workflowTask.path.instance.startDate; + + // TODO: glen johnson at alfresco com - as this web script only returns + // pending invites, this is hard coded to "pending" for now + String invitationStatus = InviteInfo.INVITATION_STATUS_PENDING; + + // fetch the person node for the inviter + NodeRef inviterRef = personService.getPerson(inviterUserNameProp); + ScriptNode inviterPerson = null; + if (inviterRef != null) + { + inviterPerson = new ScriptNode(inviterRef, serviceRegistry); + } + + // fetch the person node for the invitee + NodeRef inviteeRef = personService.getPerson(inviteeUserNameProp); + ScriptNode inviteePerson = null; + if (inviteeRef != null) + { + inviteePerson = new ScriptNode(inviteeRef, serviceRegistry); + } + + // create and add InviteInfo to inviteInfoList + InviteInfo inviteInfo = new InviteInfo(invitationStatus, inviterUserNameProp, inviterPerson, + inviteeUserNameProp, inviteePerson, role, siteShortNameProp, siteInfo, sentInviteDate, workflowId); + + return inviteInfo; + } } diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteInfo.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteInfo.java index 544997c2a6..a06cee702c 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteInfo.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteInfo.java @@ -27,6 +27,7 @@ package org.alfresco.repo.web.scripts.invite; import java.util.Date; import org.alfresco.repo.jscript.ScriptNode; +import org.alfresco.repo.site.SiteInfo; /** * Holds properties pertaining to an invitation that has been sent out by a Site Manager (Inviter) @@ -36,6 +37,11 @@ import org.alfresco.repo.jscript.ScriptNode; */ public class InviteInfo { + // invitation statuses + public static final String INVITATION_STATUS_PENDING = "pending"; + public static final String INVITATION_STATUS_ACCEPTED = "accepted"; + public static final String INVITATION_STATUS_REJECTED = "rejected"; + // private instances to hold property values private String invitationStatus; private String inviterUserName; @@ -44,12 +50,13 @@ public class InviteInfo private ScriptNode inviteePerson; private String role; private String siteShortName; + private SiteInfo siteInfo; private Date sentInviteDate; private String inviteId; public InviteInfo(String invitationStatus, String inviterUserName, ScriptNode inviterPerson, String inviteeUserName, ScriptNode inviteePerson, String role, - String siteShortName, Date sentInviteDate, String inviteId) + String siteShortName, SiteInfo siteInfo, Date sentInviteDate, String inviteId) { this.invitationStatus = invitationStatus; this.inviterUserName = inviterUserName; @@ -58,6 +65,7 @@ public class InviteInfo this.inviteePerson = inviteePerson; this.role = role; this.siteShortName = siteShortName; + this.siteInfo = siteInfo; this.sentInviteDate = sentInviteDate; this.inviteId = inviteId; } @@ -151,4 +159,9 @@ public class InviteInfo { return role; } + + public SiteInfo getSiteInfo() { + return siteInfo; + } + } diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java index 50789d4b44..356e947c9d 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java @@ -37,7 +37,6 @@ import org.alfresco.service.cmr.workflow.WorkflowService; import org.alfresco.service.cmr.workflow.WorkflowTask; import org.alfresco.service.cmr.workflow.WorkflowTaskQuery; import org.alfresco.service.cmr.workflow.WorkflowTaskState; -import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.web.scripts.DeclarativeWebScript; import org.alfresco.web.scripts.Status; @@ -88,13 +87,6 @@ public class InviteResponse extends DeclarativeWebScript private static final String RESPONSE_ACCEPT = "accept"; private static final String RESPONSE_REJECT = "reject"; - private static final String WF_TASK_ACCEPT_INVITE = "wf:acceptInviteTask"; - private static final String WF_TASK_REJECT_INVITE = "wf:rejectInviteTask"; - private static final String WF_TASK_INVITE_PENDING = "wf:invitePendingTask"; - private static final String WF_TRANSITION_ACCEPT = "accept"; - private static final String WF_TRANSITION_REJECT = "reject"; - private static final String WF_TRANSITION_ACCEPT_INVITE_END = "end"; - private static final String WF_TRANSITION_REJECT_INVITE_END = "end"; private static final String MODEL_PROP_KEY_RESPONSE = "response"; private static final String MODEL_PROP_KEY_SITE_SHORT_NAME = "siteShortName"; private static final String USER_ADMIN = "admin"; @@ -104,7 +96,6 @@ public class InviteResponse extends DeclarativeWebScript private MutableAuthenticationDao mutableAuthenticationDao; private SiteService siteService; private PersonService personService; - private NamespaceService namespaceService; /** * Sets the workflow service property @@ -150,17 +141,6 @@ public class InviteResponse extends DeclarativeWebScript { this.personService = personService; } - - /** - * Sets the namespaceService property - * - * @param namespaceService - * the namespace service to set - */ - public void setNamespaceService(NamespaceService namespaceService) - { - this.namespaceService = namespaceService; - } /* * (non-Javadoc) @@ -177,57 +157,52 @@ public class InviteResponse extends DeclarativeWebScript // initialise model to pass on for template to render Map model = new HashMap(); - // get the URL parameter values - String inviteId = req.getParameter("inviteId"); - String inviteeUserName = req.getParameter("inviteeUserName"); - String siteShortName = req.getParameter("siteShortName"); - - // get the invite response value - String response = req.getExtensionPath(); - - // check that response has been provided - if ((response == null) || (response.length() == 0)) + // Extract inviteId and inviteTicket + /*String extPath = req.getExtensionPath(); + int separatorIndex = extPath.indexOf('/'); + if (separatorIndex < 0) { - // handle response not provided - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "response has not been provided as part of URL."); + // should not happen as descriptor would not match + throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, + "Parameters missing"); } - // check that invite id URL parameter has been provided - else if ((inviteId == null) || (inviteId.length() == 0)) + String inviteId = extPath.substring(0, separatorIndex); + String inviteTicket = extPath.substring(separatorIndex + 1);*/ + + String inviteId = req.getServiceMatch().getTemplateVars().get("inviteId"); + String inviteTicket = req.getServiceMatch().getTemplateVars().get("inviteTicket"); + + // fetch the start task - it might not exist if the workflow has been finished/canceled already + WorkflowTask inviteStartTask = InviteHelper.findInviteStartTask(inviteId, workflowService); + if (inviteStartTask == null) { - // handle invite id not provided - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "invite id parameter has not been provided in the URL."); + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "No invite workflow for given id found"); } - // check that inviteeUserName URL parameter has been provided - else if ((inviteeUserName == null) || (inviteeUserName.length() == 0)) + + // check the ticket for a match + String ticket = (String) inviteStartTask.properties.get(InviteWorkflowModel.WF_PROP_INVITE_TICKET); + if (ticket == null || (! ticket.equals(inviteTicket))) { - // handle inviteeUserName not provided - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "inviteeUserName parameter has not been provided in the URL."); + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "Invalid ticket"); } - // check that siteShortName URL parameter has been provided - else if ((siteShortName == null) || (siteShortName.length() == 0)) + + // process response + String method = req.getServiceMatch().getWebScript().getDescription().getMethod(); + if (method.equals("PUT")) { - // handle siteShortName not provided + acceptInvite(model, inviteId, inviteStartTask); + } + else if (method.equals("DELETE")) + { + rejectInvite(model, inviteId, inviteStartTask); + } + else + { + /* handle unrecognised method */ throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "siteShortName parameter has not been provided in the URL."); - } else - { - // process response - if (response.equals(RESPONSE_ACCEPT)) - { - acceptInvite(model, inviteId, inviteeUserName, siteShortName); - } else if (response.equals(RESPONSE_REJECT)) - { - rejectInvite(model, inviteId, inviteeUserName, siteShortName); - } else - { - /* handle unrecognised response */ - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "response, " + response - + ", provided in URL has not been recognised."); - } + "method " + method + " is not supported by this webscript."); } return model; @@ -241,17 +216,19 @@ public class InviteResponse extends DeclarativeWebScript * for rendering * @param inviteId * ID of invite - * @param inviteeUserName - * user name of invitee - * @param siteShortName - * short name of site for which invitee is accepting - * invitation to join + * @param inviteStartTask */ - private void acceptInvite(Map model, String inviteId, - String inviteeUserName, String siteShortName) + private void acceptInvite(Map model, String inviteId, WorkflowTask inviteStartTask) { + String inviteeUserName = (String) inviteStartTask.properties.get( + InviteWorkflowModel.WF_PROP_INVITEE_USER_NAME); + String siteShortName = (String) inviteStartTask.properties.get( + InviteWorkflowModel.WF_PROP_SITE_SHORT_NAME); + String inviteeSiteRole = (String) inviteStartTask.properties.get( + InviteWorkflowModel.WF_PROP_INVITEE_SITE_ROLE); + // complete the wf:invitePendingTask task because the invitation has been accepted - completeInviteTask(inviteId, QName.createQName(WF_TASK_INVITE_PENDING, this.namespaceService), WF_TRANSITION_ACCEPT); + completeInviteTask(inviteId, InviteWorkflowModel.WF_TASK_INVITE_PENDING, InviteWorkflowModel.WF_TRANSITION_ACCEPT); // TODO glen dot johnson at alfresco dot com - farm the code that follows (up until adding properties onto // the model) out into workflow action class that gets run when task wf:acceptInviteTask @@ -265,11 +242,7 @@ public class InviteResponse extends DeclarativeWebScript { this.mutableAuthenticationDao.setEnabled(inviteeUserName, true); } - - // retrieve the site role with which the invitee was invited to the site - String inviteeSiteRole = InviteHelper.getInviteeSiteRoleFromInvite(inviteId, this.workflowService, - this.namespaceService); - + // add Invitee to Site with the site role that the inviter "started" the invite process with RunAsWork setSiteMembershipWorker = new InviteResponse.SetSiteMembershipWorker( siteShortName, inviteeUserName, inviteeSiteRole); @@ -280,7 +253,7 @@ public class InviteResponse extends DeclarativeWebScript // starting from above where wf:invitePendingTask is completed, up to here). This code // block will soon be farmed out into a workflow action which gets executed when // wf:acceptInviteTask gets completed - completeInviteTask(inviteId, QName.createQName(WF_TASK_ACCEPT_INVITE, this.namespaceService), WF_TRANSITION_ACCEPT_INVITE_END); + completeInviteTask(inviteId, InviteWorkflowModel.WF_TASK_ACCEPT_INVITE, InviteWorkflowModel.WF_TRANSITION_ACCEPT_INVITE_END); // add model properties for template to render model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_ACCEPT); @@ -301,11 +274,15 @@ public class InviteResponse extends DeclarativeWebScript * short name of site for which invitee is rejecting * invitation to join */ - private void rejectInvite(Map model, String inviteId, - String inviteeUserName, String siteShortName) + private void rejectInvite(Map model, String inviteId, WorkflowTask inviteStartTask) { + String inviteeUserName = (String) inviteStartTask.properties.get( + InviteWorkflowModel.WF_PROP_INVITEE_USER_NAME); + String siteShortName = (String) inviteStartTask.properties.get( + InviteWorkflowModel.WF_PROP_SITE_SHORT_NAME); + // complete the wf:invitePendingTask task because the invitation has been accepted - completeInviteTask(inviteId, QName.createQName(WF_TASK_INVITE_PENDING, this.namespaceService), WF_TRANSITION_REJECT); + completeInviteTask(inviteId, InviteWorkflowModel.WF_TASK_INVITE_PENDING, InviteWorkflowModel.WF_TRANSITION_REJECT); // TODO glen dot johnson at alfresco dot com - farm the code that follows (up until adding properties onto // the model) out into workflow action class that gets run when task wf:rejectInviteTask @@ -331,7 +308,7 @@ public class InviteResponse extends DeclarativeWebScript // starting from above where wf:invitePendingTask is completed, up to here). This code // block will soon be farmed out into a workflow action which gets executed when // wf:rejectInviteTask gets completed - completeInviteTask(inviteId, QName.createQName(WF_TASK_REJECT_INVITE, this.namespaceService), WF_TRANSITION_REJECT_INVITE_END); + completeInviteTask(inviteId, InviteWorkflowModel.WF_TASK_REJECT_INVITE, InviteWorkflowModel.WF_TRANSITION_REJECT_INVITE_END); // add model properties for template to render model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_REJECT); @@ -364,7 +341,7 @@ public class InviteResponse extends DeclarativeWebScript // set process name to "wf:invite" so that only // invite workflow instances are considered by this query - wfTaskQuery.setProcessName(QName.createQName("wf:invite", this.namespaceService)); + wfTaskQuery.setProcessName(InviteWorkflowModel.WF_PROCESS_INVITE); // query for invite workflow tasks with the constructed query List wf_invite_tasks = this.workflowService diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java index 3d61ce85c7..4b53d1d53b 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteServiceTest.java @@ -494,18 +494,16 @@ public class InviteServiceTest extends BaseWebScriptTest // get hold of invite ID of started invite String inviteId = result.getString("inviteId"); + String inviteTicket = result.getString("inviteTicket"); // get hold of invitee user name that was generated as part of starting // the invite String inviteeUserName = result.getString("inviteeUserName"); // Invitee accepts invitation to a Site from Inviter - String acceptInviteUrl = URL_INVITERSP_SERVICE + "/" - + INVITE_RSP_ACCEPT + "?inviteId=" + inviteId - + "&inviteeUserName=" + inviteeUserName + "&siteShortName=" - + SITE_SHORT_NAME_INVITE_1; - MockHttpServletResponse response = getRequest(acceptInviteUrl, - Status.STATUS_OK); + String acceptInviteUrl = URL_INVITE_SERVICE + "/" + inviteId + "/" + inviteTicket; + MockHttpServletResponse response = putRequest(acceptInviteUrl, + Status.STATUS_OK, null, null); // // test that invitation represented by invite ID (of invitation started @@ -530,17 +528,15 @@ public class InviteServiceTest extends BaseWebScriptTest // get hold of invite ID of started invite String inviteId = result.getString("inviteId"); + String inviteTicket = result.getString("inviteTicket"); // get hold of invitee user name that was generated as part of starting // the invite String inviteeUserName = result.getString("inviteeUserName"); // Invitee rejects invitation to a Site from Inviter - String rejectInviteUrl = URL_INVITERSP_SERVICE + "/" - + INVITE_RSP_REJECT + "?inviteId=" + inviteId - + "&inviteeUserName=" + inviteeUserName + "&siteShortName=" - + SITE_SHORT_NAME_INVITE_1; - MockHttpServletResponse response = getRequest(rejectInviteUrl, + String rejectInviteUrl = URL_INVITE_SERVICE + "/" + inviteId + "/" + inviteTicket; + MockHttpServletResponse response = deleteRequest(rejectInviteUrl, Status.STATUS_OK); // @@ -646,6 +642,6 @@ public class InviteServiceTest extends BaseWebScriptTest JSONObject inviteJSONObj = getInvitesResult.getJSONArray("invites").getJSONObject(0); - assertEquals(siteShortName, inviteJSONObj.get("siteShortName")); + assertEquals(siteShortName, inviteJSONObj.getJSONObject("site").get("shortName")); } } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteWorkflowModel.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteWorkflowModel.java new file mode 100644 index 0000000000..dadaadd289 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteWorkflowModel.java @@ -0,0 +1,42 @@ +package org.alfresco.repo.web.scripts.invite; + +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; + +public interface InviteWorkflowModel { + + // process name + public static final QName WF_PROCESS_INVITE = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "invite"); + + // workflow definition name + public static final String WORKFLOW_DEFINITION_NAME = "jbpm$wf:invite"; + + // tasks + public static final QName WF_INVITE_TASK_INVITE_TO_SITE = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "inviteToSiteTask"); + public static final QName WF_TASK_ACCEPT_INVITE = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "acceptInviteTask"); + public static final QName WF_TASK_REJECT_INVITE = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "rejectInviteTask"); + public static final QName WF_TASK_INVITE_PENDING = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "invitePendingTask"); + + + // transition names + public static final String WF_TRANSITION_SEND_INVITE = "sendInvite"; + public static final String WF_TRANSITION_ACCEPT = "accept"; + public static final String WF_TRANSITION_REJECT = "reject"; + public static final String WF_TRANSITION_ACCEPT_INVITE_END = "end"; + public static final String WF_TRANSITION_REJECT_INVITE_END = "end"; + + // workflow properties + public static final QName WF_PROP_SERVER_PATH = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "serverPath"); + public static final QName WF_PROP_ACCEPT_URL = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "acceptUrl"); + public static final QName WF_PROP_REJECT_URL = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "rejectUrl"); + public static final QName WF_PROP_INVITE_TICKET = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "inviteTicket"); + public static final QName WF_PROP_INVITER_USER_NAME = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "inviterUserName"); + public static final QName WF_PROP_INVITEE_USER_NAME = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "inviteeUserName"); + public static final QName WF_PROP_INVITEE_FIRSTNAME = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "inviteeFirstName"); + public static final QName WF_PROP_INVITEE_LASTNAME = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "inviteeLastName"); + public static final QName WF_PROP_SITE_SHORT_NAME = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "siteShortName"); + public static final QName WF_PROP_INVITEE_SITE_ROLE = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "inviteeSiteRole"); + public static final QName WF_PROP_SENT_INVITE_DATE = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "sentInviteDate"); + public static final QName WF_PROP_INVITEE_GEN_PASSWORD = QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "inviteeGenPassword"); + +} diff --git a/source/java/org/alfresco/repo/web/scripts/invite/Invites.java b/source/java/org/alfresco/repo/web/scripts/invite/Invites.java index 76ab6e5a2d..3d5cbfbf35 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/Invites.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/Invites.java @@ -25,20 +25,16 @@ package org.alfresco.repo.web.scripts.invite; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.alfresco.repo.jscript.ScriptNode; +import org.alfresco.repo.site.SiteService; import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.workflow.WorkflowService; import org.alfresco.service.cmr.workflow.WorkflowTask; import org.alfresco.service.cmr.workflow.WorkflowTaskQuery; import org.alfresco.service.cmr.workflow.WorkflowTaskState; -import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.web.scripts.DeclarativeWebScript; import org.alfresco.web.scripts.Status; @@ -76,17 +72,11 @@ public class Invites extends DeclarativeWebScript // model key names private static final String MODEL_KEY_NAME_INVITES = "invites"; - - // invitation statuses - private static final String INVITATION_STATUS_PENDING = "pending"; - private static final String INVITATION_STATUS_ACCEPTED = "accepted"; - private static final String INVITATION_STATUS_REJECTED = "rejected"; // service instances private WorkflowService workflowService; - private NamespaceService namespaceService; - private PersonService personService; private ServiceRegistry serviceRegistry; + private SiteService siteService; /** * Set the workflow service property @@ -99,25 +89,14 @@ public class Invites extends DeclarativeWebScript this.workflowService = workflowService; } - /** - * Set the namespace service - * - * @param namespaceService the namespace service to set - */ - public void setNamespaceService( - NamespaceService namespaceService) - { - this.namespaceService = namespaceService; - } - - public void setPersonService(PersonService personService) { - this.personService = personService; - } - public void setServiceRegistry(ServiceRegistry serviceRegistry) { this.serviceRegistry = serviceRegistry; } + public void setSiteService(SiteService siteService) { + this.siteService = siteService; + } + /* * (non-Javadoc) * @@ -204,17 +183,17 @@ public class Invites extends DeclarativeWebScript 1.0f); if (inviterUserName != null) { - wfQueryProps.put(QName.createQName(Invite.WF_PROP_INVITER_USER_NAME, this.namespaceService), + wfQueryProps.put(InviteWorkflowModel.WF_PROP_INVITER_USER_NAME, inviterUserName); } if (inviteeUserName != null) { - wfQueryProps.put(QName.createQName(Invite.WF_PROP_INVITEE_USER_NAME, this.namespaceService), + wfQueryProps.put(InviteWorkflowModel.WF_PROP_INVITEE_USER_NAME, inviteeUserName); } if (siteShortName != null) { - wfQueryProps.put(QName.createQName(Invite.WF_PROP_SITE_SHORT_NAME, this.namespaceService), + wfQueryProps.put(InviteWorkflowModel.WF_PROP_SITE_SHORT_NAME, siteShortName); } @@ -227,12 +206,12 @@ public class Invites extends DeclarativeWebScript // pick up the start task wfTaskQuery.setTaskState(WorkflowTaskState.COMPLETED); - wfTaskQuery.setTaskName(QName.createQName(Invite.WF_INVITE_TASK_INVITE_TO_SITE, this.namespaceService)); + wfTaskQuery.setTaskName(InviteWorkflowModel.WF_INVITE_TASK_INVITE_TO_SITE); // set process name to "wf:invite" so that only tasks associated with // invite workflow instances // are returned by query - wfTaskQuery.setProcessName(QName.createQName("wf:invite", this.namespaceService)); + wfTaskQuery.setProcessName(InviteWorkflowModel.WF_PROCESS_INVITE); // query for invite workflow tasks List wf_invite_tasks = this.workflowService @@ -247,48 +226,7 @@ public class Invites extends DeclarativeWebScript // onto model for each invite workflow task returned by the query for (WorkflowTask workflowTask : wf_invite_tasks) { - // get wf:inviterUserName, wf:inviteeUserName, wf:siteShortName - // properties from workflow path associated with workflow task - String inviterUserNameProp = (String) workflowTask.properties.get( - QName.createQName(Invite.WF_PROP_INVITER_USER_NAME, this.namespaceService)); - String inviteeUserNameProp = (String) workflowTask.properties.get( - QName.createQName(Invite.WF_PROP_INVITEE_USER_NAME, this.namespaceService)); - String siteShortNameProp = (String) workflowTask.properties.get( - QName.createQName(Invite.WF_PROP_SITE_SHORT_NAME, this.namespaceService)); - - // get workflow instance id (associated with workflow task) to place - // as "inviteId" onto model - String workflowId = workflowTask.path.instance.id; - - // set the invite start date to the time the workflow instance - // (associated with the task) was started - Date sentInviteDate = workflowTask.path.instance.startDate; - - // get role that invitee was invited to the site as - String role = InviteHelper.getInviteeSiteRoleFromInvite(inviteId, workflowService, namespaceService); - - // TODO: glen johnson at alfresco com - as this web script only returns - // pending invites, this is hard coded to "pending" for now - String invitationStatus = INVITATION_STATUS_PENDING; - - // check whether we can find a person node for inviter/invitee - NodeRef inviterRef = personService.getPerson(inviterUserNameProp); - ScriptNode inviterPerson = null; - if (inviterRef != null) - { - inviterPerson = new ScriptNode(inviterRef, serviceRegistry); - } - - NodeRef inviteeRef = personService.getPerson(inviteeUserNameProp); - ScriptNode inviteePerson = null; - if (inviteeRef != null) - { - inviteePerson = new ScriptNode(inviteeRef, serviceRegistry); - } - - // create and add InviteInfo to inviteInfoList - InviteInfo inviteInfo = new InviteInfo(invitationStatus, inviterUserNameProp, inviterPerson, - inviteeUserNameProp, inviteePerson, role, siteShortNameProp, sentInviteDate, workflowId); + InviteInfo inviteInfo = InviteHelper.getPendingInviteInfo(workflowTask, serviceRegistry, siteService); inviteInfoList.add(inviteInfo); } @@ -298,4 +236,5 @@ public class Invites extends DeclarativeWebScript return model; } + }