mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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/BRANCHES/DEV/5.2.N/root@134789 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -116,7 +116,6 @@ public interface Groups
|
||||
* @param parameters
|
||||
* the {@link Parameters} object to get the parameters passed
|
||||
* into the request including: - include param (parentIds, zones)
|
||||
* @return Updated group
|
||||
*/
|
||||
void delete(String groupId, Parameters parameters);
|
||||
|
||||
@@ -139,4 +138,13 @@ public interface Groups
|
||||
* @return a {@code org.alfresco.rest.api.model.GroupMember} object
|
||||
*/
|
||||
GroupMember createGroupMember(String groupId, GroupMember groupMember);
|
||||
|
||||
/**
|
||||
*
|
||||
* Delete group membership
|
||||
*
|
||||
* @param groupId
|
||||
* @param groupMemberId
|
||||
*/
|
||||
void deleteGroupMembership(String groupId, String groupMemberId);
|
||||
}
|
||||
|
@@ -45,7 +45,8 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
* @author cturlica
|
||||
*/
|
||||
@RelationshipResource(name = "members", entityResource = GroupsEntityResource.class, title = "Group Members")
|
||||
public class GroupMembersRelation implements RelationshipResourceAction.Read<GroupMember>, RelationshipResourceAction.Create<GroupMember>, InitializingBean
|
||||
public class GroupMembersRelation
|
||||
implements RelationshipResourceAction.Read<GroupMember>, RelationshipResourceAction.Create<GroupMember>, RelationshipResourceAction.Delete, InitializingBean
|
||||
{
|
||||
private Groups groups;
|
||||
|
||||
@@ -76,4 +77,11 @@ public class GroupMembersRelation implements RelationshipResourceAction.Read<Gro
|
||||
result.add(groups.createGroupMember(groupId, entity.get(0)));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Delete group membership")
|
||||
public void delete(String entityResourceId, String id, Parameters parameters)
|
||||
{
|
||||
groups.deleteGroupMembership(entityResourceId, id);
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user