Search in sources :

Example 1 with LeaveOption

use of org.olat.group.model.LeaveOption in project OpenOLAT by OpenOLAT.

the class BusinessGroupServiceTest method allowToLeavingBusinessGroup_overrideForbidden_notAllowForAuthorsGroups_butForLearnersGroup.

/**
 * Override of allow is forbidden system-wide. If a group have the settings not "not allowed to leave",
 * the setting must be ignored for learners group but not for authors group.
 */
@Test
public void allowToLeavingBusinessGroup_overrideForbidden_notAllowForAuthorsGroups_butForLearnersGroup() {
    businessGroupModule.setAllowLeavingGroupOverride(false);
    businessGroupModule.setAllowLeavingGroupCreatedByAuthors(false);
    businessGroupModule.setAllowLeavingGroupCreatedByLearners(true);
    // authors group
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("leave-auth-4-" + UUID.randomUUID().toString());
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-4-");
    BusinessGroup authorsGroup = businessGroupService.createBusinessGroup(author, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, null);
    businessGroupRelationDao.addRole(participant, authorsGroup, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // set to not allowed to leave
    authorsGroup = businessGroupService.updateAllowToLeaveBusinessGroup(authorsGroup, false);
    dbInstance.commitAndCloseSession();
    // check the authors group leaving option
    LeaveOption optionToLeaveAuthorsGroup = businessGroupService.isAllowToLeaveBusinessGroup(participant, authorsGroup);
    Assert.assertNotNull(optionToLeaveAuthorsGroup);
    Assert.assertFalse(optionToLeaveAuthorsGroup.isAllowToLeave());
    // learners group
    Identity learner = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-learn-4-" + UUID.randomUUID().toString());
    BusinessGroup learnersGroup = businessGroupService.createBusinessGroup(learner, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, null);
    businessGroupRelationDao.addRole(participant, learnersGroup, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // set to not allowed to leave
    learnersGroup = businessGroupService.updateAllowToLeaveBusinessGroup(learnersGroup, false);
    dbInstance.commitAndCloseSession();
    // check the learners group leaving option
    LeaveOption optionToLeaveLearnersGroup = businessGroupService.isAllowToLeaveBusinessGroup(participant, learnersGroup);
    Assert.assertNotNull(optionToLeaveLearnersGroup);
    Assert.assertTrue(optionToLeaveLearnersGroup.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 2 with LeaveOption

use of org.olat.group.model.LeaveOption in project OpenOLAT by OpenOLAT.

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)

Example 3 with LeaveOption

use of org.olat.group.model.LeaveOption in project openolat by klemens.

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 4 with LeaveOption

use of org.olat.group.model.LeaveOption in project openolat by klemens.

the class BusinessGroupServiceTest method allowToLeavingBusinessGroup_overrideForbidden_notAllowForAuthorsAndLearnersGroups.

/**
 * Override of allow is forbidden system-wide. If a group have the settings not "not allowed to leave",
 * the setting must be ignored for learners group but not for authors group.
 */
@Test
public void allowToLeavingBusinessGroup_overrideForbidden_notAllowForAuthorsAndLearnersGroups() {
    businessGroupModule.setAllowLeavingGroupOverride(false);
    businessGroupModule.setAllowLeavingGroupCreatedByAuthors(false);
    businessGroupModule.setAllowLeavingGroupCreatedByLearners(false);
    // authors group
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("leave-auth-5-" + UUID.randomUUID().toString());
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-5-");
    BusinessGroup authorsGroup = businessGroupService.createBusinessGroup(author, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, null);
    businessGroupRelationDao.addRole(participant, authorsGroup, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // set to not allowed to leave
    authorsGroup = businessGroupService.updateAllowToLeaveBusinessGroup(authorsGroup, false);
    dbInstance.commitAndCloseSession();
    // check the authors group leaving option
    LeaveOption optionToLeaveAuthorsGroup = businessGroupService.isAllowToLeaveBusinessGroup(participant, authorsGroup);
    Assert.assertNotNull(optionToLeaveAuthorsGroup);
    Assert.assertFalse(optionToLeaveAuthorsGroup.isAllowToLeave());
    // learners group
    Identity learner = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-learn-5-" + UUID.randomUUID().toString());
    BusinessGroup learnersGroup = businessGroupService.createBusinessGroup(learner, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, null);
    businessGroupRelationDao.addRole(participant, learnersGroup, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // set to not allowed to leave
    learnersGroup = businessGroupService.updateAllowToLeaveBusinessGroup(learnersGroup, false);
    dbInstance.commitAndCloseSession();
    // check the learners group leaving option
    LeaveOption optionToLeaveLearnersGroup = businessGroupService.isAllowToLeaveBusinessGroup(participant, learnersGroup);
    Assert.assertNotNull(optionToLeaveLearnersGroup);
    Assert.assertFalse(optionToLeaveLearnersGroup.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 5 with LeaveOption

use of org.olat.group.model.LeaveOption in project openolat by klemens.

the class BusinessGroupServiceTest method allowToLeavingBusinessGroup_overrideForbidden_notAllowForAuthorsGroups_butForLearnersGroup.

/**
 * Override of allow is forbidden system-wide. If a group have the settings not "not allowed to leave",
 * the setting must be ignored for learners group but not for authors group.
 */
@Test
public void allowToLeavingBusinessGroup_overrideForbidden_notAllowForAuthorsGroups_butForLearnersGroup() {
    businessGroupModule.setAllowLeavingGroupOverride(false);
    businessGroupModule.setAllowLeavingGroupCreatedByAuthors(false);
    businessGroupModule.setAllowLeavingGroupCreatedByLearners(true);
    // authors group
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("leave-auth-4-" + UUID.randomUUID().toString());
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-bg-4-");
    BusinessGroup authorsGroup = businessGroupService.createBusinessGroup(author, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, null);
    businessGroupRelationDao.addRole(participant, authorsGroup, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // set to not allowed to leave
    authorsGroup = businessGroupService.updateAllowToLeaveBusinessGroup(authorsGroup, false);
    dbInstance.commitAndCloseSession();
    // check the authors group leaving option
    LeaveOption optionToLeaveAuthorsGroup = businessGroupService.isAllowToLeaveBusinessGroup(participant, authorsGroup);
    Assert.assertNotNull(optionToLeaveAuthorsGroup);
    Assert.assertFalse(optionToLeaveAuthorsGroup.isAllowToLeave());
    // learners group
    Identity learner = JunitTestHelper.createAndPersistIdentityAsRndUser("leave-learn-4-" + UUID.randomUUID().toString());
    BusinessGroup learnersGroup = businessGroupService.createBusinessGroup(learner, "Leaving group", "But you cannot leave :-(", new Integer(0), new Integer(2), false, false, null);
    businessGroupRelationDao.addRole(participant, learnersGroup, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // set to not allowed to leave
    learnersGroup = businessGroupService.updateAllowToLeaveBusinessGroup(learnersGroup, false);
    dbInstance.commitAndCloseSession();
    // check the learners group leaving option
    LeaveOption optionToLeaveLearnersGroup = businessGroupService.isAllowToLeaveBusinessGroup(participant, learnersGroup);
    Assert.assertNotNull(optionToLeaveLearnersGroup);
    Assert.assertTrue(optionToLeaveLearnersGroup.isAllowToLeave());
}
Also used : LeaveOption(org.olat.group.model.LeaveOption) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

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