Fix to Invite REST API where inviteeUserName arg was not correctly checked when inviting external users.

Also cleanup the related .js scripts to use spaces not tabs - significantly aids debugging in the script debugger.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13913 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2009-04-09 14:16:50 +00:00
parent 063f2df8b0
commit 043af1bbbd
5 changed files with 245 additions and 254 deletions

View File

@@ -1,42 +1,41 @@
/** /**
* List/Search invitations implementation * List/Search invitations implementation
*/ */
function main()
function main ()
{ {
// Get the site id // Get the site id
var urlElements = url.extension.split("/"); var urlElements = url.extension.split("/");
var shortName = urlElements[0]; var shortName = urlElements[0];
// Get the args // Get the args
var inviteeUserName = args["inviteeUserName"]; var inviteeUserName = args["inviteeUserName"];
var invitationType = args["invitationType"]; var invitationType = args["invitationType"];
var resourceType = args["resourceType"]; var resourceType = args["resourceType"];
var resourceName = args["resourceName"]; var resourceName = args["resourceName"];
var props = {}; var props = {};
if(inviteeUserName != null) if (inviteeUserName != null)
{ {
props.inviteeUserName = inviteeUserName props.inviteeUserName = inviteeUserName
} }
if(invitationType != null) if (invitationType != null)
{ {
props.invitationType = invitationType props.invitationType = invitationType
} }
if(resourceType != null) if (resourceType != null)
{ {
props.resourceType = resourceType props.resourceType = resourceType
} }
if(resourceName != null) if (resourceName != null)
{ {
props.resourceName = resourceName props.resourceName = resourceName
} }
var invites = invitations.listInvitations(props); var invites = invitations.listInvitations(props);
// Pass the information to the template // Pass the information to the template
model.invitations = invites; model.invitations = invites;
} }
main(); main();

View File

@@ -1,33 +1,33 @@
// Cancel invitation for a web site /**
* Cancel invitation for a web site
*/
function main() function main()
{ {
// Get the url values // Get the url values
var urlElements = url.extension.split("/"); var urlElements = url.extension.split("/");
var shortName = urlElements[0]; var shortName = urlElements[0];
var inviteId = urlElements[2]; var inviteId = urlElements[2];
// Get the site // Get the site
var site = siteService.getSite(shortName); var site = siteService.getSite(shortName);
if (site == null) if (site == null)
{ {
// Site cannot be found // Site cannot be found
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist."); status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
return; return;
} }
// Need to cancel an invitation here
// Need to cancel an invitation here var invitation = site.getInvitation(inviteId);
var invitation = site.getInvitation(inviteId); if (invitation == null)
if (invitation == null) {
{ // Site cannot be found
// Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The invitation :" + inviteId + " for web site :" + shortName + ", does not exist.");
status.setCode(status.STATUS_NOT_FOUND, "The invitation :" + inviteId + " for web site :" + shortName + ", does not exist."); return;
return; }
}
// Cancel the invitation
// Cancel the invitation invitation.cancel();
invitation.cancel();
} }
main(); main();

View File

@@ -3,32 +3,30 @@
*/ */
function main() function main()
{ {
// Get the site id
// Get the site id var urlElements = url.extension.split("/");
var urlElements = url.extension.split("/"); var shortName = urlElements[0];
var shortName = urlElements[0]; var inviteId = urlElements[2];
var inviteId = urlElements[2];
var site = siteService.getSite(shortName);
var site = siteService.getSite(shortName); if (site == null)
if (site == null) {
{ // Site cannot be found
// Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist."); return;
return; }
}
var invitation = site.getInvitation(inviteId);
var invitation = site.getInvitation(inviteId); if (invitation == null)
if (invitation == null) {
{ // Site cannot be found
// Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The invitation :" + inviteId + " for web site :" + shortName + ", does not exist.");
status.setCode(status.STATUS_NOT_FOUND, "The invitation :" + inviteId + " for web site :" + shortName + ", does not exist."); return;
return; }
}
// Pass the model to the template // Pass the model to the template
model.invitation = invitation; model.invitation = invitation;
model.site = site; model.site = site;
} }
main(); main();

View File

@@ -3,137 +3,132 @@
*/ */
function main() function main()
{ {
var invitation = null;
var invitation = null;
// Get the web site site
// Get the web site site var shortName = url.extension.split("/")[0];
var shortName = url.extension.split("/")[0]; var site = siteService.getSite(shortName);
var site = siteService.getSite(shortName); if (site == null)
if (site == null) {
{ // Site cannot be found
// Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist."); return;
return; }
}
if (!json.has("invitationType"))
if(!json.has("invitationType")) {
{ status.setCode(status.STATUS_BAD_REQUEST, "The invitationType has not been set.");
status.setCode(status.STATUS_BAD_REQUEST, "The invitationType has not been set."); return;
return; }
}
// Get the role
// Get the role var invitationType = json.get("invitationType");
var invitationType = json.get("invitationType"); if (invitationType == null || invitationType.length == 0)
if (invitationType == null || invitationType.length == 0) {
{ status.setCode(status.STATUS_BAD_REQUEST, "The invitationType is null or empty.");
status.setCode(status.STATUS_BAD_REQUEST, "The invitationType is null or empty."); return;
return; }
}
if (!invitationType.match("[MODERATED]|[NOMINATED]"))
if(!invitationType.match("[MODERATED]|[NOMINATED]")) {
{ status.setCode(status.STATUS_BAD_REQUEST, "The invitationType has does not have a correct value.");
status.setCode(status.STATUS_BAD_REQUEST, "The invitationType has does not have a correct value."); return;
return; }
}
if (invitationType == "MODERATED")
if(invitationType == "MODERATED") {
{ // Check mandatory parameters
// Check mandatory parameters if (!json.has("inviteeRoleName"))
if(!json.has("inviteeRoleName")) {
{ status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName has not been set.");
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName has not been set."); return;
return; }
}
if (!json.has("inviteeUserName"))
if(!json.has("inviteeUserName")) {
{ status.setCode(status.STATUS_BAD_REQUEST, "The inviteeUserName has not been set.");
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeUserName has not been set."); return;
return; }
}
// Get the role
// Get the role var inviteeRoleName = json.get("inviteeRoleName");
var inviteeRoleName = json.get("inviteeRoleName"); if (inviteeRoleName == null || inviteeRoleName == "")
if (inviteeRoleName == null || inviteeRoleName == "") {
{ status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName has not been set.");
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName has not been set."); return;
return; }
}
var inviteeComments = json.get("inviteeComments");
var inviteeComments = json.get("inviteeComments"); if (inviteeComments == null)
if (inviteeComments == null) {
{ status.setCode(status.STATUS_BAD_REQUEST, "The inviteeComments has not been set.");
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeComments has not been set."); return;
return; }
}
var inviteeUserName = json.get("inviteeUserName");
var inviteeUserName = json.get("inviteeUserName"); if (inviteeUserName == null || inviteeUserName == "")
if (inviteeUserName == null || inviteeUserName == "") {
{ status.setCode(status.STATUS_BAD_REQUEST, "The userName has not been set.");
status.setCode(status.STATUS_BAD_REQUEST, "The userName has not been set."); return;
return; }
}
invitation = site.inviteModerated(inviteeComments, inviteeUserName, inviteeRoleName);
invitation = site.inviteModerated(inviteeComments, inviteeUserName, inviteeRoleName); }
}
if (invitationType == "NOMINATED")
if(invitationType == "NOMINATED") {
{ // Get mandatory properties
if (!json.has("inviteeRoleName"))
// Get Mandatory properties {
if(!json.has("inviteeRoleName")) status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName has not been set.");
{ return;
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName has not been set."); }
return; var inviteeRoleName = json.get("inviteeRoleName");
} if (inviteeRoleName == null || inviteeRoleName == "")
var inviteeRoleName = json.get("inviteeRoleName"); {
if (inviteeRoleName == null || inviteeRoleName == "" ) status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName is null or empty.");
{ return;
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeRoleName is null or empty."); }
return; var serverPath = json.get("serverPath");
} var acceptUrl = json.get("acceptURL");
var serverPath = json.get("serverPath"); var rejectUrl = json.get("rejectURL");
var acceptUrl = json.get("acceptURL");
var rejectUrl = json.get("rejectURL"); // Get the optional properties
if (json.has("inviteeUserName") && json.get("inviteeUserName") != "")
/** {
* Get the optional properties invitation = site.inviteNominated(json.get("inviteeUserName"), inviteeRoleName, serverPath, acceptUrl, rejectUrl);
*/ }
if(json.has("inviteeUserName")) else
{ {
var inviteeUserName = json.get("inviteeUserName"); // Get mandatory properties
invitation = site.inviteNominated(inviteeUserName, inviteeRoleName, serverPath, acceptUrl, rejectUrl); if (!json.has("inviteeFirstName"))
} {
else status.setCode(status.STATUS_BAD_REQUEST, "The inviteeFirstName has not been set.");
{ return;
// Get Mandatory properties }
if(!json.has("inviteeFirstName")) if (!json.has("inviteeLastName"))
{ {
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeFirstName has not been set."); status.setCode(status.STATUS_BAD_REQUEST, "The inviteeLastName has not been set.");
return; return;
} }
if(!json.has("inviteeLastName")) if (!json.has("inviteeEmail"))
{ {
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeLastName has not been set."); status.setCode(status.STATUS_BAD_REQUEST, "The inviteeEmail has not been set.");
return; return;
} }
if(!json.has("inviteeEmail"))
{ var inviteeFirstName = json.get("inviteeFirstName") ;
status.setCode(status.STATUS_BAD_REQUEST, "The inviteeEmail has not been set."); var inviteeLastName = json.get("inviteeLastName") ;
return; var inviteeEmail = json.get("inviteeEmail") ;
} invitation = site.inviteNominated(inviteeFirstName, inviteeLastName, inviteeEmail, inviteeRoleName, serverPath, acceptUrl, rejectUrl);
}
var inviteeFirstName = json.get("inviteeFirstName") ; }
var inviteeLastName = json.get("inviteeLastName") ;
var inviteeEmail = json.get("inviteeEmail") ; // Pass the model to the results template
invitation = site.inviteNominated(inviteeFirstName, inviteeLastName, inviteeEmail, inviteeRoleName, serverPath, acceptUrl, rejectUrl); model.site = site;
} model.invitation = invitation;
}
status.code = status.STATUS_CREATED;
// Pass the model to the results template
model.site = site;
model.invitation = invitation;
status.code = status.STATUS_CREATED;
} }
main(); main();

View File

@@ -1,40 +1,39 @@
/** /**
* List invitations implementation * List invitations implementation
*/ */
function main () function main ()
{ {
// Get the site id // Get the site id
var urlElements = url.extension.split("/"); var urlElements = url.extension.split("/");
var shortName = urlElements[0]; var shortName = urlElements[0];
// Get the args // Get the args
var inviteeUserName = args["inviteeUserName"]; var inviteeUserName = args["inviteeUserName"];
var invitationType = args["invitationType"]; var invitationType = args["invitationType"];
var site = siteService.getSite(shortName); var site = siteService.getSite(shortName);
if (site == null) if (site == null)
{ {
// Site cannot be found // Site cannot be found
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist."); status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
return; return;
} }
var props = {}; var props = {};
if(inviteeUserName != null) if (inviteeUserName != null)
{ {
props.inviteeUserName = inviteeUserName props.inviteeUserName = inviteeUserName
} }
if(invitationType != null) if (invitationType != null)
{ {
props.invitationType = invitationType props.invitationType = invitationType
} }
var invitations = site.listInvitations(props); var invitations = site.listInvitations(props);
// Pass the information to the template // Pass the information to the template
model.invitations = invitations; model.invitations = invitations;
} }
main(); main();