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 index a55ddf8227..f92be56663 100644 --- 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 @@ -2,6 +2,7 @@ Invite by ticket Returns invite information for a given inviteId and inviteTicket. No authentication is required /api/invite/{inviteId}/{inviteTicket} + /api/invite/{inviteId}/{inviteTicket}?inviteeUserName={inviteeUserName?} none required diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/membership.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/membership.get.desc.xml index bbc1ac129d..d1b66e1d05 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/membership.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/membership/membership.get.desc.xml @@ -1,8 +1,8 @@ - - Membership - Get the membership details for a user - /api/sites/{shortname}/memberships/{username} - - user - required + + Membership + Get the membership details for a user + /api/sites/{shortname}/memberships/{username} + argument + user + required \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/store/remoteavm.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/store/remoteavm.get.desc.xml index b204c63daf..0ff8314839 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/store/remoteavm.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/store/remoteavm.get.desc.xml @@ -7,7 +7,7 @@ /remotestore/{method}/s/{store}/{path} /remotestore/{method}/s/{store}/w/{webapp} /remotestore/{method}/s/{store}/w/{webapp}/{path} - none + guest required argument \ No newline at end of file diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index e87ecc5fb0..1cc9f24ccf 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -371,6 +371,7 @@ class="org.alfresco.repo.web.scripts.invite.InviteResponse" parent="webscript"> + 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 956fd984b8..7f0dcbbe9b 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java @@ -1,176 +1,223 @@ -/* - * 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.invitation.WorkflowModelNominatedInvitation; -import org.alfresco.repo.invitation.site.InviteHelper; -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 invoked by Invitee to either accept (response='accept') an - * invitation from a Site Manager (Inviter) to join a Site as a Site - * Collaborator, or to reject (response='reject') an invitation that has already - * been sent out - * - * @author glen dot johnson at alfresco dot com - */ -public class InviteResponse extends DeclarativeWebScript -{ - private static final String RESPONSE_ACCEPT = "accept"; - private static final String RESPONSE_REJECT = "reject"; - private static final String MODEL_PROP_KEY_RESPONSE = "response"; - private static final String MODEL_PROP_KEY_SITE_SHORT_NAME = "siteShortName"; - - // properties for services - private WorkflowService workflowService; - - /** - * Sets the workflow service property - * - * @param workflowService - * the workflow service instance assign to the property - */ - public void setWorkflowService(WorkflowService workflowService) - { - this.workflowService = workflowService; - } - - /* - * (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(); - - 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/cancelled already - WorkflowTask inviteStartTask = InviteHelper.findInviteStartTask(inviteId, workflowService); - if (inviteStartTask == null) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, - "No invite workflow for given id found"); - } - - // check the ticket for a match - String ticket = (String) inviteStartTask.properties.get(WorkflowModelNominatedInvitation.WF_PROP_INVITE_TICKET); - if (ticket == null || (! ticket.equals(inviteTicket))) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, - "Response to invite has supplied an invalid ticket. The response to the " - + "invitation could thus not be processed"); - } - - // process response - String action = req.getServiceMatch().getTemplateVars().get("action"); - if (action.equals("accept")) - { - acceptInvite(model, inviteId, inviteStartTask); - } - else if (action.equals("reject")) - { - rejectInvite(model, inviteId, inviteStartTask); - } - else - { - /* handle unrecognised method */ - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "action " + action + " is not supported by this webscript."); - } - - return model; - } - - /** - * Processes 'accept invite' response from invitee - * - * @param model - * model to add objects to, which will be passed to the template - * for rendering - * @param inviteId - * ID of invite - * @param inviteStartTask - * wf:inviteToSiteTask instance containing the invite parameters the - * invite workflow instance (it belongs to) was started with - */ - private void acceptInvite(Map model, String inviteId, WorkflowTask inviteStartTask) - { - String siteShortName = (String) inviteStartTask.properties.get( - WorkflowModelNominatedInvitation.WF_PROP_RESOURCE_NAME); - - // complete the wf:invitePendingTask along the 'accept' transition because the invitation has been accepted - InviteHelper.completeInviteTask(inviteId, WorkflowModelNominatedInvitation.WF_INVITE_TASK_INVITE_PENDING, - WorkflowModelNominatedInvitation.WF_TRANSITION_ACCEPT, this.workflowService); - - // add model properties for template to render - model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_ACCEPT); - model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, siteShortName); - } - - /** - * Processes 'reject' invite response from invitee - * - * @param model - * model to add objects to, which will be passed to the template - * for rendering - * @param inviteId - * ID of invite - * @param inviteeUserName - * user name of invitee - * @param siteShortName - * short name of site for which invitee is rejecting - * invitation to join - */ - private void rejectInvite(Map model, String inviteId, WorkflowTask inviteStartTask) - { - String siteShortName = (String) inviteStartTask.properties.get( - WorkflowModelNominatedInvitation.WF_PROP_RESOURCE_NAME); - - // complete the wf:invitePendingTask task along the 'reject' transition because the invitation has been rejected - InviteHelper.completeInviteTask(inviteId, WorkflowModelNominatedInvitation.WF_INVITE_TASK_INVITE_PENDING, - WorkflowModelNominatedInvitation.WF_TRANSITION_REJECT, this.workflowService); - - // add model properties for template to render - model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_REJECT); - model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, siteShortName); - } -} +/* + * Copyright (C) 2005-2009 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.invitation.WorkflowModelNominatedInvitation; +import org.alfresco.repo.invitation.site.InviteHelper; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.tenant.TenantService; +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 invoked by Invitee to either accept (response='accept') an + * invitation from a Site Manager (Inviter) to join a Site as a Site + * Collaborator, or to reject (response='reject') an invitation that has already + * been sent out + * + * @author glen dot johnson at alfresco dot com + */ +public class InviteResponse extends DeclarativeWebScript +{ + private static final String RESPONSE_ACCEPT = "accept"; + private static final String RESPONSE_REJECT = "reject"; + private static final String MODEL_PROP_KEY_RESPONSE = "response"; + private static final String MODEL_PROP_KEY_SITE_SHORT_NAME = "siteShortName"; + + // request parameter names + private static final String PARAM_INVITEE_USER_NAME = "inviteeUserName"; + + // properties for services + private WorkflowService workflowService; + + private TenantService tenantService; + + /** + * Sets the workflow service property + * + * @param workflowService + * the workflow service instance assign to the property + */ + public void setWorkflowService(WorkflowService workflowService) + { + this.workflowService = workflowService; + } + + /** + * Sets the tenant service property + * + * @param tenantService + * the tenant service instance assign to the property + */ + public void setTenantService(TenantService tenantService) + { + this.tenantService = tenantService; + } + + /* + * (non-Javadoc) + * + * @see + * org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco + * .web.scripts.WebScriptRequest, + * org.alfresco.web.scripts.WebScriptResponse) + */ + @Override + protected Map executeImpl(final WebScriptRequest req, final Status status) + { + if (tenantService.isEnabled()) + { + final String tenantDomain; + + String inviteeUserName = req.getParameter(PARAM_INVITEE_USER_NAME); + if (inviteeUserName != null) + { + tenantDomain = tenantService.getUserDomain(inviteeUserName); + } + else + { + tenantDomain = ""; + } + + return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork>() + { + public Map doWork() throws Exception + { + return execute(req, status); + } + }, tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain)); + } + else + { + return execute(req, status); + } + } + + private Map execute(WebScriptRequest req, Status status) + { + // initialise model to pass on for template to render + Map model = new HashMap(); + + 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/cancelled already + WorkflowTask inviteStartTask = InviteHelper.findInviteStartTask(inviteId, workflowService); + if (inviteStartTask == null) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "No invite workflow for given id found"); + } + + // check the ticket for a match + String ticket = (String) inviteStartTask.properties.get(WorkflowModelNominatedInvitation.WF_PROP_INVITE_TICKET); + if (ticket == null || (! ticket.equals(inviteTicket))) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "Response to invite has supplied an invalid ticket. The response to the " + + "invitation could thus not be processed"); + } + + // process response + String action = req.getServiceMatch().getTemplateVars().get("action"); + if (action.equals("accept")) + { + acceptInvite(model, inviteId, inviteStartTask); + } + else if (action.equals("reject")) + { + rejectInvite(model, inviteId, inviteStartTask); + } + else + { + /* handle unrecognised method */ + throw new WebScriptException(Status.STATUS_BAD_REQUEST, + "action " + action + " is not supported by this webscript."); + } + + return model; + } + + /** + * Processes 'accept invite' response from invitee + * + * @param model + * model to add objects to, which will be passed to the template + * for rendering + * @param inviteId + * ID of invite + * @param inviteStartTask + * wf:inviteToSiteTask instance containing the invite parameters the + * invite workflow instance (it belongs to) was started with + */ + private void acceptInvite(Map model, String inviteId, WorkflowTask inviteStartTask) + { + String siteShortName = (String) inviteStartTask.properties.get( + WorkflowModelNominatedInvitation.WF_PROP_RESOURCE_NAME); + + // complete the wf:invitePendingTask along the 'accept' transition because the invitation has been accepted + InviteHelper.completeInviteTask(inviteId, WorkflowModelNominatedInvitation.WF_INVITE_TASK_INVITE_PENDING, + WorkflowModelNominatedInvitation.WF_TRANSITION_ACCEPT, this.workflowService); + + // add model properties for template to render + model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_ACCEPT); + model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, siteShortName); + } + + /** + * Processes 'reject' invite response from invitee + * + * @param model + * model to add objects to, which will be passed to the template + * for rendering + * @param inviteId + * ID of invite + * @param inviteeUserName + * user name of invitee + * @param siteShortName + * short name of site for which invitee is rejecting + * invitation to join + */ + private void rejectInvite(Map model, String inviteId, WorkflowTask inviteStartTask) + { + String siteShortName = (String) inviteStartTask.properties.get( + WorkflowModelNominatedInvitation.WF_PROP_RESOURCE_NAME); + + // complete the wf:invitePendingTask task along the 'reject' transition because the invitation has been rejected + InviteHelper.completeInviteTask(inviteId, WorkflowModelNominatedInvitation.WF_INVITE_TASK_INVITE_PENDING, + WorkflowModelNominatedInvitation.WF_TRANSITION_REJECT, this.workflowService); + + // add model properties for template to render + model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_REJECT); + model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, siteShortName); + } +}