From 3d481e8df08fec078f36683d012cd527a20591bb Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Thu, 3 Nov 2016 14:01:42 +0000 Subject: [PATCH] Merged 5.2.N (5.2.1) to HEAD (5.2) 131909 mward: REPO-892: allow creation of enabled/disabled users git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@132319 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/rest/api/impl/PeopleImpl.java | 27 ++++++------- .../alfresco/rest/api/model/PersonUpdate.java | 1 + .../alfresco/rest/api/tests/TestPeople.java | 40 ++++++++++++++++++- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java index e6e701ceb5..a86b6d3e4f 100644 --- a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java +++ b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java @@ -25,18 +25,12 @@ */ package org.alfresco.rest.api.impl; -import java.io.Serializable; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.People; import org.alfresco.rest.api.Sites; -import org.alfresco.rest.api.model.Company; import org.alfresco.rest.api.model.Person; import org.alfresco.rest.api.model.PersonUpdate; import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException; @@ -44,6 +38,7 @@ import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; import org.alfresco.service.cmr.repository.*; import org.alfresco.service.cmr.security.AuthenticationService; +import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.NoSuchPersonException; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.site.SiteService; @@ -51,6 +46,11 @@ import org.alfresco.service.cmr.thumbnail.ThumbnailService; import org.alfresco.service.cmr.usage.ContentUsageService; import org.alfresco.service.namespace.QName; +import java.io.Serializable; +import java.util.List; +import java.util.Map; +import java.util.UUID; + /** * Centralises access to people services and maps between representations. * @@ -295,6 +295,11 @@ public class PeopleImpl implements People throw new ConstraintViolatedException("Person '"+person.getUserName()+"' already exists."); } Map props = person.toProperties(); + + MutableAuthenticationService mas = (MutableAuthenticationService) authenticationService; + // TODO: very temporary code, until REPO-1503 (set password) implemented. + mas.createAuthentication(person.getUserName(), UUID.randomUUID().toString().toCharArray()); + mas.setAuthenticationEnabled(person.getUserName(), person.isEnabled()); NodeRef nodeRef = personService.createPerson(props); // Write the contents of PersonUpdate.getDescription() text to a content file @@ -314,15 +319,7 @@ public class PeopleImpl implements People } // Return a fresh retrieval - props = nodeService.getProperties(nodeRef); - // Do not put this pseudo/temp-property into the bag before creating the person - // as it would be created as a residual property. - props.put(Person.PROP_PERSON_DESCRIPTION, person.getDescription()); - final boolean enabled = personService.isEnabled(person.getUserName()); - return new Person(nodeRef, props, enabled); - - // ...or -// return getPerson(person.getUserName()); + return getPerson(person.getUserName()); } private void validateCreatePersonData(PersonUpdate person) diff --git a/source/java/org/alfresco/rest/api/model/PersonUpdate.java b/source/java/org/alfresco/rest/api/model/PersonUpdate.java index 9881c235cc..edf2a54269 100644 --- a/source/java/org/alfresco/rest/api/model/PersonUpdate.java +++ b/source/java/org/alfresco/rest/api/model/PersonUpdate.java @@ -251,6 +251,7 @@ public class PersonUpdate addToMap(properties, ContentModel.PROP_MOBILE, getMobile()); addToMap(properties, ContentModel.PROP_TELEPHONE, getTelephone()); addToMap(properties, ContentModel.PROP_USER_STATUS, getUserStatus()); + addToMap(properties, ContentModel.PROP_ENABLED, isEnabled()); addToMap(properties, ContentModel.PROP_EMAIL_FEED_DISABLED, isEmailNotificationsEnabled() != null ? !isEmailNotificationsEnabled() : null); diff --git a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java index 583682480d..8f798f7d54 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java @@ -176,7 +176,45 @@ public class TestPeople extends EnterpriseTestApi assertEquals(true, p.isEnabled()); assertEquals(true, p.isEmailNotificationsEnabled()); } + + @Test + public void testCreatePerson_canCreateDisabledPerson() throws PublicApiException + { + publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); + // Person disabled + { + PersonUpdate person = new PersonUpdate.Builder(). + id("myUserName04@"+account1.getId()). + firstName("Firstname"). + email("myUserName04@"+account1.getId()). + enabled(false). + build(); + + Person p = people.create(person); + assertEquals(false, p.isEnabled()); + // Check that a freshly retrieved person exhibits the same result + p = people.getPerson(person.getUserName()); + assertEquals(false, p.isEnabled()); + } + + // Person enabled + { + PersonUpdate person = new PersonUpdate.Builder(). + id("myUserName05@"+account1.getId()). + firstName("Firstname"). + email("myUserName05@"+account1.getId()). + enabled(true). + build(); + + Person p = people.create(person); + assertEquals(true, p.isEnabled()); + // Check that a freshly retrieved person exhibits the same result + p = people.getPerson(person.getUserName()); + assertEquals(true, p.isEnabled()); + } + } + @Test public void testCreatePerson_notAllFieldsRequired() throws Exception { @@ -211,7 +249,7 @@ public class TestPeople extends EnterpriseTestApi assertEquals(null, p.getMobile()); assertEquals("1234 5678 9012", p.getTelephone()); assertEquals(null, p.getUserStatus()); - assertEquals(true, p.isEnabled()); + assertEquals(false, p.isEnabled()); assertEquals(false, p.isEmailNotificationsEnabled()); }