From 043af1bbbde4eb660741feb88f5e52783e702d78 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Thu, 9 Apr 2009 14:16:50 +0000 Subject: [PATCH] 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 --- .../repository/invitation/invitations.get.js | 71 +++-- .../site/invitation/invitation.delete.js | 56 ++-- .../site/invitation/invitation.get.js | 48 ++-- .../site/invitation/invitation.post.json.js | 257 +++++++++--------- .../site/invitation/invitations.get.js | 67 +++-- 5 files changed, 245 insertions(+), 254 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/invitation/invitations.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/invitation/invitations.get.js index 541f89f566..f6dd93342b 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/invitation/invitations.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/invitation/invitations.get.js @@ -1,42 +1,41 @@ /** * List/Search invitations implementation */ - -function main () +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 resourceType = args["resourceType"]; - var resourceName = args["resourceName"]; - - var props = {}; - - if(inviteeUserName != null) - { - props.inviteeUserName = inviteeUserName - } - if(invitationType != null) - { - props.invitationType = invitationType - } - if(resourceType != null) - { - props.resourceType = resourceType - } - if(resourceName != null) - { - props.resourceName = resourceName - } - - var invites = invitations.listInvitations(props); - - // Pass the information to the template - model.invitations = invites; + // 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 resourceType = args["resourceType"]; + var resourceName = args["resourceName"]; + + var props = {}; + + if (inviteeUserName != null) + { + props.inviteeUserName = inviteeUserName + } + if (invitationType != null) + { + props.invitationType = invitationType + } + if (resourceType != null) + { + props.resourceType = resourceType + } + if (resourceName != null) + { + props.resourceName = resourceName + } + + var invites = invitations.listInvitations(props); + + // Pass the information to the template + model.invitations = invites; } -main(); +main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.delete.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.delete.js index 590ac6215d..6669d37356 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.delete.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.delete.js @@ -1,33 +1,33 @@ -// Cancel invitation for a web site - +/** + * 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(); + // 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(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.get.js index 4e0847db39..b638528b78 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.get.js @@ -3,32 +3,30 @@ */ 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; - } - + // 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(); - + +main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.post.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.post.json.js index bb36aba23f..b2c674ee90 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.post.json.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.post.json.js @@ -3,137 +3,132 @@ */ 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; + 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") && json.get("inviteeUserName") != "") + { + invitation = site.inviteNominated(json.get("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(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.js index dc2b300c66..4d5b52a511 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitations.get.js @@ -1,40 +1,39 @@ /** * 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; + // 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(); +main(); \ No newline at end of file