Merged 5.2.N (5.2.2) to HEAD (5.2)

134789 rmunteanu: REPO-1306: Delete group membership
      - Added functionality and tests
      - Added minor changes to create group membership functionality ( REPO-1307 )


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@137359 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrei Rebegea
2017-06-14 16:59:24 +00:00
parent 33c862b455
commit 7aabb7a740
5 changed files with 144 additions and 30 deletions

View File

@@ -620,13 +620,14 @@ public class GroupsImpl implements Groups
if (!authorityService.authorityExists(groupMember.getId()))
{
throw new EntityNotFoundException("Group member with id " + groupMember.getId() + " does not exists");
throw new EntityNotFoundException(groupMember.getId());
}
AuthorityType existingAuthorityType = AuthorityType.getAuthorityType(groupMember.getId());
if (existingAuthorityType != authorityType)
{
throw new IllegalArgumentException("Incorrect group member type, " + existingAuthorityType + " exists with the given id");
throw new IllegalArgumentException("Incorrect group member type, "
+ (AuthorityType.USER.equals(existingAuthorityType) ? Groups.PARAM_MEMBER_TYPE_PERSON : existingAuthorityType) + " exists with the given id");
}
authorityService.addAuthority(groupId, groupMember.getId());
@@ -635,6 +636,14 @@ public class GroupsImpl implements Groups
return getGroupMember(authority);
}
public void deleteGroupMembership(String groupId, String groupMemberId)
{
validateGroupId(groupId, false);
validateGroupMemberId(groupMemberId);
// TODO: Verify if groupMemberId is member of groupId
authorityService.removeAuthority(groupId, groupMemberId);
}
private AuthorityType getAuthorityType(String memberType)
{
AuthorityType authorityType = null;
@@ -735,6 +744,18 @@ public class GroupsImpl implements Groups
}
}
private void validateGroupMemberId(String groupMemberId)
{
if (groupMemberId == null || groupMemberId.isEmpty())
{
throw new InvalidArgumentException("group member id is null or empty");
}
if (!(personAuthorityExists(groupMemberId) || groupAuthorityExists(groupMemberId, false)))
{
throw new EntityNotFoundException(groupMemberId);
}
}
private void validateGroup(Group group, boolean isUpdate)
{
if (group == null)
@@ -811,6 +832,11 @@ public class GroupsImpl implements Groups
return authorityExists(AuthorityType.GROUP, authorityName, inferPrefix);
}
private boolean personAuthorityExists(String authorityName)
{
return authorityExists(AuthorityType.USER, authorityName, false);
}
private boolean authorityExists(AuthorityType authorityType, String authorityName, boolean inferPrefix)
{
String name = inferPrefix ? authorityService.getName(authorityType, authorityName) : authorityName;