diff --git a/src/main/java/org/olat/repository/CatalogContextEntryControllerCreator.java b/src/main/java/org/olat/repository/CatalogContextEntryControllerCreator.java index ec7c4cf4b714a2d8684f3ad841714effe3546eee..fb2a9462062bb06489f944d980dd983176dd70b4 100644 --- a/src/main/java/org/olat/repository/CatalogContextEntryControllerCreator.java +++ b/src/main/java/org/olat/repository/CatalogContextEntryControllerCreator.java @@ -20,15 +20,26 @@ package org.olat.repository; +import java.util.ArrayList; import java.util.List; +import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.navigation.SiteConfiguration; +import org.olat.core.gui.control.navigation.SiteDefinitions; +import org.olat.core.gui.control.navigation.SiteSecurityCallback; +import org.olat.core.id.OLATResourceable; import org.olat.core.id.context.ContextEntry; import org.olat.core.id.context.ContextEntryControllerCreator; import org.olat.core.id.context.DefaultContextEntryControllerCreator; +import org.olat.core.id.context.TabContext; +import org.olat.core.logging.OLog; +import org.olat.core.logging.Tracing; +import org.olat.core.util.StringHelper; import org.olat.repository.site.CatalogSite; -import org.olat.repository.site.RepositorySite; +import org.olat.repository.site.CatalogSiteDef; +import org.olat.repository.site.MyCoursesSite; /** * Description:<br> @@ -39,6 +50,8 @@ import org.olat.repository.site.RepositorySite; */ public class CatalogContextEntryControllerCreator extends DefaultContextEntryControllerCreator { + private static final OLog log = Tracing.createLoggerFor(CatalogContextEntryControllerCreator.class); + private final RepositoryModule repositoryModule; public CatalogContextEntryControllerCreator(RepositoryModule repositoryModule) { @@ -52,10 +65,32 @@ public class CatalogContextEntryControllerCreator extends DefaultContextEntryCon @Override public String getSiteClassName(List<ContextEntry> ces, UserRequest ureq) { - if(repositoryModule.isCatalogSiteEnabled()) { + if(isCatalogSiteVisible(ureq)) { return CatalogSite.class.getName(); } else { - return RepositorySite.class.getName(); + return MyCoursesSite.class.getName(); + } + } + + private boolean isCatalogSiteVisible(UserRequest ureq) { + if(repositoryModule.isCatalogEnabled() && repositoryModule.isCatalogSiteEnabled()) { + try { + CatalogSiteDef siteDef = CoreSpringFactory.getImpl(CatalogSiteDef.class); + SiteDefinitions siteDefinitions = CoreSpringFactory.getImpl(SiteDefinitions.class); + SiteConfiguration config = siteDefinitions.getConfigurationSite(siteDef); + if(config != null && StringHelper.containsNonWhitespace(config.getSecurityCallbackBeanId())) { + String secCallbackBeanId = config.getSecurityCallbackBeanId(); + Object siteSecCallback = CoreSpringFactory.getBean(secCallbackBeanId); + if (siteSecCallback instanceof SiteSecurityCallback && !((SiteSecurityCallback)siteSecCallback).isAllowedToLaunchSite(ureq)) { + return false; + } + } + } catch (Exception e) { + log.error("Cannot find if the user is allowed to launch the catalog.", e); + } + return true; + } else { + return false; } } @@ -63,4 +98,17 @@ public class CatalogContextEntryControllerCreator extends DefaultContextEntryCon public boolean validateContextEntryAndShowError(ContextEntry ce, UserRequest ureq, WindowControl wControl) { return repositoryModule.isCatalogEnabled(); } + + @Override + public TabContext getTabContext(UserRequest ureq, OLATResourceable ores, ContextEntry mainEntry, List<ContextEntry> entries) { + //My courses need the catalog entry + List<ContextEntry> redirectEntries = new ArrayList<>(); + if(entries == null || entries.isEmpty() || !entries.get(0).equals(mainEntry)) { + redirectEntries.add(mainEntry); + } + if(entries != null && entries.size() > 0) { + redirectEntries.addAll(entries); + } + return new TabContext(getTabName(mainEntry, ureq), ores, redirectEntries); + } } \ No newline at end of file