diff --git a/src/core/features/courses/services/handlers/dashboard-home.ts b/src/core/features/courses/services/handlers/dashboard-home.ts index 521038dea..778b1d3d2 100644 --- a/src/core/features/courses/services/handlers/dashboard-home.ts +++ b/src/core/features/courses/services/handlers/dashboard-home.ts @@ -15,6 +15,8 @@ import { Injectable } from '@angular/core'; import { CoreBlockDelegate } from '@features/block/services/block-delegate'; import { CoreMainMenuHomeHandler, CoreMainMenuHomeHandlerToDisplay } from '@features/mainmenu/services/home-delegate'; +import { CoreSites } from '@services/sites'; +import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { CoreCoursesDashboard } from '../dashboard'; @@ -45,40 +47,25 @@ export class CoreDashboardHomeHandlerService implements CoreMainMenuHomeHandler * @return Whether or not the handler is enabled on a site level. */ async isEnabledForSite(siteId?: string): Promise { - const promises: Promise[] = []; - let blocksEnabled = false; - let dashboardAvailable = false; - let dashboardEnabled = false; + const site = await CoreSites.getSite(siteId); // Check if blocks and 3.6 dashboard is enabled. - promises.push(CoreBlockDelegate.areBlocksDisabled(siteId).then((disabled) => { - blocksEnabled = !disabled; + const [blocksDisabled, dashboardDisabled, dashboardAvailable, dashboardConfig] = await Promise.all([ + CoreBlockDelegate.areBlocksDisabled(site.getId()), + CoreCoursesDashboard.isDisabled(site.getId()), + CoreCoursesDashboard.isAvailable(site.getId()), + CoreUtils.ignoreErrors(site.getConfig('enabledashboard'), '1'), + ]); + const dashboardEnabled = !dashboardDisabled && dashboardConfig !== '0'; - return; - })); - - promises.push(CoreCoursesDashboard.isDisabled(siteId).then((disabled) => { - dashboardEnabled = !disabled; - - return; - })); - - promises.push(CoreCoursesDashboard.isAvailable(siteId).then((available) => { - dashboardAvailable = available; - - return; - })); - - await Promise.all(promises); - - if (dashboardAvailable && dashboardEnabled && blocksEnabled) { + if (dashboardAvailable && dashboardEnabled && !blocksDisabled) { const blocks = await CoreCoursesDashboard.getDashboardBlocks(undefined, siteId); return CoreBlockDelegate.hasSupportedBlock(blocks.mainBlocks) || CoreBlockDelegate.hasSupportedBlock(blocks.sideBlocks); } // Dashboard is enabled but not available, we will fake blocks. - return dashboardEnabled && blocksEnabled; + return dashboardEnabled && !blocksDisabled; } /**