REPO-1305: Delete a group

- first version

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@134676 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Cristian Turlica
2017-01-20 13:46:59 +00:00
parent debae96be4
commit 688a068f2a
6 changed files with 165 additions and 10 deletions

View File

@@ -43,6 +43,7 @@ public interface Groups
String PARAM_INCLUDE_PARENT_IDS = "parentIds";
String PARAM_INCLUDE_ZONES = "zones";
String PARAM_IS_ROOT = "isRoot";
String PARAM_CASCADE = "cascade";
String PARAM_MEMBER_TYPE = "memberType";
String PARAM_MEMBER_TYPE_GROUP = "GROUP";
String PARAM_MEMBER_TYPE_PERSON = "PERSON";
@@ -107,6 +108,18 @@ public interface Groups
*/
CollectionWithPagingInfo<Group> getGroupsByPersonId(String personId, Parameters parameters);
/**
* Delete the given group.
*
* @param groupId
* the group ID
* @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);
/**
* Gets a list of groups.
*

View File

@@ -47,8 +47,8 @@ import java.util.List;
* @author cturlica
*/
@EntityResource(name = "groups", title = "Groups")
public class GroupsEntityResource
implements EntityResourceAction.Read<Group>, EntityResourceAction.ReadById<Group>, EntityResourceAction.Create<Group>, EntityResourceAction.Update<Group>, InitializingBean
public class GroupsEntityResource implements EntityResourceAction.Read<Group>, EntityResourceAction.ReadById<Group>, EntityResourceAction.Create<Group>,
EntityResourceAction.Update<Group>, EntityResourceAction.Delete, InitializingBean
{
private Groups groups;
@@ -94,4 +94,11 @@ public class GroupsEntityResource
{
return groups.update(groupId, group, parameters);
}
@Override
@WebApiDescription(title = "Delete group", description = "Delete group")
public void delete(String groupId, Parameters parameters)
{
groups.delete(groupId, parameters);
}
}

View File

@@ -30,6 +30,7 @@ import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.security.authority.AuthorityDAO;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authority.AuthorityException;
import org.alfresco.repo.security.authority.AuthorityInfo;
import org.alfresco.repo.security.authority.UnknownAuthorityException;
import org.alfresco.rest.antlr.WhereClauseParser;
@@ -138,7 +139,7 @@ public class GroupsImpl implements Groups
public Group update(String groupId, Group group, Parameters parameters)
{
validateGroupId(groupId);
validateGroupId(groupId, false);
validateGroup(group, true);
authorityService.setAuthorityDisplayName(groupId, group.getDisplayName());
@@ -525,9 +526,31 @@ public class GroupsImpl implements Groups
}
}
public void delete(String groupId, Parameters parameters)
{
// Get cascade param - default false (if not provided).
boolean cascade = Boolean.valueOf(parameters.getParameter(PARAM_CASCADE));
try
{
authorityService.deleteAuthority(groupId, cascade);
}
catch (AuthorityException ae)
{
if (ae.getMsgId().equals("Trying to modify a fixed authority"))
{
throw new ConstraintViolatedException("Trying to modify a fixed authority");
}
else
{
throw ae;
}
}
}
public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters)
{
validateGroupId(groupId);
validateGroupId(groupId, false);
Paging paging = parameters.getPaging();
@@ -646,14 +669,14 @@ public class GroupsImpl implements Groups
return groupMember;
}
private void validateGroupId(String groupId)
private void validateGroupId(String groupId, boolean inferPrefix)
{
if (groupId == null || groupId.isEmpty())
{
throw new InvalidArgumentException("groupId is null or empty");
}
if (!groupAuthorityExists(groupId))
if (!groupAuthorityExists(groupId, inferPrefix))
{
throw new EntityNotFoundException(groupId);
}
@@ -702,14 +725,19 @@ public class GroupsImpl implements Groups
}
}
private boolean groupAuthorityExists(String shortName)
private boolean groupAuthorityExists(String authorityName)
{
return authorityExists(AuthorityType.GROUP, shortName);
return groupAuthorityExists(authorityName, true);
}
private boolean authorityExists(AuthorityType authorityType, String shortName)
private boolean groupAuthorityExists(String authorityName, boolean inferPrefix)
{
String name = authorityService.getName(authorityType, shortName);
return authorityExists(AuthorityType.GROUP, authorityName, inferPrefix);
}
private boolean authorityExists(AuthorityType authorityType, String authorityName, boolean inferPrefix)
{
String name = inferPrefix ? authorityService.getName(authorityType, authorityName) : authorityName;
return (name != null && authorityService.authorityExists(name));
}