mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-5506 Description handling rework
This commit is contained in:
@@ -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);
|
||||
|
@@ -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";
|
||||
|
@@ -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<String> 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);
|
||||
@@ -184,30 +170,30 @@ public class GroupsImpl implements Groups
|
||||
validateGroup(group, true);
|
||||
|
||||
try
|
||||
{
|
||||
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<QName, Serializable> 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<String> includeParam = parameters.getInclude();
|
||||
AuthorityInfo authorityInfo = getAuthorityInfo(groupId, includeParam.contains(PARAM_INCLUDE_DESCRIPTION));
|
||||
|
||||
final Set<String> rootAuthorities = getAllRootAuthorities(AuthorityType.GROUP);
|
||||
final List<String> includeParam = parameters.getInclude();
|
||||
|
||||
return getGroup(authorityInfo, includeParam, rootAuthorities);
|
||||
}
|
||||
@@ -227,7 +213,7 @@ public class GroupsImpl implements Groups
|
||||
PagingResults<AuthorityInfo> 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<AuthorityInfo> getAuthoritiesInfo(AuthorityType authorityType, GroupsFilter groupsFilter, Set<String> rootAuthorities,
|
||||
Pair<String, Boolean> sortProp, Paging paging)
|
||||
Pair<String, Boolean> 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<AuthorityInfo> 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<String, String> 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<String, String> getAuthorityDisplayNameAndDescription(String id, boolean defaultDisplayNameIfNull)
|
||||
{
|
||||
return defaultDisplayNameIfNull ? authorityService.getAuthorityDisplayNameAndDescription(id) : authorityDAO.getAuthorityDisplayNameAndDescription(id);
|
||||
}
|
||||
|
||||
private Group getGroup(AuthorityInfo authorityInfo, List<String> includeParam, Set<String> 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())
|
||||
{
|
||||
if (includeParam != null && includeParam.contains(PARAM_INCLUDE_DESCRIPTION))
|
||||
{
|
||||
Pair<String, String> 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<String> 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<String> authorityZones = authorityService.getAuthorityZones(authorityInfo.getAuthorityName());
|
||||
group.setZones(authorityZones);
|
||||
}
|
||||
|
||||
if (includeParam.contains(PARAM_INCLUDE_HAS_SUBGROUPS))
|
||||
{
|
||||
Set<String> 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<AuthorityInfo> 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);
|
||||
}
|
||||
|
@@ -1693,8 +1693,6 @@
|
||||
<property name="authorityService" ref="AuthorityService" />
|
||||
<property name="authorityDAO" ref="authorityDAO" />
|
||||
<property name="people" ref="people"/>
|
||||
<property name="nodes" ref="Nodes"/>
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
</bean>
|
||||
|
||||
<bean id="Groups" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
|
@@ -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<String, String> 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<String, String> 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);
|
||||
|
||||
|
@@ -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,9 +153,16 @@ 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<QName, Serializable> properties);
|
||||
Pair<String, String> getAuthorityDisplayNameAndDescription(String authorityName);
|
||||
|
||||
/**
|
||||
* Set the display name and description for an authority
|
||||
*/
|
||||
void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description);
|
||||
|
||||
/**
|
||||
* Get root authorities
|
||||
|
@@ -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<QName, Serializable> properties)
|
||||
public Pair<String, String> 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)
|
||||
|
@@ -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);
|
||||
|
@@ -697,6 +697,29 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
||||
authorityDAO.setAuthorityDisplayName(authorityName, authorityDisplayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Pair<String, String> getAuthorityDisplayNameAndDescription(String name)
|
||||
{
|
||||
Pair<String, String> 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}
|
||||
*/
|
||||
|
@@ -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<String, String> 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
|
||||
|
@@ -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<QName, Serializable> 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
|
||||
@@ -1460,6 +1433,20 @@ public class AuthorityServiceTest extends TestCase
|
||||
assertEquals(pubAuthorityService.getAuthorityDisplayName("Monkey"), "Monkey");
|
||||
}
|
||||
|
||||
public void testAuthorityDisplayNameAndDescription()
|
||||
{
|
||||
Map<QName, Serializable> props = new HashMap<>();
|
||||
props.put(ContentModel.PROP_DESCRIPTION, "Test auth description");
|
||||
String testAuth = pubAuthorityService.createAuthority(AuthorityType.GROUP, "Test auth", props);
|
||||
Pair<String, String> 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()
|
||||
{
|
||||
String TEST_RUN = System.currentTimeMillis()+"-";
|
||||
|
Reference in New Issue
Block a user