use of org.olat.group.model.LeaveOption in project OpenOLAT by OpenOLAT.
the class BusinessGroupServiceTest method allowToLeavingBusinessGroup_defaultSettings.
/**
* Test the default settings. Participants are allowed to leave business groups.
*/
@Test
public void allowToLeavingBusinessGroup_defaultSettings() {
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("leave-auth-1-" + UUID.randomUUID().toString());
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-1-");
BusinessGroup group = businessGroupService.createBusinessGroup(author, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, null);
businessGroupRelationDao.addRole(participant, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
LeaveOption optionToLeave = businessGroupService.isAllowToLeaveBusinessGroup(participant, group);
Assert.assertNotNull(optionToLeave);
Assert.assertTrue(optionToLeave.isAllowToLeave());
}
use of org.olat.group.model.LeaveOption in project openolat by klemens.
the class BusinessGroupServiceTest method allowToLeavingBusinessGroup_defaultSettings_groupOverride.
/**
* Test the default settings but the author set the business group to "leaving not allowed".
*/
@Test
public void allowToLeavingBusinessGroup_defaultSettings_groupOverride() {
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("leave-auth-2-" + UUID.randomUUID().toString());
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-2-");
BusinessGroup group = businessGroupService.createBusinessGroup(author, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, null);
businessGroupRelationDao.addRole(participant, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// set to not allowed to leave
group = businessGroupService.updateAllowToLeaveBusinessGroup(group, false);
dbInstance.commitAndCloseSession();
LeaveOption optionToLeave = businessGroupService.isAllowToLeaveBusinessGroup(participant, group);
Assert.assertNotNull(optionToLeave);
Assert.assertFalse(optionToLeave.isAllowToLeave());
ContactList contacts = optionToLeave.getContacts();
Assert.assertNotNull(contacts);
Collection<Identity> contactList = contacts.getIdentiEmails().values();
Assert.assertNotNull(contactList);
Assert.assertEquals(1, contactList.size());
Assert.assertTrue(contactList.contains(author));
}
use of org.olat.group.model.LeaveOption in project openolat by klemens.
the class BusinessGroupServiceTest method allowToLeavingBusinessGroup_overrideForbidden.
/**
* Override of allow is forbidden system-wide. If a group have the settings not "not allowed to leave",
* the setting must be ignored and the participants allowed to leave the group.
*/
@Test
public void allowToLeavingBusinessGroup_overrideForbidden() {
businessGroupModule.setAllowLeavingGroupOverride(false);
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("leave-auth-3-" + UUID.randomUUID().toString());
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-3-");
BusinessGroup group = businessGroupService.createBusinessGroup(author, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, null);
businessGroupRelationDao.addRole(participant, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// set to not allowed to leave
group = businessGroupService.updateAllowToLeaveBusinessGroup(group, false);
dbInstance.commitAndCloseSession();
LeaveOption optionToLeave = businessGroupService.isAllowToLeaveBusinessGroup(participant, group);
Assert.assertNotNull(optionToLeave);
Assert.assertTrue(optionToLeave.isAllowToLeave());
}
use of org.olat.group.model.LeaveOption in project openolat by klemens.
the class BusinessGroupServiceImpl method isAllowToLeaveBusinessGroup.
@Override
public LeaveOption isAllowToLeaveBusinessGroup(Identity identity, BusinessGroup group) {
LeaveOption opt;
if (groupModule.isAllowLeavingGroupOverride()) {
if (group.isAllowToLeave()) {
opt = new LeaveOption();
} else {
ContactList list = getAdminContactList(group);
opt = new LeaveOption(false, list);
}
} else if (groupModule.isAllowLeavingGroupCreatedByAuthors() && groupModule.isAllowLeavingGroupCreatedByLearners()) {
opt = new LeaveOption();
} else if (!groupModule.isAllowLeavingGroupCreatedByAuthors() && !groupModule.isAllowLeavingGroupCreatedByLearners()) {
ContactList list = getAdminContactList(group);
opt = new LeaveOption(false, list);
} else {
int numOfCoaches = countMembers(group, GroupRoles.coach.name());
if (numOfCoaches == 0) {
int numOfResources = businessGroupRelationDAO.countResources(group);
if (numOfResources > 0) {
// author group
if (groupModule.isAllowLeavingGroupCreatedByAuthors()) {
opt = new LeaveOption();
} else {
ContactList list = getAdminContactList(group);
opt = new LeaveOption(false, list);
}
// learner group
} else if (groupModule.isAllowLeavingGroupCreatedByLearners()) {
opt = new LeaveOption();
} else {
ContactList list = getAdminContactList(group);
opt = new LeaveOption(false, list);
}
} else {
int numOfAuthors = businessGroupRelationDAO.countAuthors(group);
if (numOfAuthors > 0) {
if (groupModule.isAllowLeavingGroupCreatedByAuthors()) {
opt = new LeaveOption();
} else {
ContactList list = getAdminContactList(group);
opt = new LeaveOption(false, list);
}
} else if (groupModule.isAllowLeavingGroupCreatedByLearners()) {
opt = new LeaveOption();
} else {
ContactList list = getAdminContactList(group);
opt = new LeaveOption(false, list);
}
}
}
return opt;
}
Aggregations