From 2fc6bda87a3e088c71193baa3d4df776df6e023d Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Thu, 1 Dec 2016 11:29:11 +0000 Subject: [PATCH] Merged mward/5.2.n-repo1636-contentinfo (5.2.1) to 5.2.N (5.2.1) 133294 mward: REPO-1636: Filter cm:preferenceValues and usr:enabled properties when getting people git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133309 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/rest/api/impl/PeopleImpl.java | 17 +++++-- .../alfresco/rest/api/tests/TestPeople.java | 45 ++++++++++++++----- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java index 0499ab100a..9381b84bbb 100644 --- a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java +++ b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java @@ -25,9 +25,6 @@ */ package org.alfresco.rest.api.impl; -import java.io.Serializable; -import java.util.*; - import org.alfresco.model.ContentModel; import org.alfresco.query.PagingRequest; import org.alfresco.query.PagingResults; @@ -64,6 +61,16 @@ import org.alfresco.service.cmr.usage.ContentUsageService; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; +import java.io.Serializable; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** * Centralises access to people services and maps between representations. * @@ -97,7 +104,9 @@ public class PeopleImpl implements People ContentModel.PROP_GOOGLEUSERNAME, ContentModel.PROP_SIZE_QUOTA, ContentModel.PROP_SIZE_CURRENT, - ContentModel.PROP_EMAIL_FEED_DISABLED); + ContentModel.PROP_EMAIL_FEED_DISABLED, + ContentModel.PROP_PREFERENCE_VALUES, + ContentModel.PROP_ENABLED); protected Nodes nodes; protected Sites sites; 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 8c598eb1bf..31bf08a77a 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java @@ -25,11 +25,6 @@ */ package org.alfresco.rest.api.tests; -import static org.junit.Assert.*; - -import java.io.Serializable; -import java.util.*; - import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.rest.api.tests.RepoService.TestNetwork; @@ -42,8 +37,7 @@ import org.alfresco.rest.api.tests.client.RequestContext; import org.alfresco.rest.api.tests.client.data.Company; import org.alfresco.rest.api.tests.client.data.JSONAble; import org.alfresco.rest.api.tests.client.data.Person; -import org.alfresco.service.cmr.dictionary.CustomModelService; -import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.preference.PreferenceService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.PersonService; @@ -55,6 +49,27 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.EmptyStackException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + public class TestPeople extends EnterpriseTestApi { private People people; @@ -473,13 +488,15 @@ public class TestPeople extends EnterpriseTestApi // the REST API's "create person" function here, so we're isolating this test from it. PersonService personService = applicationContext.getBean("PersonService", PersonService.class); NodeService nodeService = applicationContext.getBean("NodeService", NodeService.class); + PreferenceService prefService = applicationContext.getBean("PreferenceService", PreferenceService.class); Map nodeProps = new HashMap<>(); // The cm:titled aspect should be auto-added for the cm:title property nodeProps.put(ContentModel.PROP_TITLE, "A title"); // These properties should not be present when a person is retrieved // since they are present as top-level fields. - nodeProps.put(ContentModel.PROP_USERNAME, "docbrown@"+account1.getId()); + String userName = "docbrown@" + account1.getId(); + nodeProps.put(ContentModel.PROP_USERNAME, userName); nodeProps.put(ContentModel.PROP_FIRSTNAME, "Doc"); nodeProps.put(ContentModel.PROP_LASTNAME, "Brown"); nodeProps.put(ContentModel.PROP_JOBTITLE, "Inventor"); @@ -510,13 +527,16 @@ public class TestPeople extends EnterpriseTestApi AuthenticationUtil.setFullyAuthenticatedUser("admin@"+account1.getId()); personService.createPerson(nodeProps); + + // Set a preference, so that we can test that we're filtering this property correctly. + prefService.setPreferences(userName, Collections.singletonMap("olives", "green")); // Get the person using the REST API publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin")); - Person person = people.getPerson("docbrown@"+account1.getId()); + Person person = people.getPerson(userName); // Did we get the correct aspects/properties? - assertEquals("docbrown@"+account1.getId(), person.getId()); + assertEquals(userName, person.getId()); assertEquals("Doc", person.getFirstName()); assertEquals("A title", person.getProperties().get("cm:title")); assertTrue(person.getAspectNames().contains("cm:titled")); @@ -548,6 +568,11 @@ public class TestPeople extends EnterpriseTestApi assertFalse(person.getProperties().containsKey("cm:sizeCurrent")); assertFalse(person.getProperties().containsKey("cm:emailFeedDisabled")); assertFalse(person.getProperties().containsKey("cm:persondescription")); + assertFalse(person.getProperties().containsKey("usr:enabled")); + // TODO: others, e.g. usr:* ? + // We also don't want cm:preferenceValues (see REPO-1636) + assertFalse(person.getProperties().containsKey("cm:preferenceValues")); + // Check that no properties are present that should have been filtered. for (String key : person.getProperties().keySet())