Skip to content

Commit

Permalink
Fix bug in logic for determining whether a workflow group will be lef…
Browse files Browse the repository at this point in the history
…t empty. Need to check *both* EPerson and subgroup counts.
  • Loading branch information
tdonohue committed Oct 3, 2023
1 parent 279318a commit fe509ac
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,13 @@ public void removeMember(Context context, Group group, EPerson ePerson) throws S
for (CollectionRole collectionRole : collectionRoles) {
if (StringUtils.equals(collectionRole.getRoleId(), role.getId())
&& claimedTask.getWorkflowItem().getCollection() == collectionRole.getCollection()) {
// Get total number of unique EPerson objs who are a member of this group (or subgroup)
int totalMembers = countAllMembers(context, group);
// If only one EPerson is a member, then we cannot delete the last member of this group.
if (totalMembers == 1) {
// Count number of EPersons who are *direct* members of this group
int totalDirectEPersons = ePersonService.countByGroups(context, Set.of(group));
// Count number of Groups which have this groupParent as a direct parent
int totalChildGroups = countByParent(context, group);
// If this group has only one direct EPerson and *zero* child groups, then we cannot delete the
// EPerson or we will leave this group empty.
if (totalDirectEPersons == 1 && totalChildGroups == 0) {
throw new IllegalStateException(
"Refused to remove user " + ePerson
.getID() + " from workflow group because the group " + group
Expand All @@ -193,10 +196,13 @@ public void removeMember(Context context, Group group, EPerson ePerson) throws S
}
}
if (!poolTasks.isEmpty()) {
// Get total number of unique EPerson objs who are a member of this group (or subgroup)
int totalMembers = countAllMembers(context, group);
// If only one EPerson is a member, then we cannot delete the last member of this group.
if (totalMembers == 1) {
// Count number of EPersons who are *direct* members of this group
int totalDirectEPersons = ePersonService.countByGroups(context, Set.of(group));
// Count number of Groups which have this groupParent as a direct parent
int totalChildGroups = countByParent(context, group);
// If this group has only one direct EPerson and *zero* child groups, then we cannot delete the
// EPerson or we will leave this group empty.
if (totalDirectEPersons == 1 && totalChildGroups == 0) {
throw new IllegalStateException(
"Refused to remove user " + ePerson
.getID() + " from workflow group because the group " + group
Expand All @@ -217,9 +223,12 @@ public void removeMember(Context context, Group groupParent, Group childGroup) t
List<PoolTask> poolTasks = poolTaskService.findByGroup(context, groupParent);
if (!poolTasks.isEmpty()) {
// Count number of Groups which have this groupParent as a direct parent
int totalChildren = countByParent(context, groupParent);
// If only one group has this as a parent, we cannot delete the last child group
if (totalChildren == 1) {
int totalChildGroups = countByParent(context, groupParent);

Check warning on line 226 in dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java#L226

Added line #L226 was not covered by tests
// Count number of EPersons who are *direct* members of this group
int totalDirectEPersons = ePersonService.countByGroups(context, Set.of(groupParent));

Check warning on line 228 in dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

dspace-api/src/main/java/org/dspace/eperson/GroupServiceImpl.java#L228

Added line #L228 was not covered by tests
// If this group has only one childGroup and *zero* direct EPersons, then we cannot delete the
// childGroup or we will leave this group empty.
if (totalChildGroups == 1 && totalDirectEPersons == 0) {
throw new IllegalStateException(
"Refused to remove sub group " + childGroup
.getID() + " from workflow group because the group " + groupParent
Expand Down

0 comments on commit fe509ac

Please sign in to comment.