mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-892: allow creation of enabled/disabled users
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@131909 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -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<QName, Serializable> 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)
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user