Search in sources :

Example 11 with LeaveOption

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());
}
Also used : LeaveOption(org.olat.group.model.LeaveOption) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 12 with LeaveOption

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));
}
Also used : LeaveOption(org.olat.group.model.LeaveOption) BusinessGroup(org.olat.group.BusinessGroup) ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 13 with LeaveOption

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());
}
Also used : LeaveOption(org.olat.group.model.LeaveOption) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 14 with LeaveOption

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;
}
Also used : LeaveOption(org.olat.group.model.LeaveOption) ContactList(org.olat.core.util.mail.ContactList)

Aggregations

LeaveOption (org.olat.group.model.LeaveOption)14 Test (org.junit.Test)12 Identity (org.olat.core.id.Identity)12 BusinessGroup (org.olat.group.BusinessGroup)12 ContactList (org.olat.core.util.mail.ContactList)6 GroupRoles (org.olat.basesecurity.GroupRoles)2 Roles (org.olat.core.id.Roles)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2