Skip to content
Snippets Groups Projects
Commit ac753dca authored by Mihai Danaila's avatar Mihai Danaila
Browse files

SSDM-14194: AdminUI improved error message on already existing userid creation

parent 51aa8ec4
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
...@@ -202,6 +202,19 @@ public class CreatePersonExecutor ...@@ -202,6 +202,19 @@ public class CreatePersonExecutor
{ {
try try
{ {
PersonPE systemUser = daoFactory.getPersonDAO().tryFindPersonByUserId(PersonPE.SYSTEM_USER_ID);
if (systemUser == null)
{
throw new UserFailureException(
"Couldn't find system user with default settings in the DB.");
}
PersonPE existingPerson = daoFactory.getPersonDAO().tryFindPersonByUserId(person.getUserId());
if (existingPerson != null){
throw new UserFailureException(
"User with User Id [" + person.getUserId() + "] already exists!"
);
}
daoFactory.getPersonDAO().createPerson(person); daoFactory.getPersonDAO().createPerson(person);
} catch (final DataAccessException e) } catch (final DataAccessException e)
{ {
......
...@@ -20,6 +20,7 @@ import static org.testng.Assert.assertEquals; ...@@ -20,6 +20,7 @@ import static org.testng.Assert.assertEquals;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -58,6 +59,38 @@ public class CreatePersonTest extends AbstractTest ...@@ -58,6 +59,38 @@ public class CreatePersonTest extends AbstractTest
assertEquals(person.getSpace().getCode(), "CISD"); assertEquals(person.getSpace().getCode(), "CISD");
} }
@Test
public void testCreateExistingPerson()
{
// Given
String sessionToken = v3api.login(TEST_USER, PASSWORD);
PersonCreation personCreation = new PersonCreation();
personCreation.setUserId("user-existing");
// When
List<PersonPermId> persons = v3api.createPersons(sessionToken, List.of(personCreation));
// Then
assertEquals(persons.toString(), "[" + personCreation.getUserId() + "]");
PersonFetchOptions fetchOptions = new PersonFetchOptions();
fetchOptions.withRegistrator();
Person person = v3api.getPersons(sessionToken, persons, fetchOptions).get(persons.get(0));
assertEquals(person.getUserId(), personCreation.getUserId());
assertEquals(person.getRegistrator().getUserId(), TEST_USER);
// Given
PersonCreation existingPersonCreation = new PersonCreation();
existingPersonCreation.setUserId("user-existing");
// When
try
{
List<PersonPermId> existingPersons = v3api.createPersons(sessionToken, List.of(existingPersonCreation));
} catch (UserFailureException e)
{
assertEquals("User with User Id [" + existingPersonCreation.getUserId() + "] already exists! (Context: [])", e.getMessage());
}
}
@Test(dataProvider = "usersNotAllowedToCreatePersons") @Test(dataProvider = "usersNotAllowedToCreatePersons")
public void testCreateWithUserCausingAuthorizationFailure(final String user) public void testCreateWithUserCausingAuthorizationFailure(final String user)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment