diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index e40f5a3cd8..75cecb45ff 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -45,7 +45,7 @@ public class GroupsTests extends RestTest restClient.authenticateUser(userModel).withCoreAPI().usingGroups().createGroup(groupBodyCreate); restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); //+ve - restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate) + restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones,hasSubgroups,description").usingGroups().createGroup(groupBodyCreate) .assertThat().field("zones").contains("APP.DEFAULT") .and().field("isRoot").is(true) .and().field("displayName").is(groupName) @@ -82,7 +82,7 @@ public class GroupsTests extends RestTest restClient.assertStatusCodeIs(HttpStatus.OK); //GetGroupDetails: - restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) + restClient.withCoreAPI().usingParams("include=zones,hasSubgroups,description").usingGroups().getGroupDetail("GROUP_"+groupName) .assertThat().field("id").is("GROUP_"+groupName) .and().field("zones").contains("APP.DEFAULT") .and().field("isRoot").is(true) @@ -94,7 +94,7 @@ public class GroupsTests extends RestTest restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); //VerifyIfParentHasNoSubgroups: - restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) + restClient.withCoreAPI().usingParams("include=zones,hasSubgroups").usingGroups().getGroupDetail("GROUP_"+groupName) .assertThat().field("id").is("GROUP_"+groupName) .and().field("hasSubgroups").is(false); restClient.assertStatusCodeIs(HttpStatus.OK); diff --git a/remote-api/src/main/java/org/alfresco/rest/api/Groups.java b/remote-api/src/main/java/org/alfresco/rest/api/Groups.java index 53eb220387..58b6d13aa8 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/Groups.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/Groups.java @@ -40,8 +40,10 @@ public interface Groups { String PARAM_ID = "id"; String PARAM_DISPLAY_NAME = "displayName"; + String PARAM_INCLUDE_DESCRIPTION = "description"; String PARAM_INCLUDE_PARENT_IDS = "parentIds"; String PARAM_INCLUDE_ZONES = "zones"; + String PARAM_INCLUDE_HAS_SUBGROUPS = "hasSubgroups"; String PARAM_IS_ROOT = "isRoot"; String PARAM_CASCADE = "cascade"; String PARAM_MEMBER_TYPE = "memberType"; diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 92c1cf1818..464d4ff525 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -53,7 +53,6 @@ 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; @@ -71,9 +70,6 @@ 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.InvalidNodeRefException; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; @@ -114,11 +110,9 @@ public class GroupsImpl implements Groups private final static Set LIST_GROUP_MEMBERS_QUERY_PROPERTIES = new HashSet<>(List.of(PARAM_MEMBER_TYPE)); protected AuthorityService authorityService; - protected NodeService nodeService; private AuthorityDAO authorityDAO; protected People people; - protected Nodes nodes; public AuthorityService getAuthorityService() { @@ -130,10 +124,6 @@ public class GroupsImpl implements Groups this.authorityService = authorityService; } - public void setNodeService(NodeService nodeService) { - this.nodeService = nodeService; - } - public void setAuthorityDAO(AuthorityDAO authorityDAO) { this.authorityDAO = authorityDAO; @@ -144,10 +134,6 @@ 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); @@ -185,29 +171,29 @@ public class GroupsImpl implements Groups try { - authorityService.setAuthorityDisplayName(groupId, group.getDisplayName()); + if (StringUtils.isNotEmpty(group.getDescription())) + { + authorityService.setAuthorityDisplayNameAndDescription(groupId, group.getDisplayName(), group.getDescription()); + } + else + { + authorityService.setAuthorityDisplayName(groupId, group.getDisplayName()); + } } catch (AuthorityException ae) { handleAuthorityException(ae); } - if (StringUtils.isNotEmpty(group.getDescription())) - { - Map props = new HashMap<>(); - props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); - authorityDAO.setAuthorityProperties(authorityService.getName(AuthorityType.GROUP, groupId), props); - } - return getGroup(groupId, parameters); } public Group getGroup(String groupId, Parameters parameters) throws EntityNotFoundException { - AuthorityInfo authorityInfo = getAuthorityInfo(groupId); + final List includeParam = parameters.getInclude(); + AuthorityInfo authorityInfo = getAuthorityInfo(groupId, includeParam.contains(PARAM_INCLUDE_DESCRIPTION)); final Set rootAuthorities = getAllRootAuthorities(AuthorityType.GROUP); - final List includeParam = parameters.getInclude(); return getGroup(authorityInfo, includeParam, rootAuthorities); } @@ -227,7 +213,7 @@ public class GroupsImpl implements Groups PagingResults pagingResult; try { - pagingResult = getAuthoritiesInfo(authorityType, groupsFilters, rootAuthorities, sortProp, paging); + pagingResult = getAuthoritiesInfo(authorityType, groupsFilters, rootAuthorities, sortProp, paging, parameters.getInclude().contains(PARAM_INCLUDE_DESCRIPTION)); } catch (UnknownAuthorityException e) { @@ -367,7 +353,7 @@ public class GroupsImpl implements Groups filter(a -> a.startsWith(AuthorityType.GROUP.getPrefixString())). filter(a -> isRootPredicate(finalIsRootParam, rootAuthorities, a)). filter(a -> zonePredicate(a, finalZoneFilter)). - map(this::getAuthorityInfo). + map(a -> getAuthorityInfo(a, includeParam.contains(PARAM_INCLUDE_DESCRIPTION))). sorted(new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond())). collect(Collectors.toList()); @@ -386,7 +372,7 @@ public class GroupsImpl implements Groups } private PagingResults getAuthoritiesInfo(AuthorityType authorityType, GroupsFilter groupsFilter, Set rootAuthorities, - Pair sortProp, Paging paging) + Pair sortProp, Paging paging, boolean includeDescription) { Boolean isRootParam = groupsFilter.getIsRoot(); String zoneFilter = groupsFilter.getZoneFilter(); @@ -402,7 +388,7 @@ public class GroupsImpl implements Groups // Limit the post processing work by using the already loaded // list of root authorities. List authorities = rootAuthorities.stream(). - map(this::getAuthorityInfo). + map(auth -> getAuthorityInfo(auth, includeDescription)). filter(auth -> zonePredicate(auth.getAuthorityName(), zoneFilter)). filter(auth -> displayNamePredicate(auth.getAuthorityDisplayName(), displayNameFilter)). collect(Collectors.toList()); @@ -557,9 +543,9 @@ public class GroupsImpl implements Groups * The authority name. * @return The authority info. */ - private AuthorityInfo getAuthorityInfo(String id) + private AuthorityInfo getAuthorityInfo(String id, boolean includeDescription) { - return getAuthorityInfo(id, false); + return getAuthorityInfo(id, includeDescription, false); } /** @@ -568,11 +554,13 @@ public class GroupsImpl implements Groups * * @param id * The authority name. + * @param includeDescription + * True if description should be loaded * @param defaultDisplayNameIfNull * True if we would like to get a default value (e.g. shortName of the authority) if the authority display name is null. * @return The authority info. */ - private AuthorityInfo getAuthorityInfo(String id, boolean defaultDisplayNameIfNull) + private AuthorityInfo getAuthorityInfo(String id, boolean includeDescription, boolean defaultDisplayNameIfNull) { if (id == null || id.isEmpty()) { @@ -585,9 +573,20 @@ public class GroupsImpl implements Groups throw new EntityNotFoundException(id); } - String authorityDisplayName = getAuthorityDisplayName(id, defaultDisplayNameIfNull); + String authorityDisplayName; + String description = null; - return new AuthorityInfo(null, authorityDisplayName, id); + if (includeDescription) + { + Pair displayNameAndDescription = getAuthorityDisplayNameAndDescription(id, defaultDisplayNameIfNull); + authorityDisplayName = displayNameAndDescription.getFirst(); + description = displayNameAndDescription.getSecond(); + } + else + { + authorityDisplayName = getAuthorityDisplayName(id, defaultDisplayNameIfNull); + } + return new AuthorityInfo(null, authorityDisplayName, id, description); } private String getAuthorityDisplayName(String id, boolean defaultDisplayNameIfNull) @@ -595,6 +594,11 @@ public class GroupsImpl implements Groups return defaultDisplayNameIfNull ? authorityService.getAuthorityDisplayName(id) : authorityDAO.getAuthorityDisplayName(id); } + private Pair getAuthorityDisplayNameAndDescription(String id, boolean defaultDisplayNameIfNull) + { + return defaultDisplayNameIfNull ? authorityService.getAuthorityDisplayNameAndDescription(id) : authorityDAO.getAuthorityDisplayNameAndDescription(id); + } + private Group getGroup(AuthorityInfo authorityInfo, List includeParam, Set rootAuthorities) { if (authorityInfo == null) @@ -607,37 +611,24 @@ public class GroupsImpl implements Groups // REPO-1743 String authorityDisplayName = authorityInfo.getAuthorityDisplayName(); + String description = authorityInfo.getDescription(); if (authorityDisplayName == null || authorityDisplayName.isEmpty()) { - authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName()); + if (includeParam != null && includeParam.contains(PARAM_INCLUDE_DESCRIPTION)) + { + Pair displayNameAndDescription = authorityService.getAuthorityDisplayNameAndDescription(authorityInfo.getAuthorityName()); + authorityDisplayName = displayNameAndDescription.getFirst(); + description = displayNameAndDescription.getSecond(); + } + else + { + authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName()); + } } group.setDisplayName(authorityDisplayName); - - group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); - - Set containedAuthorities; - try - { - containedAuthorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true); - } catch (UnknownAuthorityException e) - { - containedAuthorities = Collections.emptySet(); - } - group.setHasSubgroups(CollectionUtils.isNotEmpty(containedAuthorities)); - - NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName()); - String description; - try - { - description = groupNodeRef != null && nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? - nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() : - null; - } catch (InvalidNodeRefException e) - { - description = null; - } group.setDescription(description); + group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); // Optionally include if (includeParam != null) @@ -660,6 +651,19 @@ public class GroupsImpl implements Groups Set authorityZones = authorityService.getAuthorityZones(authorityInfo.getAuthorityName()); group.setZones(authorityZones); } + + if (includeParam.contains(PARAM_INCLUDE_HAS_SUBGROUPS)) + { + Set containedAuthorities; + try + { + containedAuthorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true); + } catch (UnknownAuthorityException e) + { + containedAuthorities = Collections.emptySet(); + } + group.setHasSubgroups(CollectionUtils.isNotEmpty(containedAuthorities)); + } } return group; @@ -947,7 +951,7 @@ public class GroupsImpl implements Groups } List authorityInfoList = new ArrayList<>(authorities.size()); - authorityInfoList.addAll(authorities.stream().map(this::getAuthorityInfo).collect(Collectors.toList())); + authorityInfoList.addAll(authorities.stream().map(auth -> getAuthorityInfo(auth, false)).collect(Collectors.toList())); // Post process sorting - this should be moved to service // layer. It is done here because sorting is not supported at @@ -996,7 +1000,7 @@ public class GroupsImpl implements Groups private GroupMember getGroupMember(String authorityId) { - AuthorityInfo authorityInfo = getAuthorityInfo(authorityId); + AuthorityInfo authorityInfo = getAuthorityInfo(authorityId, false); return getGroupMember(authorityInfo); } 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 8be6d2fa2c..f5627ad823 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1693,8 +1693,6 @@ - - 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 4d28bb07e6..da3245ee3a 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 @@ -68,6 +68,7 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest private static final String MEMBER_TYPE_GROUP = "GROUP"; private static final String MEMBER_TYPE_PERSON = "PERSON"; private static final String GROUP_EVERYONE = "GROUP_EVERYONE"; + private static final String INCLUDE_DESCRIPTION_HAS_SUBGROUPS = "description,hasSubgroups"; protected AuthorityService authorityService; @@ -666,13 +667,13 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest assertNotNull(group.getId()); assertNotNull(group.getDisplayName()); assertNotNull(group.getIsRoot()); - assertNotNull(group.getHasSubgroups()); if (!ignoreOptionallyIncluded) { // Optionally included. assertNull(group.getParentIds()); assertNull(group.getZones()); + assertNotNull(group.getHasSubgroups()); } } @@ -1420,12 +1421,12 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); Map otherParams = new HashMap<>(); - otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS); + otherParams.put("include", INCLUDE_DESCRIPTION_HAS_SUBGROUPS); Group group = generateGroup(); group.setDescription("testDesc"); - Group createdGroup01 = groupsProxy.createGroup(group, null, HttpServletResponse.SC_CREATED); + Group createdGroup01 = groupsProxy.createGroup(group, otherParams, HttpServletResponse.SC_CREATED); assertNotNull(createdGroup01); assertNotNull(createdGroup01.getId()); @@ -1440,6 +1441,7 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest Group subGroup01 = generateGroup(); subGroup01.setParentIds(subGroup01Parents); + otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS + "," + INCLUDE_DESCRIPTION_HAS_SUBGROUPS); Group createdSubGroup01 = groupsProxy.createGroup(subGroup01, otherParams, HttpServletResponse.SC_CREATED); assertNotNull(createdSubGroup01); assertNotNull(createdSubGroup01.getId()); @@ -1449,7 +1451,7 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest assertFalse(createdSubGroup01.getHasSubgroups()); //validate if parent group now has any subgroup - Group group01 = groupsProxy.getGroup(createdGroup01.getId(), null, HttpServletResponse.SC_OK); + Group group01 = groupsProxy.getGroup(createdGroup01.getId(), otherParams, HttpServletResponse.SC_OK); assertTrue(group01.getHasSubgroups()); } @@ -1623,7 +1625,7 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest final Groups groupsProxy = publicApiClient.groups(); Map otherParams = new HashMap<>(); - otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS); + otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS + "," + org.alfresco.rest.api.Groups.PARAM_INCLUDE_DESCRIPTION); setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java index a6b685d6c5..993a93b3a7 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java @@ -37,6 +37,7 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.AuthorityService.AuthorityFilter; import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; public interface AuthorityDAO { @@ -152,10 +153,17 @@ public interface AuthorityDAO void setAuthorityDisplayName(String authorityName, String authorityDisplayName); /** - * Set the properties for an authority + * Get the display name and description for an authority + * + * @return the display name and description */ - void setAuthorityProperties(String authorityName, Map properties); - + Pair getAuthorityDisplayNameAndDescription(String authorityName); + + /** + * Set the display name and description for an authority + */ + void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description); + /** * Get root authorities */ diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index 86c96957e8..085bcca96a 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -1442,18 +1442,29 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor return; } nodeService.setProperty(ref, ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); - } - @Override - public void setAuthorityProperties(String authorityName, Map properties) + public Pair getAuthorityDisplayNameAndDescription(String authorityName) + { + NodeRef ref = getAuthorityOrNull(authorityName); + if (ref == null) + { + return Pair.nullPair(); + } + Serializable displayName = nodeService.getProperty(ref, ContentModel.PROP_AUTHORITY_DISPLAY_NAME); + Serializable description = nodeService.getProperty(ref, ContentModel.PROP_DESCRIPTION); + return new Pair<>(DefaultTypeConverter.INSTANCE.convert(String.class, displayName), DefaultTypeConverter.INSTANCE.convert(String.class, description)); + } + + public void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description) { NodeRef ref = getAuthorityOrNull(authorityName); if (ref == null) { return; } - properties.forEach((key, value) -> nodeService.setProperty(ref, key, value)); + nodeService.setProperty(ref, ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); + nodeService.setProperty(ref, ContentModel.PROP_DESCRIPTION, description); } public NodeRef getOrCreateZone(String zoneName) diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityInfo.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityInfo.java index 9d6729acc1..cce5aa326b 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityInfo.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityInfo.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * 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 Repository + * %% + * 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.security.authority; import org.alfresco.api.AlfrescoPublicApi; @@ -39,15 +39,24 @@ import org.alfresco.service.cmr.security.AuthorityType; public class AuthorityInfo { private Long nodeId; - private String authorityDisplayName; // eg. My Group, My Role private String authorityName; // eg. GROUP_my1, ROLE_myA + private String description; + public AuthorityInfo(Long nodeId, String authorityDisplayName, String authorityName, String description) + { + this.nodeId = nodeId; + this.authorityDisplayName = authorityDisplayName; + this.authorityName = authorityName; + this.description = description; + } + public AuthorityInfo(Long nodeId, String authorityDisplayName, String authorityName) { this.nodeId = nodeId; this.authorityDisplayName = authorityDisplayName; this.authorityName = authorityName; + this.description = null; } public Long getNodeId() @@ -65,6 +74,10 @@ public class AuthorityInfo return authorityName; } + public String getDescription() { + return description; + } + public String getShortName() { AuthorityType type = AuthorityType.getAuthorityType(authorityName); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java index 8efd66b507..7923bcffe4 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -696,6 +696,29 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean checkTypeIsMutable(type); authorityDAO.setAuthorityDisplayName(authorityName, authorityDisplayName); } + + /** + * {@inheritDoc} + */ + public Pair getAuthorityDisplayNameAndDescription(String name) + { + Pair displayNameAndDescription = authorityDAO.getAuthorityDisplayNameAndDescription(name); + if(displayNameAndDescription.getFirst() == null) + { + displayNameAndDescription.setFirst(getShortName(name)); + } + return displayNameAndDescription; + } + + /** + * {@inheritDoc} + */ + public void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description) + { + AuthorityType type = AuthorityType.getAuthorityType(authorityName); + checkTypeIsMutable(type); + authorityDAO.setAuthorityDisplayNameAndDescription(authorityName, authorityDisplayName, description); + } /** * {@inheritDoc} diff --git a/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java b/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java index e1cd6ac1ff..65835cc45e 100644 --- a/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java +++ b/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java @@ -38,6 +38,7 @@ import org.alfresco.service.Auditable; import org.alfresco.service.NotAuditable; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; /** * The service that encapsulates authorities granted to users. @@ -441,7 +442,16 @@ public interface AuthorityService * @return - the display name */ @Auditable(parameters = {"name"}) - public String getAuthorityDisplayName(String name); + String getAuthorityDisplayName(String name); + + /** + * Get the display name and description for the given authority. + * + * @param name - the full authority string including any prefix (e.g. GROUP_woof) + * @return - pair containing display name and description + */ + @Auditable(parameters = {"name"}) + Pair getAuthorityDisplayNameAndDescription(String name); /** * Set the display name for the given authority. @@ -451,7 +461,18 @@ public interface AuthorityService * @param authorityDisplayName String */ @Auditable(parameters = {"authorityName", "authorityDisplayName"}) - public void setAuthorityDisplayName(String authorityName, String authorityDisplayName); + void setAuthorityDisplayName(String authorityName, String authorityDisplayName); + + /** + * Set the display name and description for the given authority. + * Setting the display name is only supported for authorities of type group + * + * @param authorityName String + * @param authorityDisplayName String + * @param description String + */ + @Auditable(parameters = {"authorityName", "authorityDisplayName", "description"}) + void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description); /** * Gets the authority node for the specified name diff --git a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java index 2dc6af536f..eb4753b0f9 100644 --- a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java +++ b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java @@ -83,6 +83,7 @@ import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.service.transaction.TransactionService; import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; +import org.alfresco.util.Pair; import org.alfresco.util.testing.category.LuceneTests; import org.alfresco.util.testing.category.RedundantTests; import org.junit.FixMethodOrder; @@ -616,34 +617,6 @@ public class AuthorityServiceTest extends TestCase pubAuthorityService.deleteAuthority(auth); } - @Test - public void testUpdateAuthorityProperties() - { - String auth; - String groupName = "TESTGROUP"; - String prefixedGroupName = "GROUP_TESTGROUP"; - String description = "testDesc"; - String title = "testTitle"; - Map props = new HashMap<>(); - props.put(ContentModel.PROP_DESCRIPTION, description); - props.put(ContentModel.PROP_TITLE, title); - - // create authority with properties - auth = pubAuthorityService.createAuthority(AuthorityType.GROUP, groupName, props); - assertTrue(pubAuthorityService.authorityExists(prefixedGroupName)); - - // update authority properties - String newDescription = "newTestDesc"; - String newTitle = "newTestTitle"; - props.put(ContentModel.PROP_DESCRIPTION, newDescription); - props.put(ContentModel.PROP_TITLE, newTitle); - authorityDAO.setAuthorityProperties(auth, props); - NodeRef nodeRef = pubAuthorityService.getAuthorityNodeRef(auth); - assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION), newDescription); - assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE), newTitle); - pubAuthorityService.deleteAuthority(auth); - } - public void testCreateOwnerAuth() { try @@ -1459,6 +1432,20 @@ public class AuthorityServiceTest extends TestCase assertEquals(pubAuthorityService.getAuthorityDisplayName("ROLE_Gibbon"), "Gibbon"); assertEquals(pubAuthorityService.getAuthorityDisplayName("Monkey"), "Monkey"); } + + public void testAuthorityDisplayNameAndDescription() + { + Map props = new HashMap<>(); + props.put(ContentModel.PROP_DESCRIPTION, "Test auth description"); + String testAuth = pubAuthorityService.createAuthority(AuthorityType.GROUP, "Test auth", props); + Pair displayNameAndDescription = pubAuthorityService.getAuthorityDisplayNameAndDescription(testAuth); + assertEquals(displayNameAndDescription.getFirst(), "Test auth"); + assertEquals(displayNameAndDescription.getSecond(), "Test auth description"); + pubAuthorityService.setAuthorityDisplayNameAndDescription(testAuth, "Modified auth", "Modified description"); + displayNameAndDescription = pubAuthorityService.getAuthorityDisplayNameAndDescription(testAuth); + assertEquals(displayNameAndDescription.getFirst(), "Modified auth"); + assertEquals(displayNameAndDescription.getSecond(), "Modified description"); + } public void testGetAuthoritiesFilteringSorting() {