diff --git a/src/addons/mod/lti/services/lti-helper.ts b/src/addons/mod/lti/services/lti-helper.ts index 3f11b180f..905252c24 100644 --- a/src/addons/mod/lti/services/lti-helper.ts +++ b/src/addons/mod/lti/services/lti-helper.ts @@ -61,7 +61,7 @@ export class AddonModLtiHelperProvider { const modal = await CoreDomUtils.showModalLoading(); try { - const openInBrowser = await AddonModLti.isOpenInAppBrowserDisabled(siteId); + const openInBrowser = await AddonModLti.shouldLaunchInBrowser(siteId); if (openInBrowser) { const site = await CoreSites.getSite(siteId); diff --git a/src/addons/mod/lti/services/lti.ts b/src/addons/mod/lti/services/lti.ts index de9409d71..44e2d7604 100644 --- a/src/addons/mod/lti/services/lti.ts +++ b/src/addons/mod/lti/services/lti.ts @@ -184,8 +184,35 @@ export class AddonModLtiProvider { await site.invalidateWsCacheForKey(this.getLtiLaunchDataCacheKey(id)); } + /** + * Check if open LTI in browser via site with auto-login is disabled. + * This setting was added in 3.11. + * + * @param siteId Site ID. If not defined, current site. + * @return Promise resolved with boolean: whether it's disabled. + */ + async isLaunchViaSiteDisabled(siteId?: string): Promise { + const site = await CoreSites.getSite(siteId); + + return this.isLaunchViaSiteDisabledInSite(site); + } + + /** + * Check if open LTI in browser via site with auto-login is disabled. + * This setting was added in 3.11. + * + * @param site Site. If not defined, current site. + * @return Whether it's disabled. + */ + isLaunchViaSiteDisabledInSite(site?: CoreSite): boolean { + site = site || CoreSites.getCurrentSite(); + + return !!site?.isFeatureDisabled('CoreCourseModuleDelegate_AddonModLti:launchViaSite'); + } + /** * Check if open in InAppBrowser is disabled. + * This setting was removed in Moodle 3.11 because the default behaviour of the app changed. * * @param siteId Site ID. If not defined, current site. * @return Promise resolved with boolean: whether it's disabled. @@ -198,6 +225,7 @@ export class AddonModLtiProvider { /** * Check if open in InAppBrowser is disabled. + * This setting was removed in Moodle 3.11 because the default behaviour of the app changed. * * @param site Site. If not defined, current site. * @return Whether it's disabled. @@ -239,7 +267,7 @@ export class AddonModLtiProvider { * @param siteId Site ID. If not defined, current site. * @return Promise resolved when the WS call is successful. */ - logView(id: number, name?: string, siteId?: string): Promise { + logView(id: number, name?: string, siteId?: string): Promise { const params: AddonModLtiViewLtiWSParams = { ltiid: id, }; @@ -256,6 +284,24 @@ export class AddonModLtiProvider { ); } + /** + * Check whether the LTI should be launched in browser via the site with auto-login. + * + * @param siteId Site ID. + * @return Promise resolved with boolean. + */ + async shouldLaunchInBrowser(siteId?: string): Promise { + const site = await CoreSites.getSite(siteId); + + if (site.isVersionGreaterEqualThan('3.11')) { + // In 3.11+, launch in browser by default unless it's disabled. + return !this.isLaunchViaSiteDisabledInSite(site); + } else { + // In old sites the default behaviour is to launch in InAppBrowser. + return this.isOpenInAppBrowserDisabledInSite(site); + } + } + } export const AddonModLti = makeSingleton(AddonModLtiProvider); diff --git a/src/core/classes/site.ts b/src/core/classes/site.ts index 64effc43c..549ac2dcf 100644 --- a/src/core/classes/site.ts +++ b/src/core/classes/site.ts @@ -79,6 +79,7 @@ export class CoreSite { '3.8': 2019111800, '3.9': 2020061500, '3.10': 2020110900, + '3.11': 2021051000, // @todo: Replace with the right version once it's released. }; // Possible cache update frequencies.