diff --git a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java index d66116f439701edfc8748453f3c4759bf842a5b8..3b03e64f7eba20b49a5cadf53e7cabb8f6eeb789 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupServiceImpl.java @@ -1092,7 +1092,7 @@ public class BusinessGroupServiceImpl implements BusinessGroupService { if(coaches.isEmpty()) { Collection<BusinessGroup> groups = Collections.singletonList(group); List<RepositoryEntry> entries = businessGroupRelationDAO.findRepositoryEntries(groups, 0, -1); - coaches.addAll(repositoryService.getMembers(entries, RepositoryEntryRelationType.all, GroupRoles.coach.name())); + coaches.addAll(repositoryService.getMembers(entries, RepositoryEntryRelationType.defaultGroup, GroupRoles.coach.name())); if(coaches.isEmpty()) { //get system administrators of the user's organisations diff --git a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java index 0a5f25e3dc3b727066cd0ebc0590d67f9fb18113..02dcf542b71f886c9ce71af10d79c47607cebd92 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java @@ -65,6 +65,7 @@ import org.olat.group.model.LeaveOption; import org.olat.group.model.MembershipModification; import org.olat.group.model.SearchBusinessGroupParams; import org.olat.repository.RepositoryEntry; +import org.olat.repository.manager.RepositoryEntryRelationDAO; import org.olat.resource.accesscontrol.ACService; import org.olat.resource.accesscontrol.ResourceReservation; import org.olat.resource.accesscontrol.manager.ACReservationDAO; @@ -92,12 +93,14 @@ public class BusinessGroupServiceTest extends OlatTestCase { @Autowired private UserManager userManager; @Autowired - private ACReservationDAO reservationDao; - @Autowired private BaseSecurity securityManager; @Autowired + private ACReservationDAO reservationDao; + @Autowired private BusinessGroupRelationDAO businessGroupRelationDao; @Autowired + private RepositoryEntryRelationDAO repositoryEntryRelationDao; + @Autowired private BusinessGroupModule businessGroupModule; @Autowired private BusinessGroupService businessGroupService; @@ -1153,6 +1156,38 @@ public class BusinessGroupServiceTest extends OlatTestCase { } } + @Test + public void allowToLeavingBusinessGroup_withCourse_andGroups() { + //authors group + RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry(); + Identity coachCourse = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-8-"); + Identity coachGroup = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-8-"); + Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-8-"); + BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "Leaving group 8a", "But you cannot leave :-(", Integer.valueOf(0), Integer.valueOf(2), false, false, resource); + BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "Leaving group 8b", "But you cannot leave :-(", Integer.valueOf(0), Integer.valueOf(2), false, false, resource); + repositoryEntryRelationDao.addRole(coachCourse, resource, GroupRoles.coach.name()); + businessGroupRelationDao.addRole(coachGroup, group2, GroupRoles.coach.name()); + businessGroupRelationDao.addRole(participant, group1, GroupRoles.participant.name()); + + dbInstance.commitAndCloseSession(); + + //set to not allowed to leave + group1 = businessGroupService.updateAllowToLeaveBusinessGroup(group1, false); + dbInstance.commitAndCloseSession(); + + //check the authors group leaving option + LeaveOption optionToLeave = businessGroupService.isAllowToLeaveBusinessGroup(participant, group1); + Assert.assertNotNull(optionToLeave); + Assert.assertFalse(optionToLeave.isAllowToLeave()); + ContactList contacts = optionToLeave.getContacts(); + Collection<Identity> contactList = contacts.getIdentiEmails().values(); + Assert.assertNotNull(contactList); + Assert.assertFalse(contactList.isEmpty()); + Assert.assertEquals(1, contactList.size()); + Assert.assertTrue(contactList.contains(coachCourse)); + Assert.assertFalse(contactList.contains(coachGroup));// coach of other group doesn't receive an email + } + @Test public void allowToLeavingBusinessGroup_subOrganisation() { // a special