diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.js b/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.js index fd84ece1fe..b3d0d48ba9 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.js @@ -1,14 +1,29 @@ function main() { + // // Get the person details - var userName = json.get("userName"); - if ((userName === null) || (userName.length == 0)) + // + + if ((json.isNull("userName")) || (json.get("userName").length() == 0)) { - status.setCode(status.STATUS_BAD_REQUEST, "User name missing when creating person") + status.setCode(status.STATUS_BAD_REQUEST, "User name missing when creating person"); + return; + } + + if ((json.isNull("firstName")) || (json.get("firstName").length() == 0)) + { + status.setCode(status.STATUS_BAD_REQUEST, "First name missing when creating person"); + return; + } + + if ((json.isNull("lastName")) || (json.get("lastName").length() == 0)) + { + status.setCode(status.STATUS_BAD_REQUEST, "Last name missing when creating person"); return; } // Create the person with the supplied user name + var userName = json.get("userName"); var person = people.createPerson(userName); // return error message if a person with that user name could not be created diff --git a/source/java/org/alfresco/repo/web/scripts/person/PersonServiceTest.java b/source/java/org/alfresco/repo/web/scripts/person/PersonServiceTest.java index dbc1f590ae..0cd637b89b 100644 --- a/source/java/org/alfresco/repo/web/scripts/person/PersonServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/person/PersonServiceTest.java @@ -168,8 +168,12 @@ public class PersonServiceTest extends BaseWebScriptTest person.put("jobtitle", jobTitle); person.put("email", email); - MockHttpServletResponse response = postRequest(URL_PEOPLE, expectedStatus, person.toString(), "application/json"); - this.createdPeople.add(userName); + MockHttpServletResponse response = postRequest(URL_PEOPLE, expectedStatus, person.toString(), "application/json"); + + if ((userName != null) && (userName.length() != 0)) + { + this.createdPeople.add(userName); + } // switch back to non-admin user this.authenticationComponent.setCurrentUser(currentUser); @@ -265,9 +269,10 @@ public class PersonServiceTest extends BaseWebScriptTest { String userName = RandomStringUtils.randomNumeric(6); - // Create a new site + // Create a new person JSONObject result = createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation", - "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", Status.STATUS_OK); + "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", + Status.STATUS_OK); assertEquals(userName, result.get("userName")); assertEquals("myTitle", result.get("title")); assertEquals("myFirstName", result.get("firstName")); @@ -279,5 +284,48 @@ public class PersonServiceTest extends BaseWebScriptTest // Check for duplicate names createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation", "myJobTitle", "myEmail", "myBio", "images/avatar.jpg", 500); + } + + public void testCreatePersonMissingUserName() throws Exception + { + // Create a new person with userName == null (user name missing) + createPerson(null, "myTitle", "myFirstName", "myLastName", "myOrganisation", + "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", + Status.STATUS_BAD_REQUEST); + + // Create a new person with userName == "" (user name is blank) + createPerson("", "myTitle", "myFirstName", "myLastName", "myOrganisation", + "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", + Status.STATUS_BAD_REQUEST); + } + + public void testCreatePersonMissingFirstName() throws Exception + { + String userName = RandomStringUtils.randomNumeric(6); + + // Create a new person with firstName == null (first name missing) + createPerson(userName, "myTitle", null, "myLastName", "myOrganisation", + "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", + Status.STATUS_BAD_REQUEST); + + // Create a new person with firstName == "" (first name is blank) + createPerson(userName, "myTitle", "", "myLastName", "myOrganisation", + "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", + Status.STATUS_BAD_REQUEST); + } + + public void testCreatePersonMissingLastName() throws Exception + { + String userName = RandomStringUtils.randomNumeric(6); + + // Create a new person with lastName == null (last name is missing) + createPerson(userName, "myTitle", "myFirstName", null, "myOrganisation", + "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", + Status.STATUS_BAD_REQUEST); + + // Create a new person with lastName == "" (last name is blank) + createPerson(userName, "myTitle", "myFirstName", "", "myOrganisation", + "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", + Status.STATUS_BAD_REQUEST); } }