diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java index ec8c28b105..d8a9b975b2 100644 --- a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java @@ -38,8 +38,12 @@ public class RestGroupsModel extends TestModel implements IRestModel parentIds; @@ -75,6 +79,22 @@ public class RestGroupsModel extends TestModel implements IRestModel props = groupNode.getProperties(); + if (props != null) + { + props.put("cm:description", group.getDescription()); + } + } + return getGroup(authority, parameters); } @@ -168,6 +187,17 @@ public class GroupsImpl implements Groups handleAuthorityException(ae); } + if (group.getDescription() != null && !group.getDescription().isEmpty()) + { + NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(group.getDisplayName()); + Node groupNode = nodes.getNode(groupNodeRef.getId()); + Map props = groupNode.getProperties(); + if (props != null) + { + props.put("cm:description", group.getDescription()); + } + } + return getGroup(groupId, parameters); } @@ -584,6 +614,17 @@ public class GroupsImpl implements Groups group.setDisplayName(authorityDisplayName); group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); + group.setHasSubgroups(!authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true).isEmpty()); + + NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityDisplayName); + Node groupNode = nodes.getNode(groupNodeRef.getId()); + Map props = groupNode.getProperties(); + String description = ""; + if (props != null) + { + description = props.get("cm:description") != null ? (String) props.get("cm:description") : ""; + } + group.setDescription(description); // Optionally include if (includeParam != null) @@ -1014,6 +1055,10 @@ public class GroupsImpl implements Groups { throw new InvalidArgumentException("Group update does not support field: zones"); } + if (group.wasSet(Group.HAS_SUBGROUPS)) + { + throw new InvalidArgumentException("Group update does not support field: hasSubgroups"); + } } } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java b/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java index 6ef826229c..8b4a364751 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java @@ -42,7 +42,9 @@ public class Group implements Comparable protected String id; // group id (aka authority name) protected String displayName; + protected String description; protected Boolean isRoot; + protected Boolean hasSubgroups; protected Set parentIds; protected Set zones; @@ -50,7 +52,9 @@ public class Group implements Comparable public static final String ID = "id"; public static final String DISPLAY_NAME = "displayName"; + public static final String DESCRIPTION = "description"; public static final String IS_ROOT = "isRoot"; + public static final String HAS_SUBGROUPS = "hasSubgroups"; public static final String PARENT_IDS = "parentIds"; public static final String ZONES = "zones"; @@ -81,6 +85,14 @@ public class Group implements Comparable setFields.put(DISPLAY_NAME, true); } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + public Boolean getIsRoot() { return isRoot; @@ -92,6 +104,14 @@ public class Group implements Comparable setFields.put(IS_ROOT, true); } + public Boolean getHasSubgroups() { + return hasSubgroups; + } + + public void setHasSubgroups(Boolean hasSubgroups) { + this.hasSubgroups = hasSubgroups; + } + public Set getParentIds() { return parentIds; @@ -154,7 +174,8 @@ public class Group implements Comparable @Override public String toString() { - return "Group [id=" + id + ", displayName=" + displayName + ", isRoot=" + isRoot + "]"; + return "Group [id=" + id + ", displayName=" + displayName + ", description=" + description + + ", isRoot=" + isRoot + ", hasSubgroups=" + hasSubgroups + "]"; } public boolean wasSet(String fieldName) diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index f5627ad823..bae0d4b540 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1693,6 +1693,7 @@ + diff --git a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java index 9e2a2e5865..9c15689c0e 100644 --- a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.web.scripts.groups; @@ -229,7 +229,8 @@ public class GroupsTest extends BaseWebScriptTest assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - gotRootGroup = true; + assertEquals("hasSubgroups wrong", true, rootGroup.getString("hasSubgroups")); + gotRootGroup = true; } if(rootGroup.getString("shortName").equals(EMAIL_GROUP)) { @@ -270,7 +271,8 @@ public class GroupsTest extends BaseWebScriptTest assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - } + assertEquals("hasSubgroups wrong", true, rootGroup.getString("hasSubgroups")); + } } } @@ -293,7 +295,8 @@ public class GroupsTest extends BaseWebScriptTest assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - } + assertEquals("hasSubgroups wrong", true, rootGroup.getString("hasSubgroups")); + } } } @@ -382,12 +385,14 @@ public class GroupsTest extends BaseWebScriptTest */ { JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); + newGroupJSON.put("displayName", myDisplayName); + newGroupJSON.put("description", "testDesc"); Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); JSONObject top = new JSONObject(response.getContentAsString()); JSONObject rootGroup = top.getJSONObject("data"); assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName")); assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName")); + assertEquals("description wrong", "testDesc", rootGroup.getString("description")); } /** @@ -502,7 +507,18 @@ public class GroupsTest extends BaseWebScriptTest assertEquals("shortName wrong", TEST_LINK, subGroup.getString("shortName")); assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); } - + + /** + * Check if myGroup has subgroups + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject myGroup = top.getJSONObject("data"); + assertTrue(myGroup.getBoolean("hasSubgroups")); + } + /** * Now link in an existing user */ @@ -555,6 +571,17 @@ public class GroupsTest extends BaseWebScriptTest //assertTrue("group B not removed", data.length() == 0); } + + /** + * Check if myGroup has no subgroups + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject myGroup = top.getJSONObject("data"); + assertFalse(myGroup.getBoolean("hasSubgroups")); + } /** * Create a new group (BUFFY) @@ -613,19 +640,22 @@ public class GroupsTest extends BaseWebScriptTest { String myGroupName = "GT_UG"; String myDisplayName = "GT_UGDisplay"; + String description = "GT_UGDesc"; String myNewDisplayName = "GT_UGDisplayNew"; - - this.authenticationComponent.setSystemUserAsCurrentUser(); + String newDescription = "GT_UGDescNew"; + + this.authenticationComponent.setSystemUserAsCurrentUser(); try { /** - * Create a root group + * Create a root group with descrription */ { JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); - sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); + newGroupJSON.put("displayName", myDisplayName); + newGroupJSON.put("description", description); + sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); } /** @@ -633,14 +663,15 @@ public class GroupsTest extends BaseWebScriptTest */ { JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myNewDisplayName); - Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK); + newGroupJSON.put("displayName", myNewDisplayName); + newGroupJSON.put("description", newDescription); + Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK); JSONObject top = new JSONObject(response.getContentAsString()); logger.debug(response.getContentAsString()); JSONObject data = top.getJSONObject("data"); assertTrue(data.length() > 0); assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - + assertEquals("description wrong", newDescription, data.getString("description")); } /** @@ -653,7 +684,7 @@ public class GroupsTest extends BaseWebScriptTest JSONObject data = top.getJSONObject("data"); assertTrue(data.length() > 0); assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - + assertEquals("description wrong", newDescription, data.getString("description")); } /** diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index df0e8f45ed..1cd05a8d9b 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -43,11 +43,9 @@ import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.util.GUID; -import org.alfresco.util.testing.category.LuceneTests; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.experimental.categories.Category; import org.mockito.Mock; import jakarta.servlet.http.HttpServletResponse; @@ -663,7 +661,9 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest assertNotNull(group); assertNotNull(group.getId()); assertNotNull(group.getDisplayName()); + assertNotNull(group.getDescription()); assertNotNull(group.getIsRoot()); + assertNotNull(group.getHasSubgroups()); if (!ignoreOptionallyIncluded) { @@ -1421,13 +1421,16 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS); Group group = generateGroup(); + group.setDescription("testDesc"); Group createdGroup01 = groupsProxy.createGroup(group, null, HttpServletResponse.SC_CREATED); assertNotNull(createdGroup01); assertNotNull(createdGroup01.getId()); + assertEquals(createdGroup01.getDescription(), "testDesc"); assertTrue(createdGroup01.getIsRoot()); assertNull(createdGroup01.getParentIds()); + assertFalse(createdGroup01.getHasSubgroups()); Set subGroup01Parents = new HashSet<>(); subGroup01Parents.add(createdGroup01.getId()); @@ -1441,6 +1444,8 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest assertFalse(createdSubGroup01.getIsRoot()); assertNotNull(createdSubGroup01.getParentIds()); assertEquals(subGroup01Parents, createdSubGroup01.getParentIds()); + assertTrue(createdGroup01.getHasSubgroups()); + assertFalse(createdSubGroup01.getHasSubgroups()); } // Group id is missing. @@ -1623,6 +1628,7 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest subGroupParents.add(group.getId()); Group generatedSubGroup = generateGroup(); + generatedSubGroup.setDescription("initialDesc"); generatedSubGroup.setParentIds(subGroupParents); Group subGroup = groupsProxy.createGroup(generatedSubGroup, otherParams, HttpServletResponse.SC_CREATED); @@ -1645,9 +1651,11 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest String displayName = "newDisplayName"; + String description = "newDesc"; Group mySubGroup = new Group(); mySubGroup.setDisplayName(displayName); + mySubGroup.setDescription(description); Group updateGroup = groupsProxy.updateGroup(subGroup.getId(), mySubGroup, otherParams, HttpServletResponse.SC_OK); @@ -1657,8 +1665,9 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest assertFalse(updateGroup.getIsRoot()); assertNotNull(updateGroup.getParentIds()); - // Check that only display name changed. + // Check that only display name and description changed. assertEquals(displayName, updateGroup.getDisplayName()); + assertEquals(description, updateGroup.getDescription()); // Check that nothing else changed. assertEquals(subGroup.getId(), updateGroup.getId());