mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-5506 Add description and hasSubgroups to groups API
This commit is contained in:
@@ -51,9 +51,11 @@ import org.alfresco.repo.security.authority.AuthorityInfo;
|
||||
import org.alfresco.repo.security.authority.UnknownAuthorityException;
|
||||
import org.alfresco.rest.antlr.WhereClauseParser;
|
||||
import org.alfresco.rest.api.Groups;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.People;
|
||||
import org.alfresco.rest.api.model.Group;
|
||||
import org.alfresco.rest.api.model.GroupMember;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
@@ -68,6 +70,7 @@ import org.alfresco.rest.framework.resource.parameters.where.Query;
|
||||
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper;
|
||||
import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker;
|
||||
import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
@@ -109,6 +112,7 @@ public class GroupsImpl implements Groups
|
||||
private AuthorityDAO authorityDAO;
|
||||
|
||||
protected People people;
|
||||
protected Nodes nodes;
|
||||
|
||||
public AuthorityService getAuthorityService()
|
||||
{
|
||||
@@ -130,6 +134,10 @@ public class GroupsImpl implements Groups
|
||||
this.people = people;
|
||||
}
|
||||
|
||||
public void setNodes(Nodes nodes) {
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
public Group create(Group group, Parameters parameters)
|
||||
{
|
||||
validateGroup(group, false);
|
||||
@@ -151,6 +159,17 @@ public class GroupsImpl implements Groups
|
||||
authorityService.addAuthority(group.getParentIds(), authority);
|
||||
}
|
||||
|
||||
if (group.getDescription() != null && !group.getDescription().isEmpty())
|
||||
{
|
||||
NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityDisplayName);
|
||||
Node groupNode = nodes.getNode(groupNodeRef.getId());
|
||||
Map<String, Object> 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<String, Object> 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<String, Object> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,9 @@ public class Group implements Comparable<Group>
|
||||
|
||||
protected String id; // group id (aka authority name)
|
||||
protected String displayName;
|
||||
protected String description;
|
||||
protected Boolean isRoot;
|
||||
protected Boolean hasSubgroups;
|
||||
protected Set<String> parentIds;
|
||||
protected Set<String> zones;
|
||||
|
||||
@@ -50,7 +52,9 @@ public class Group implements Comparable<Group>
|
||||
|
||||
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<Group>
|
||||
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<Group>
|
||||
setFields.put(IS_ROOT, true);
|
||||
}
|
||||
|
||||
public Boolean getHasSubgroups() {
|
||||
return hasSubgroups;
|
||||
}
|
||||
|
||||
public void setHasSubgroups(Boolean hasSubgroups) {
|
||||
this.hasSubgroups = hasSubgroups;
|
||||
}
|
||||
|
||||
public Set<String> getParentIds()
|
||||
{
|
||||
return parentIds;
|
||||
@@ -154,7 +174,8 @@ public class Group implements Comparable<Group>
|
||||
@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)
|
||||
|
@@ -1693,6 +1693,7 @@
|
||||
<property name="authorityService" ref="AuthorityService" />
|
||||
<property name="authorityDAO" ref="authorityDAO" />
|
||||
<property name="people" ref="people"/>
|
||||
<property name="nodes" ref="nodes"/>
|
||||
</bean>
|
||||
|
||||
<bean id="Groups" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* #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 <http://www.gnu.org/licenses/>.
|
||||
* #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"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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<String> 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());
|
||||
|
Reference in New Issue
Block a user