diff --git a/dspace-api/src/main/java/org/dspace/content/CommunityServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/CommunityServiceImpl.java index cece560d9a..f48f7c1a36 100644 --- a/dspace-api/src/main/java/org/dspace/content/CommunityServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/CommunityServiceImpl.java @@ -452,9 +452,6 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl imp rawDelete(context, childCommunity); - childCommunity.removeParentCommunity(parentCommunity); - parentCommunity.removeSubCommunity(childCommunity); - log.info(LogManager.getHeader(context, "remove_subcommunity", "parent_comm_id=" + parentCommunity.getID() + ",child_comm_id=" + childCommunity .getID())); @@ -553,6 +550,13 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl imp // Remove any Handle handleService.unbindHandle(context, community); + // Remove the parent-child relationship for the community we want to delete + Community parent = (Community) getParentObject(context, community); + if (parent != null) { + community.removeParentCommunity(parent); + parent.removeSubCommunity(community); + } + Group g = community.getAdministrators(); // Delete community row diff --git a/dspace-api/src/test/java/org/dspace/content/ITCommunityCollection.java b/dspace-api/src/test/java/org/dspace/content/ITCommunityCollection.java index 26931d77b9..2d7271896d 100644 --- a/dspace-api/src/test/java/org/dspace/content/ITCommunityCollection.java +++ b/dspace-api/src/test/java/org/dspace/content/ITCommunityCollection.java @@ -209,6 +209,7 @@ public class ITCommunityCollection extends AbstractIntegrationTest { // Create a hierachy of sub-Communities and Collections and Items. Community child = communityService.createSubcommunity(context, parentCom); Community child2 = communityService.createSubcommunity(context, parentCom); + Community child3 = communityService.createSubcommunity(context, parentCom); Community grandchild = communityService.createSubcommunity(context, child); Collection childCol = collectionService.create(context, child); Collection grandchildCol = collectionService.create(context, grandchild); @@ -252,6 +253,13 @@ public class ITCommunityCollection extends AbstractIntegrationTest { assertThat("Community Admin unable to delete sub-Community", communityService.find(context, commId), nullValue()); + // Test deletion of single Sub-Community with own admin group + communityService.createAdministrators(context, child3); + commId = child3.getID(); + communityService.delete(context, child3); + assertThat("Community Admin unable to delete sub-Community", + communityService.find(context, commId), nullValue()); + // Test deletion of Sub-Community Hierarchy as a Community Admin commId = child.getID(); collId = childCol.getID();