mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Invitation service
Java Script API for invitations on Site object. Implementation of REST API for Site / Invitations. Rename of old invite workflow to invitation-nominated and renaming of properties for consistency. Old workflow is due for deprecation. Rework to Nominated workflow to unscramble user creation. Start Workflow UI bean now knows to avoid workflows managed by the InvitationService. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13523 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<#-- renders an invitation object which can be either a MODERATED or NOMINATED invitation-->
|
||||
<#macro invitationJSON invitation>
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"inviteId": "${invitation.inviteId}",
|
||||
"inviteeUserName": "${invitation.inviteeUserName}",
|
||||
<#if invitation.roleName??>"roleName": "${invitation.roleName}",</#if>
|
||||
<#-- Moderated invitation properties -->
|
||||
<#if invitation.inviteeComments??>"inviteeComments": "${invitation.inviteeComments}",</#if>
|
||||
<#-- Nominated invitation properties -->
|
||||
<#if invitation.acceptURL??>"acceptURL": "${invitation.acceptURL}",</#if>
|
||||
<#if invitation.acceptURL??>"rejectURL": "${invitation.rejectURL}",</#if>
|
||||
<#if invitation.sentInviteDateAsISO8601??>"sentInviteDate" : { "iso8601" : "${invitation.sentInviteDateAsISO8601}" }, </#if>
|
||||
<#if invitation.inviteeFirstName??>"inviteeFirstName": "${invitation.inviteeFirstName}",</#if>
|
||||
<#if invitation.inviteeLastName??>"inviteeLastName": "${invitation.inviteeLastName}",</#if>
|
||||
<#if invitation.inviteeEmail??>"inviteeEmail": "${invitation.inviteeEmail}",</#if>
|
||||
<#-- put a mandatory property at the end to deal cleanly with training commas -->
|
||||
"resourceType": "${invitation.resourceType}",
|
||||
"resourceName": "${invitation.resourceName}",
|
||||
"invitationType": "${invitation.invitationType}"
|
||||
}
|
||||
</#escape>
|
||||
</#macro>
|
@@ -0,0 +1,20 @@
|
||||
<webscript>
|
||||
<shortname>Cancel invitation</shortname>
|
||||
<description><![CDATA[
|
||||
Cancel an open invitation.
|
||||
<BR>
|
||||
Canceling an invitation immediatly stops the invitation, it is different to rejecting an
|
||||
invitation which will result in the invitation workflow continuing to a normal but rejected conclusion.
|
||||
In particular the approver or invitee are not notified if an invitation is canceled.
|
||||
<BR>
|
||||
Only a site manager may cancel an invitation.
|
||||
<BR>
|
||||
Returns 200, STATUS_OK on success.
|
||||
]]>
|
||||
</description>
|
||||
<url>/api/sites/{shortname}/invitations/{invitationId}</url>
|
||||
<format default="json"/>
|
||||
<lifecycle>draft_public_api</lifecycle>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,33 @@
|
||||
// Cancel invitation for a web site
|
||||
|
||||
function main()
|
||||
{
|
||||
// Get the url values
|
||||
var urlElements = url.extension.split("/");
|
||||
var shortName = urlElements[0];
|
||||
var inviteId = urlElements[2];
|
||||
|
||||
// Get the site
|
||||
var site = siteService.getSite(shortName);
|
||||
if (site == null)
|
||||
{
|
||||
// Site cannot be found
|
||||
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Need to cancel an invitation here
|
||||
var invitation = site.getInvitation(inviteId);
|
||||
if (invitation == null)
|
||||
{
|
||||
// Site cannot be found
|
||||
status.setCode(status.STATUS_NOT_FOUND, "The invitation :" + inviteId + " for web site :" + shortName + ", does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Cancel the invitation
|
||||
invitation.cancel();
|
||||
}
|
||||
|
||||
main();
|
@@ -0,0 +1 @@
|
||||
{}
|
@@ -0,0 +1,12 @@
|
||||
<webscript>
|
||||
<shortname>Get Invitation</shortname>
|
||||
<description><![CDATA[
|
||||
Get a single web site invitation.
|
||||
]]>
|
||||
</description>
|
||||
<url>/api/sites/{shortname}/invitations/{inviteId}</url>
|
||||
<format default="json"/>
|
||||
<lifecycle>draft_public_api</lifecycle>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Get Invitation web script
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
|
||||
// Get the site id
|
||||
var urlElements = url.extension.split("/");
|
||||
var shortName = urlElements[0];
|
||||
var inviteId = urlElements[2];
|
||||
|
||||
var site = siteService.getSite(shortName);
|
||||
if (site == null)
|
||||
{
|
||||
// Site cannot be found
|
||||
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
var invitation = site.getInvitation(inviteId);
|
||||
if (invitation == null)
|
||||
{
|
||||
// Site cannot be found
|
||||
status.setCode(status.STATUS_NOT_FOUND, "The invitation :" + inviteId + " for web site :" + shortName + ", does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Pass the model to the template
|
||||
model.invitation = invitation;
|
||||
model.site = site;
|
||||
}
|
||||
|
||||
main();
|
||||
|
@@ -0,0 +1,5 @@
|
||||
<#-- Get Invitation -->
|
||||
<#import "../../invitation/invitation.lib.ftl" as invitationLib/>
|
||||
{
|
||||
"data":<@invitationLib.invitationJSON invitation=invitation />
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
<webscript>
|
||||
<shortname>Create invitation for web site</shortname>
|
||||
<description><![CDATA[
|
||||
Create a new invitation for this web site.
|
||||
<BR />
|
||||
For a Nominated Invitation, where an existing site member nominates someone else who is possibly not yet an alfresco user to become a member of this web site.
|
||||
|
||||
<BR>
|
||||
For an existing user, the invitee is identified by inviteeUserName.
|
||||
For a user who does not have a userName a new account will be generated based upon
|
||||
inviteeFirstName, inviteeLastName and inviteeEmail
|
||||
<BR> if inviteeUserName is specified then inviteeFirstName, inviteeLastName and inviteeEmail are ignored.
|
||||
|
||||
<dl>
|
||||
<dt>invitationType</dt><dd>mandatory - "NOMINATED"</dd>
|
||||
<dt>inviteeFirstName</dt> <dd> optional, </dd>
|
||||
<dt>inviteeLastName</dt> <dd> optional, </dd>
|
||||
<dt>inviteeEmail</dt> <dd> optional, </dd>
|
||||
<dt>inviteeUserName</dt> <dd> optional </dd>
|
||||
<dt>serverPath</dt>
|
||||
<dt>acceptURL</dt>
|
||||
<dt>rejectURL</dt>
|
||||
<dt>inviteeRoleName</dt> <dd> mandatory what role to be given on this web site </dd>
|
||||
</dl>
|
||||
|
||||
<BR />
|
||||
For a Moderated Invitation, where an existing user wants to be made a member of a moderated web site.
|
||||
<dl>
|
||||
<dt>invitationType</dt><dd>mandatory - "MODERATED"</dd>
|
||||
<dt>inviteeUserName</dt><dd>optional who wants to be invited to this web site? </dd>
|
||||
<dt>inviteeComments</dt> <dd>mandatory (but can be blank) why do they want membership to this site ? </dd>
|
||||
<dt>inviteeRoleName</dt> <dd>mandatory what role to be given on this web site </dd>
|
||||
</dl>
|
||||
<BR />
|
||||
|
||||
Returns HTTPStatus.Created (201) if an invitation is created.
|
||||
|
||||
]]></description>
|
||||
<url>/api/sites/{shortname}/invitations</url>
|
||||
<format default="json"/>
|
||||
<lifecycle>draft_public_api</lifecycle>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,5 @@
|
||||
<#-- Create / Post / Invitation -->
|
||||
<#import "../../invitation/invitation.lib.ftl" as invitationLib/>
|
||||
{
|
||||
"data":<@invitationLib.invitationJSON invitation=invitation />
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* Create / Post / Invitation
|
||||
*/
|
||||
function main()
|
||||
{
|
||||
|
||||
var invitation = null;
|
||||
|
||||
// Get the web site site
|
||||
var shortName = url.extension.split("/")[0];
|
||||
var site = siteService.getSite(shortName);
|
||||
if (site == null)
|
||||
{
|
||||
// Site cannot be found
|
||||
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!json.has("invitationType"))
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The invitationType has not been set.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the role
|
||||
var invitationType = json.get("invitationType");
|
||||
if (invitationType == null || invitationType.length == 0)
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The invitationType is null or empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!invitationType.match("[MODERATED]|[NOMINATED]"))
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The invitationType has does not have a correct value.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(invitationType == "MODERATED")
|
||||
{
|
||||
// Check mandatory parameters
|
||||
if(!json.has("inviteeRoleName"))
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName has not been set.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!json.has("inviteeUserName"))
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeUserName has not been set.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the role
|
||||
var inviteeRoleName = json.get("inviteeRoleName");
|
||||
if (inviteeRoleName == null || inviteeRoleName == "")
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName has not been set.");
|
||||
return;
|
||||
}
|
||||
|
||||
var inviteeComments = json.get("inviteeComments");
|
||||
if (inviteeComments == null)
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeComments has not been set.");
|
||||
return;
|
||||
}
|
||||
|
||||
var inviteeUserName = json.get("inviteeUserName");
|
||||
if (inviteeUserName == null || inviteeUserName == "")
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The userName has not been set.");
|
||||
return;
|
||||
}
|
||||
|
||||
invitation = site.inviteModerated(inviteeComments, inviteeUserName, inviteeRoleName);
|
||||
}
|
||||
|
||||
if(invitationType == "NOMINATED")
|
||||
{
|
||||
|
||||
// Get Mandatory properties
|
||||
if(!json.has("inviteeRoleName"))
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName has not been set.");
|
||||
return;
|
||||
}
|
||||
var inviteeRoleName = json.get("inviteeRoleName");
|
||||
if (inviteeRoleName == null || inviteeRoleName == "" )
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName is null or empty.");
|
||||
return;
|
||||
}
|
||||
var serverPath = json.get("serverPath");
|
||||
var acceptUrl = json.get("acceptURL");
|
||||
var rejectUrl = json.get("rejectURL");
|
||||
|
||||
/**
|
||||
* Get the optional properties
|
||||
*/
|
||||
if(json.has("inviteeUserName"))
|
||||
{
|
||||
var inviteeUserName = json.get("inviteeUserName");
|
||||
invitation = site.inviteNominated(inviteeUserName, inviteeRoleName, serverPath, acceptUrl, rejectUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get Mandatory properties
|
||||
if(!json.has("inviteeFirstName"))
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeFirstName has not been set.");
|
||||
return;
|
||||
}
|
||||
if(!json.has("inviteeLastName"))
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeLastName has not been set.");
|
||||
return;
|
||||
}
|
||||
if(!json.has("inviteeEmail"))
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeEmail has not been set.");
|
||||
return;
|
||||
}
|
||||
|
||||
var inviteeFirstName = json.get("inviteeFirstName") ;
|
||||
var inviteeLastName = json.get("inviteeLastName") ;
|
||||
var inviteeEmail = json.get("inviteeEmail") ;
|
||||
invitation = site.inviteNominated(inviteeFirstName, inviteeLastName, inviteeEmail, inviteeRoleName, serverPath, acceptUrl, rejectUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// Pass the model to the results template
|
||||
model.site = site;
|
||||
model.invitation = invitation;
|
||||
|
||||
status.code = status.STATUS_CREATED;
|
||||
}
|
||||
|
||||
main();
|
@@ -0,0 +1,22 @@
|
||||
<webscript>
|
||||
<shortname>List Invitations</shortname>
|
||||
<description><![CDATA[
|
||||
Get a collecton of a site web invitations.
|
||||
<BR />
|
||||
With no parameters, returns all open invitations for this web site.
|
||||
<BR />
|
||||
With inviteeUserName, returns all open invitations for this web site and invitee.
|
||||
<BR />
|
||||
With invitationType, returns all open invitations of the specified type (Either NOMINATED or MODERATED).
|
||||
|
||||
<BR />
|
||||
|
||||
<BR />
|
||||
]]>
|
||||
</description>
|
||||
<url>/api/sites/{shortname}/invitations?inviteeUserName={inviteeUserName?}&invitationType={invitationType?}</url>
|
||||
<format default="json"/>
|
||||
<lifecycle>draft_public_api</lifecycle>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* List invitations implementation
|
||||
*/
|
||||
|
||||
function main ()
|
||||
{
|
||||
// Get the site id
|
||||
var urlElements = url.extension.split("/");
|
||||
var shortName = urlElements[0];
|
||||
|
||||
// Get the args
|
||||
var inviteeUserName = args["inviteeUserName"];
|
||||
var invitationType = args["invitationType"];
|
||||
|
||||
var site = siteService.getSite(shortName);
|
||||
if (site == null)
|
||||
{
|
||||
// Site cannot be found
|
||||
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
var props = {};
|
||||
|
||||
if(inviteeUserName != null)
|
||||
{
|
||||
props.inviteeUserName = inviteeUserName
|
||||
}
|
||||
if(invitationType != null)
|
||||
{
|
||||
props.invitationType = invitationType
|
||||
}
|
||||
|
||||
var invitations = site.listInvitations(props);
|
||||
|
||||
// Pass the information to the template
|
||||
model.invitations = invitations;
|
||||
}
|
||||
|
||||
main();
|
@@ -0,0 +1,9 @@
|
||||
<#-- list / search / invitations -->
|
||||
|
||||
<#import "../../invitation/invitation.lib.ftl" as invitationLib/>
|
||||
"data": [
|
||||
<#list invitations as invitation>
|
||||
<@invitationLib.invitationJSON invitation=invitation />
|
||||
<#if invitation_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
@@ -625,7 +625,7 @@ public class Invite extends DeclarativeWebScript
|
||||
workflowProps.put(WorkflowModelNominatedInvitation.WF_PROP_INVITEE_GEN_PASSWORD, inviteePassword);
|
||||
workflowProps.put(WorkflowModelNominatedInvitation.WF_PROP_RESOURCE_TYPE, Invitation.ResourceType.WEB_SITE);
|
||||
workflowProps.put(WorkflowModelNominatedInvitation.WF_PROP_RESOURCE_NAME, siteShortName);
|
||||
workflowProps.put(WorkflowModelNominatedInvitation.WF_PROP_INVITEE_SITE_ROLE, inviteeSiteRole);
|
||||
workflowProps.put(WorkflowModelNominatedInvitation.WF_PROP_INVITEE_ROLE, inviteeSiteRole);
|
||||
workflowProps.put(WorkflowModelNominatedInvitation.WF_PROP_SERVER_PATH, serverPath);
|
||||
workflowProps.put(WorkflowModelNominatedInvitation.WF_PROP_ACCEPT_URL, acceptUrl);
|
||||
workflowProps.put(WorkflowModelNominatedInvitation.WF_PROP_REJECT_URL, rejectUrl);
|
||||
|
@@ -44,6 +44,7 @@ import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.alfresco.web.scripts.Status;
|
||||
import org.alfresco.web.scripts.TestWebScriptServer.DeleteRequest;
|
||||
import org.alfresco.web.scripts.TestWebScriptServer.GetRequest;
|
||||
import org.alfresco.web.scripts.TestWebScriptServer.PostRequest;
|
||||
@@ -54,7 +55,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Unit test to test site Web Script API
|
||||
* Unit test to test site Web Script API of the Site Object.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
@@ -195,12 +196,12 @@ public class SiteServiceTest extends BaseWebScriptTest
|
||||
public void testGetSite() throws Exception
|
||||
{
|
||||
// Get a site that doesn't exist
|
||||
Response response = sendRequest(new GetRequest(URL_SITES + "/" + "somerandomshortname"), 404);
|
||||
sendRequest(new GetRequest(URL_SITES + "/" + "somerandomshortname"), 404);
|
||||
|
||||
// Create a site and get it
|
||||
String shortName = GUID.generate();
|
||||
JSONObject result = createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||
response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
|
||||
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 200);
|
||||
|
||||
}
|
||||
|
||||
@@ -456,4 +457,305 @@ public class SiteServiceTest extends BaseWebScriptTest
|
||||
assertEquals("Additional Site Information", addInfo.get("title"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* End to end sanity check of web site invitation.
|
||||
*
|
||||
* Nominated and Moderated invitations.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testInvitationSanityCheck() throws Exception
|
||||
{
|
||||
String shortName = GUID.generate();
|
||||
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||
|
||||
String inviteComments = "Please sir, let me in";
|
||||
String userName = USER_TWO;
|
||||
String roleName = SiteModel.SITE_CONSUMER;
|
||||
|
||||
String inviteeFirstName = "Buffy";
|
||||
String inviteeLastName = "Summers";
|
||||
String inviteeEmail = "buffy@sunnydale";
|
||||
String inviteeUserName = userName;
|
||||
String serverPath = "http://localhost:8081/share/";
|
||||
String acceptURL = "page/accept-invite";
|
||||
String rejectURL = "page/reject-invite";
|
||||
|
||||
// Create a nominated invitation
|
||||
String nominatedId = createNominatedInvitation(shortName, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL);
|
||||
|
||||
// Get the nominated invitation
|
||||
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/" + nominatedId), 200);
|
||||
|
||||
//Create a new moderated invitation
|
||||
String moderatedId = createModeratedInvitation(shortName, inviteComments, userName, roleName);
|
||||
|
||||
// Get the moderated invitation
|
||||
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/" + moderatedId), 200);
|
||||
|
||||
// search for the moderated invitation
|
||||
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations?inviteeUserName=" + userName), 200);
|
||||
|
||||
// Search for all invitations on this site
|
||||
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations"), 200);
|
||||
|
||||
// cancel the nominated invitation
|
||||
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + "/invitations/" + nominatedId), 200);
|
||||
|
||||
// cancel the moderated invitation
|
||||
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + "/invitations/" + moderatedId), 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed Test of Get Invitation Web Script
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testGetInvitation() throws Exception
|
||||
{
|
||||
String shortName = GUID.generate();
|
||||
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||
|
||||
/*
|
||||
* Create a new moderated invitation
|
||||
*/
|
||||
String inviteeComments = "Please sir, let $* me in";
|
||||
String userName = USER_TWO;
|
||||
String roleName = SiteModel.SITE_CONSUMER;
|
||||
String inviteId = createModeratedInvitation(shortName, inviteeComments, userName, roleName);
|
||||
|
||||
/*
|
||||
* Negative test - site does not exist
|
||||
*/
|
||||
sendRequest(new GetRequest(URL_SITES + "/rubbish/invitations/" + inviteId), 404);
|
||||
|
||||
/*
|
||||
* Negative test - site does exist but invitation doesn't
|
||||
*/
|
||||
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/jbpm$8787487"), 404);
|
||||
|
||||
/*
|
||||
* Negative test - site does exist but invitation engine is wrong
|
||||
*/
|
||||
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/trash$123"), 404);
|
||||
|
||||
/*
|
||||
* Negative test - site does exist but invitation doesn't no $ in inviteId
|
||||
*/
|
||||
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/trash123"), 404);
|
||||
|
||||
/*
|
||||
* Positive test - get the invitation and validate that it is correct
|
||||
*/
|
||||
{
|
||||
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 200);
|
||||
JSONObject top = new JSONObject(response.getContentAsString());
|
||||
//System.out.println(response.getContentAsString());
|
||||
JSONObject data = top.getJSONObject("data");
|
||||
assertNotNull("data is null", data);
|
||||
assertEquals("inviteId is not set", data.getString("inviteId"), inviteId);
|
||||
assertEquals("invitationType", "MODERATED", data.getString("invitationType"));
|
||||
assertEquals("inviteeUserName is not set", userName, data.getString("inviteeUserName"));
|
||||
assertEquals("resourceName is not correct", shortName, data.getString("resourceName"));
|
||||
assertEquals("resourceType is not correct", "WEB_SITE", data.getString("resourceType"));
|
||||
// Moderated specific properties
|
||||
assertEquals("inviteeComments", inviteeComments, data.getString("inviteeComments"));
|
||||
assertEquals("roleName is not set", roleName, data.getString("roleName"));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Cancel the invitation
|
||||
*/
|
||||
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 200);
|
||||
|
||||
/*
|
||||
* Verify that the invitation is no longer open
|
||||
*/
|
||||
sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 404);
|
||||
|
||||
/**
|
||||
* Create a nominated invitation
|
||||
*/
|
||||
String inviteeFirstName = "Buffy";
|
||||
String inviteeLastName = "Summers";
|
||||
String inviteeEmail = "FirstName123.LastName123@email.com";
|
||||
String inviteeUserName = null;
|
||||
String serverPath = "http://localhost:8081/share/";
|
||||
String acceptURL = "page/accept-invite";
|
||||
String rejectURL = "page/reject-invite";
|
||||
inviteId = createNominatedInvitation(shortName, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL);
|
||||
|
||||
/*
|
||||
* Positive test - get the invitation and validate that it is correct
|
||||
* inviteId and inviteeUserName will be generated.
|
||||
*/
|
||||
{
|
||||
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 200);
|
||||
JSONObject top = new JSONObject(response.getContentAsString());
|
||||
//System.out.println(response.getContentAsString());
|
||||
JSONObject data = top.getJSONObject("data");
|
||||
assertNotNull("data is null", data);
|
||||
assertEquals("inviteId is not set", data.getString("inviteId"), inviteId);
|
||||
assertEquals("invitationType", "NOMINATED", data.getString("invitationType"));
|
||||
assertEquals("resourceName is not correct", shortName, data.getString("resourceName"));
|
||||
assertEquals("resourceType is not correct", "WEB_SITE", data.getString("resourceType"));
|
||||
|
||||
// Nominated specific attributes
|
||||
assertEquals("roleName is not set", roleName, data.getString("roleName"));
|
||||
// Generated user name
|
||||
assertNotNull("inviteeUserName is not set", data.getString("inviteeUserName"));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Cancel the nominated invitation
|
||||
*/
|
||||
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName + "/invitations/" + inviteId), 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed Test of List Invitation Web Script.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testListInvitation() throws Exception
|
||||
{
|
||||
String shortName = GUID.generate();
|
||||
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed test of Create Invitation Web Script
|
||||
*
|
||||
* Create Nominated Invitation
|
||||
*
|
||||
* Create Moderated Invitation
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testCreateInvitation() throws Exception
|
||||
{
|
||||
String shortName = GUID.generate();
|
||||
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||
|
||||
|
||||
String inviteComments = "Please sir, let me in";
|
||||
String userName = USER_TWO;
|
||||
String roleName = SiteModel.SITE_CONSUMER;
|
||||
String inviteId = null;
|
||||
|
||||
/*
|
||||
* Negative test - wrong invitation type
|
||||
*/
|
||||
{
|
||||
JSONObject newInvitation = new JSONObject();
|
||||
newInvitation.put("invitationType", "Grundge");
|
||||
newInvitation.put("inviteeRoleName", roleName);
|
||||
newInvitation.put("inviteeComments", inviteComments);
|
||||
newInvitation.put("inviteeUserName", userName);
|
||||
sendRequest(new PostRequest(URL_SITES + "/" + shortName + "/invitations", newInvitation.toString(), "application/json"), Status.STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
/*
|
||||
* Negative test - missing Invitation type
|
||||
*/
|
||||
{
|
||||
JSONObject newInvitation = new JSONObject();
|
||||
newInvitation.put("inviteeRoleName", roleName);
|
||||
newInvitation.put("inviteeComments", inviteComments);
|
||||
newInvitation.put("inviteeUserName", userName);
|
||||
sendRequest(new PostRequest(URL_SITES + "/" + shortName + "/invitations", newInvitation.toString(), "application/json"), Status.STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
/*
|
||||
* Negative test - blank RoleName
|
||||
*/
|
||||
{
|
||||
JSONObject newInvitation = new JSONObject();
|
||||
newInvitation.put("invitationType", "MODERATED");
|
||||
newInvitation.put("inviteeRoleName", "");
|
||||
newInvitation.put("inviteeComments", inviteComments);
|
||||
newInvitation.put("inviteeUserName", userName);
|
||||
sendRequest(new PostRequest(URL_SITES + "/" + shortName + "/invitations", newInvitation.toString(), "application/json"), Status.STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new moderated invitation
|
||||
*/
|
||||
JSONObject newInvitation = new JSONObject();
|
||||
{
|
||||
newInvitation.put("invitationType", "MODERATED");
|
||||
newInvitation.put("inviteeRoleName", roleName);
|
||||
newInvitation.put("inviteeComments", inviteComments);
|
||||
newInvitation.put("inviteeUserName", userName);
|
||||
Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + "/invitations", newInvitation.toString(), "application/json"), Status.STATUS_CREATED);
|
||||
JSONObject top = new JSONObject(response.getContentAsString());
|
||||
JSONObject data = top.getJSONObject("data");
|
||||
inviteId = data.getString("inviteId");
|
||||
assertEquals("invitationType", "MODERATED", data.getString("invitationType"));
|
||||
assertEquals("inviteeUserName is not set", userName, data.getString("inviteeUserName"));
|
||||
assertEquals("resourceName is not correct", shortName, data.getString("resourceName"));
|
||||
assertEquals("resourceType is not correct", "WEB_SITE", data.getString("resourceType"));
|
||||
|
||||
}
|
||||
assertNotNull("inviteId is null", inviteId);
|
||||
assertTrue("inviteId is too small", inviteId.length() > 0);
|
||||
|
||||
}
|
||||
|
||||
private String createNominatedInvitation(String siteName, String inviteeFirstName, String inviteeLastName, String inviteeEmail, String inviteeUserName, String inviteeRoleName, String serverPath, String acceptURL, String rejectURL) throws Exception
|
||||
{
|
||||
/*
|
||||
* Create a new nominated invitation
|
||||
*/
|
||||
JSONObject newInvitation = new JSONObject();
|
||||
|
||||
newInvitation.put("invitationType", "NOMINATED");
|
||||
newInvitation.put("inviteeRoleName", inviteeRoleName);
|
||||
if(inviteeUserName != null)
|
||||
{
|
||||
// nominate an existing user
|
||||
newInvitation.put("inviteeUserName", inviteeUserName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// nominate someone else
|
||||
newInvitation.put("inviteeFirstName", inviteeFirstName);
|
||||
newInvitation.put("inviteeLastName", inviteeLastName);
|
||||
newInvitation.put("inviteeEmail", inviteeEmail);
|
||||
}
|
||||
newInvitation.put("serverPath", serverPath);
|
||||
newInvitation.put("acceptURL", acceptURL);
|
||||
newInvitation.put("rejectURL", rejectURL);
|
||||
|
||||
Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation.toString(), "application/json"), 201);
|
||||
JSONObject top = new JSONObject(response.getContentAsString());
|
||||
JSONObject data = top.getJSONObject("data");
|
||||
String inviteId = data.getString("inviteId");
|
||||
|
||||
return inviteId;
|
||||
}
|
||||
|
||||
private String createModeratedInvitation(String siteName, String inviteeComments, String inviteeUserName, String inviteeRoleName) throws Exception
|
||||
{
|
||||
/*
|
||||
* Create a new moderated invitation
|
||||
*/
|
||||
JSONObject newInvitation = new JSONObject();
|
||||
|
||||
newInvitation.put("invitationType", "MODERATED");
|
||||
newInvitation.put("inviteeRoleName", inviteeRoleName);
|
||||
newInvitation.put("inviteeComments", inviteeComments);
|
||||
newInvitation.put("inviteeUserName", inviteeUserName);
|
||||
Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation.toString(), "application/json"), 201);
|
||||
JSONObject top = new JSONObject(response.getContentAsString());
|
||||
JSONObject data = top.getJSONObject("data");
|
||||
String inviteId = data.getString("inviteId");
|
||||
|
||||
return inviteId;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user