mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fixed check for missing user name parameter, and added checks for missing first name and missing last name parameters, to Person Service REST API method POST People.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10215 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,14 +1,29 @@
|
|||||||
function main()
|
function main()
|
||||||
{
|
{
|
||||||
|
//
|
||||||
// Get the person details
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the person with the supplied user name
|
// Create the person with the supplied user name
|
||||||
|
var userName = json.get("userName");
|
||||||
var person = people.createPerson(userName);
|
var person = people.createPerson(userName);
|
||||||
|
|
||||||
// return error message if a person with that user name could not be created
|
// return error message if a person with that user name could not be created
|
||||||
|
@@ -168,8 +168,12 @@ public class PersonServiceTest extends BaseWebScriptTest
|
|||||||
person.put("jobtitle", jobTitle);
|
person.put("jobtitle", jobTitle);
|
||||||
person.put("email", email);
|
person.put("email", email);
|
||||||
|
|
||||||
MockHttpServletResponse response = postRequest(URL_PEOPLE, expectedStatus, person.toString(), "application/json");
|
MockHttpServletResponse response = postRequest(URL_PEOPLE, expectedStatus, person.toString(), "application/json");
|
||||||
this.createdPeople.add(userName);
|
|
||||||
|
if ((userName != null) && (userName.length() != 0))
|
||||||
|
{
|
||||||
|
this.createdPeople.add(userName);
|
||||||
|
}
|
||||||
|
|
||||||
// switch back to non-admin user
|
// switch back to non-admin user
|
||||||
this.authenticationComponent.setCurrentUser(currentUser);
|
this.authenticationComponent.setCurrentUser(currentUser);
|
||||||
@@ -265,9 +269,10 @@ public class PersonServiceTest extends BaseWebScriptTest
|
|||||||
{
|
{
|
||||||
String userName = RandomStringUtils.randomNumeric(6);
|
String userName = RandomStringUtils.randomNumeric(6);
|
||||||
|
|
||||||
// Create a new site
|
// Create a new person
|
||||||
JSONObject result = createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation",
|
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(userName, result.get("userName"));
|
||||||
assertEquals("myTitle", result.get("title"));
|
assertEquals("myTitle", result.get("title"));
|
||||||
assertEquals("myFirstName", result.get("firstName"));
|
assertEquals("myFirstName", result.get("firstName"));
|
||||||
@@ -279,5 +284,48 @@ public class PersonServiceTest extends BaseWebScriptTest
|
|||||||
// Check for duplicate names
|
// Check for duplicate names
|
||||||
createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation",
|
createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation",
|
||||||
"myJobTitle", "myEmail", "myBio", "images/avatar.jpg", 500);
|
"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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user