diff --git a/src/main/java/org/olat/course/nodes/ENCourseNode.java b/src/main/java/org/olat/course/nodes/ENCourseNode.java index c51cafd4554e1387a43b0d30421887a07436bfb8..147a3d61042f7a98b3d7f1039f252e20496d9124 100644 --- a/src/main/java/org/olat/course/nodes/ENCourseNode.java +++ b/src/main/java/org/olat/course/nodes/ENCourseNode.java @@ -41,6 +41,7 @@ import org.olat.core.gui.control.generic.tabbable.TabbableController; import org.olat.core.gui.translator.PackageTranslator; import org.olat.core.gui.translator.Translator; import org.olat.core.id.Roles; +import org.olat.core.util.StringHelper; import org.olat.core.util.Util; import org.olat.core.util.filter.FilterFactory; import org.olat.course.ICourse; @@ -56,12 +57,14 @@ import org.olat.course.properties.PersistingCoursePropertyManager; import org.olat.course.run.navigation.NodeRunConstructionResult; import org.olat.course.run.userview.NodeEvaluation; import org.olat.course.run.userview.UserCourseEnvironment; +import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; import org.olat.group.BusinessGroupShort; import org.olat.group.area.BGArea; import org.olat.group.area.BGAreaManager; import org.olat.modules.ModuleConfiguration; import org.olat.repository.RepositoryEntry; +import org.olat.resource.OLATResource; /** * Description:<BR> @@ -160,6 +163,46 @@ public class ENCourseNode extends AbstractAccessableCourseNode { Controller ctrl = TitledWrapperHelper.getWrapper(ureq, wControl, controller, this, "o_en_icon"); return new NodeRunConstructionResult(ctrl); } + + public boolean isUsedForEnrollment(List<BusinessGroup> groups, OLATResource courseResource) { + if(groups == null || groups.isEmpty()) return false; + + ModuleConfiguration mc = getModuleConfiguration(); + String groupNames = (String) mc.get(CONFIG_GROUPNAME); + List<Long> groupKeys = mc.getList(ENCourseNode.CONFIG_GROUP_IDS, Long.class); + if(groupKeys != null && groupKeys.size() > 0) { + for(BusinessGroup group:groups) { + if(groupKeys.contains(group.getKey())) { + return true; + } + } + } else if(StringHelper.containsNonWhitespace(groupNames)) { + String[] groupNameArr = groupNames.split(","); + for(BusinessGroup group:groups) { + for(String groupName:groupNameArr) { + if(groupName != null && group.getName() != null && groupName.equals(group.getName())) { + return true; + } + } + } + } + + List<Long> areaKeys = mc.getList(ENCourseNode.CONFIG_AREA_IDS, Long.class); + if(areaKeys == null || areaKeys.isEmpty()) { + String areaNames = (String) mc.get(CONFIG_AREANAME); + areaKeys = CoreSpringFactory.getImpl(BGAreaManager.class).toAreaKeys(areaNames, courseResource); + } + if(areaKeys != null && areaKeys.size() > 0) { + List<Long> areaGroupKeys = CoreSpringFactory.getImpl(BGAreaManager.class).findBusinessGroupKeysOfAreaKeys(areaKeys); + for(BusinessGroup group:groups) { + if(areaGroupKeys.contains(group.getKey())) { + return true; + } + } + } + + return false; + } /** * @see org.olat.course.nodes.CourseNode#isConfigValid() diff --git a/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java b/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java index 9ed3db87ca0aa1a658b0bec75109f4379fda9ba4..51d8252224ac4ac403a8b64db9e278f500a361a7 100644 --- a/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java +++ b/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java @@ -238,7 +238,8 @@ public class EnrollmentManager extends BasicManager { } return groups; } - protected List<Long> getBusinessGroupKeys(List<Long> groupKeys, List<Long> areaKeys) { + + public List<Long> getBusinessGroupKeys(List<Long> groupKeys, List<Long> areaKeys) { List<Long> allKeys = new ArrayList<>(); if(groupKeys != null && !groupKeys.isEmpty()) { allKeys.addAll(groupKeys); diff --git a/src/main/java/org/olat/course/run/CourseRuntimeController.java b/src/main/java/org/olat/course/run/CourseRuntimeController.java index fe15cafdf387df12f16785eb920c1ccafe4002d5..20fe12dc4dabd74adc9c7645b9ce687e6966e0ee 100644 --- a/src/main/java/org/olat/course/run/CourseRuntimeController.java +++ b/src/main/java/org/olat/course/run/CourseRuntimeController.java @@ -22,6 +22,7 @@ package org.olat.course.run; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.olat.NewControllerFactory; @@ -101,6 +102,7 @@ import org.olat.course.groupsandrights.CourseGroupManager; import org.olat.course.groupsandrights.CourseRights; import org.olat.course.member.MembersManagementMainController; import org.olat.course.nodes.CourseNode; +import org.olat.course.nodes.ENCourseNode; import org.olat.course.reminder.ui.CourseRemindersController; import org.olat.course.run.calendar.CourseCalendarController; import org.olat.course.run.glossary.CourseGlossaryFactory; @@ -128,6 +130,7 @@ import org.olat.repository.controllers.EntryChangedEvent; import org.olat.repository.model.RepositoryEntrySecurity; import org.olat.repository.ui.RepositoryEntryLifeCycleChangeController; import org.olat.repository.ui.RepositoryEntryRuntimeController; +import org.olat.resource.OLATResource; import org.olat.util.logging.activity.LoggingResourceable; import org.springframework.beans.factory.annotation.Autowired; @@ -654,7 +657,7 @@ public class CourseRuntimeController extends RepositoryEntryRuntimeController im if(repositoryService.isParticipantAllowedToLeave(getRepositoryEntry()) && !assessmentLock && !roles.isGuestOnly() - && (uce.isParticipant() || !uce.getParticipatingGroups().isEmpty())) { + && isAllowedToLeave(uce)) { leaveLink = LinkFactory.createToolLink("sign.out", "leave", translate("sign.out"), this); leaveLink.setIconLeftCSS("o_icon o_icon-fw o_icon_sign_out"); myCourse.addComponent(new Spacer("leaving-space")); @@ -666,6 +669,36 @@ public class CourseRuntimeController extends RepositoryEntryRuntimeController im } } + private boolean isAllowedToLeave(UserCourseEnvironmentImpl uce) { + if(uce.getParticipatingGroups().size() > 0) { + CourseNode rootNode = uce.getCourseEnvironment().getRunStructure().getRootNode(); + OLATResource courseResource = uce.getCourseEnvironment().getCourseGroupManager().getCourseResource(); + + AtomicBoolean bool = new AtomicBoolean(false); + new TreeVisitor(new Visitor() { + @Override + public void visit(INode node) { + if(!bool.get() && node instanceof ENCourseNode) { + try { + ENCourseNode enNode = (ENCourseNode)node; + boolean cancelEnrollEnabled = enNode.getModuleConfiguration().getBooleanSafe(ENCourseNode.CONF_CANCEL_ENROLL_ENABLED); + if(!cancelEnrollEnabled && enNode.isUsedForEnrollment(uce.getParticipatingGroups(), courseResource)) { + bool.set(true); + } + } catch (Exception e) { + logError("", e); + } + } + } + }, rootNode, true).visitAll(); + + if(bool.get()) { + return false;// is in a enrollment group + } + } + return (uce.isParticipant() || !uce.getParticipatingGroups().isEmpty()); + } + private void initGeneralTools(ICourse course) { boolean assessmentLock = isAssessmentLock();