MOBILE-3819 core: Remove local_mobile support

main
Dani Palou 2021-09-03 13:33:03 +02:00
parent 68e57c0f17
commit 705f7ce92d
12 changed files with 87 additions and 287 deletions

View File

@ -62,7 +62,6 @@
"zh-tw": "正體中文" "zh-tw": "正體中文"
}, },
"wsservice": "moodle_mobile_app", "wsservice": "moodle_mobile_app",
"wsextservice": "local_mobile",
"demo_sites": { "demo_sites": {
"student": { "student": {
"url": "https:\/\/school.moodledemo.net", "url": "https:\/\/school.moodledemo.net",

View File

@ -1851,7 +1851,6 @@
"core.login.invalidurl": "scorm", "core.login.invalidurl": "scorm",
"core.login.invalidvaluemax": "local_moodlemobileapp", "core.login.invalidvaluemax": "local_moodlemobileapp",
"core.login.invalidvaluemin": "local_moodlemobileapp", "core.login.invalidvaluemin": "local_moodlemobileapp",
"core.login.localmobileunexpectedresponse": "local_moodlemobileapp",
"core.login.loggedoutssodescription": "local_moodlemobileapp", "core.login.loggedoutssodescription": "local_moodlemobileapp",
"core.login.login": "moodle", "core.login.login": "moodle",
"core.login.loginbutton": "local_moodlemobileapp", "core.login.loginbutton": "local_moodlemobileapp",

View File

@ -485,9 +485,6 @@ export class CoreSite {
* *
* Caching is also implemented, when enabled this method will returned a cached version of the request if the * Caching is also implemented, when enabled this method will returned a cached version of the request if the
* data hasn't expired. * data hasn't expired.
*
* This method is smart which means that it will try to map the method to a compatibility one if need be, usually this
* means that it will fallback on the 'local_mobile_' prefixed function if it is available and the non-prefixed is not.
*/ */
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
async request<T = unknown>(method: string, data: any, preSets: CoreSiteWSPreSets, retrying?: boolean): Promise<T> { async request<T = unknown>(method: string, data: any, preSets: CoreSiteWSPreSets, retrying?: boolean): Promise<T> {
@ -505,18 +502,12 @@ export class CoreSite {
throw new CoreError(Translate.instant('core.errorofflinedisabled')); throw new CoreError(Translate.instant('core.errorofflinedisabled'));
} }
// Check if the method is available, use a prefixed version if possible. // Check if the method is available.
// We ignore this check when we do not have the site info, as the list of functions is not loaded yet. // We ignore this check when we do not have the site info, as the list of functions is not loaded yet.
if (this.getInfo() && !this.wsAvailable(method, false)) { if (this.getInfo() && !this.wsAvailable(method)) {
const compatibilityMethod = CoreConstants.WS_PREFIX + method; this.logger.error(`WS function '${method}' is not available.`);
if (this.wsAvailable(compatibilityMethod, false)) {
this.logger.info(`Using compatibility WS method '${compatibilityMethod}'`);
method = compatibilityMethod;
} else {
this.logger.error(`WS function '${method}' is not available, even in compatibility mode.`);
throw new CoreError(Translate.instant('core.wsfunctionnotavailable')); throw new CoreError(Translate.instant('core.wsfunctionnotavailable'));
}
} }
const wsPreSets: CoreWSPreSets = { const wsPreSets: CoreWSPreSets = {
@ -860,24 +851,10 @@ export class CoreSite {
* Check if a WS is available in this site. * Check if a WS is available in this site.
* *
* @param method WS name. * @param method WS name.
* @param checkPrefix When true also checks with the compatibility prefix.
* @return Whether the WS is available. * @return Whether the WS is available.
*/ */
wsAvailable(method: string, checkPrefix: boolean = true): boolean { wsAvailable(method: string): boolean {
if (typeof this.infos == 'undefined') { return !!this.infos?.functionsByName?.[method];
return false;
}
if (this.infos?.functionsByName?.[method]) {
return true;
}
// Let's try again with the compatibility prefix.
if (checkPrefix) {
return this.wsAvailable(CoreConstants.WS_PREFIX + method, false);
}
return false;
} }
/** /**
@ -1301,112 +1278,32 @@ export class CoreSite {
/** /**
* Check if the local_mobile plugin is installed in the Moodle site. * Check if the local_mobile plugin is installed in the Moodle site.
* *
* @param retrying True if we're retrying the check.
* @return Promise resolved when the check is done. * @return Promise resolved when the check is done.
* @deprecated since app 4.0
*/ */
async checkLocalMobilePlugin(retrying?: boolean): Promise<LocalMobileResponse> { async checkLocalMobilePlugin(): Promise<LocalMobileResponse> {
const checkUrl = this.siteUrl + '/local/mobile/check.php'; // Not used anymore.
const service = CoreConstants.CONFIG.wsextservice; return { code: 0, coreSupported: true };
if (!service) {
// External service not defined.
return { code: 0 };
}
let data;
try {
const response = await CoreWS.sendHTTPRequest(checkUrl, {
method: 'post',
data: { service },
});
data = response.body;
} catch (ex) {
return { code: 0 };
}
if (data === null) {
// This probably means that the server was configured to return null for non-existing URLs. Not installed.
return { code: 0 };
}
if (typeof data != 'undefined' && data.errorcode === 'requirecorrectaccess') {
if (!retrying) {
this.siteUrl = CoreUrlUtils.addOrRemoveWWW(this.siteUrl);
return this.checkLocalMobilePlugin(true);
} else {
throw new CoreWSError(data);
}
} else if (typeof data == 'undefined' || typeof data.code == 'undefined') {
// The local_mobile returned something we didn't expect. Let's assume it's not installed.
return { code: 0, warning: 'core.login.localmobileunexpectedresponse' };
}
const code = parseInt(data.code, 10);
if (data.error) {
switch (code) {
case 1:
// Site in maintenance mode.
throw new CoreError(Translate.instant('core.login.siteinmaintenance'));
case 2:
// Web services not enabled.
throw new CoreError(Translate.instant('core.login.webservicesnotenabled'));
case 3:
// Extended service not enabled, but the official is enabled.
return { code: 0 };
case 4:
// Neither extended or official services enabled.
throw new CoreError(Translate.instant('core.login.mobileservicesnotenabled'));
default:
throw new CoreError(Translate.instant('core.unexpectederror'));
}
} else {
return { code, service, coreSupported: !!data.coresupported };
}
} }
/** /**
* Check if local_mobile has been installed in Moodle. * Check if local_mobile has been installed in Moodle.
* *
* @return Whether the App is able to use local_mobile plugin for this site. * @return Whether the App is able to use local_mobile plugin for this site.
* @deprecated since app 4.0
*/ */
checkIfAppUsesLocalMobile(): boolean { checkIfAppUsesLocalMobile(): boolean {
let appUsesLocalMobile = false; return false;
if (!this.infos || !this.infos.functions) {
return appUsesLocalMobile;
}
this.infos.functions.forEach((func) => {
if (func.name.indexOf(CoreConstants.WS_PREFIX) != -1) {
appUsesLocalMobile = true;
}
});
return appUsesLocalMobile;
} }
/** /**
* Check if local_mobile has been installed in Moodle but the app is not using it. * Check if local_mobile has been installed in Moodle but the app is not using it.
* *
* @return Promise resolved it local_mobile was added, rejected otherwise. * @return Promise resolved it local_mobile was added, rejected otherwise.
* @deprecated since app 4.0
*/ */
async checkIfLocalMobileInstalledAndNotUsed(): Promise<void> { async checkIfLocalMobileInstalledAndNotUsed(): Promise<void> {
const appUsesLocalMobile = this.checkIfAppUsesLocalMobile(); throw new CoreError('Deprecated.');
if (appUsesLocalMobile) {
// App already uses local_mobile, it wasn't added.
throw new CoreError('Already used.');
}
const data = await this.checkLocalMobilePlugin();
if (typeof data.service == 'undefined') {
// The local_mobile NOT installed. Reject.
throw new CoreError('Not installed.');
}
} }
/** /**
@ -2078,6 +1975,8 @@ export type CoreSiteWSPreSets = {
/** /**
* Response of checking local_mobile status. * Response of checking local_mobile status.
*
* @deprecated since app 4.0
*/ */
export type LocalMobileResponse = { export type LocalMobileResponse = {
/** /**

View File

@ -68,7 +68,7 @@ export class CoreConstants {
// WS constants. // WS constants.
static readonly WS_TIMEOUT = 30000; // Timeout when not in WiFi. static readonly WS_TIMEOUT = 30000; // Timeout when not in WiFi.
static readonly WS_TIMEOUT_WIFI = 30000; // Timeout when in WiFi. static readonly WS_TIMEOUT_WIFI = 30000; // Timeout when in WiFi.
static readonly WS_PREFIX = 'local_mobile_'; static readonly WS_PREFIX = 'local_mobile_'; // @deprecated since app 4.0.
// Login constants. // Login constants.
static readonly LOGIN_SSO_CODE = 2; // SSO in browser window is required. static readonly LOGIN_SSO_CODE = 2; // SSO in browser window is required.

View File

@ -56,7 +56,6 @@
"invalidurl": "Invalid URL specified", "invalidurl": "Invalid URL specified",
"invalidvaluemax": "The maximum value is {{$a}}", "invalidvaluemax": "The maximum value is {{$a}}",
"invalidvaluemin": "The minimum value is {{$a}}", "invalidvaluemin": "The minimum value is {{$a}}",
"localmobileunexpectedresponse": "Moodle Mobile Additional Features check returned an unexpected response. You will be authenticated using the standard mobile service.",
"loggedoutssodescription": "You have to authenticate again. You need to log in to the site in a browser window.", "loggedoutssodescription": "You have to authenticate again. You need to log in to the site in a browser window.",
"login": "Log in", "login": "Log in",
"loginbutton": "Log in", "loginbutton": "Log in",

View File

@ -124,7 +124,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
} }
/** /**
* Check if a site uses local_mobile, requires SSO login, etc. * Get site config and check if it requires SSO login.
* This should be used only if a fixed URL is set, otherwise this check is already performed in CoreLoginSitePage. * This should be used only if a fixed URL is set, otherwise this check is already performed in CoreLoginSitePage.
* *
* @param siteUrl Site URL to check. * @param siteUrl Site URL to check.
@ -145,10 +145,6 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
this.siteConfig = result.config; this.siteConfig = result.config;
this.treatSiteConfig(); this.treatSiteConfig();
if (result && result.warning) {
CoreDomUtils.showErrorModal(result.warning, true, 4000);
}
if (CoreLoginHelper.isSSOLoginNeeded(result.code)) { if (CoreLoginHelper.isSSOLoginNeeded(result.code)) {
// SSO. User needs to authenticate in a browser. // SSO. User needs to authenticate in a browser.
this.isBrowserSSO = true; this.isBrowserSSO = true;

View File

@ -310,8 +310,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
}; };
if (this.siteConfig?.launchurl) { if (this.siteConfig?.launchurl) {
const service = CoreSites.determineService(this.siteUrl); params.redirect = CoreLoginHelper.prepareForSSOLogin(this.siteUrl, undefined, this.siteConfig.launchurl);
params.redirect = CoreLoginHelper.prepareForSSOLogin(this.siteUrl, service, this.siteConfig.launchurl);
} }
// Get the recaptcha response (if needed). // Get the recaptcha response (if needed).

View File

@ -339,10 +339,6 @@ export class CoreLoginSitePage implements OnInit {
CoreForms.triggerFormSubmittedEvent(this.formElement, true); CoreForms.triggerFormSubmittedEvent(this.formElement, true);
if (response.warning) {
CoreDomUtils.showErrorModal(response.warning, true, 4000);
}
if (CoreLoginHelper.isSSOLoginNeeded(response.code)) { if (CoreLoginHelper.isSSOLoginNeeded(response.code)) {
// SSO. User needs to authenticate in a browser. // SSO. User needs to authenticate in a browser.
CoreLoginHelper.confirmAndOpenBrowserForSSOLogin( CoreLoginHelper.confirmAndOpenBrowserForSSOLogin(

View File

@ -128,8 +128,8 @@ export class CoreLoginHelperProvider {
* *
* @param siteurl URL of the site where the SSO login will be performed. * @param siteurl URL of the site where the SSO login will be performed.
* @param typeOfLogin CoreConstants.LOGIN_SSO_CODE or CoreConstants.LOGIN_SSO_INAPP_CODE. * @param typeOfLogin CoreConstants.LOGIN_SSO_CODE or CoreConstants.LOGIN_SSO_INAPP_CODE.
* @param service The service to use. If not defined, external service will be used. * @param service The service to use. If not defined, core service will be used.
* @param launchUrl The URL to open for SSO. If not defined, local_mobile launch URL will be used. * @param launchUrl The URL to open for SSO. If not defined, default tool mobile launch URL will be used.
* @return Promise resolved when done or if user cancelled. * @return Promise resolved when done or if user cancelled.
*/ */
async confirmAndOpenBrowserForSSOLogin( async confirmAndOpenBrowserForSSOLogin(
@ -655,8 +655,7 @@ export class CoreLoginHelperProvider {
return false; return false;
} }
const service = CoreSites.determineService(siteUrl); const loginUrl = this.prepareForSSOLogin(siteUrl, undefined, launchUrl, pageName, pageOptions, {
const loginUrl = this.prepareForSSOLogin(siteUrl, service, launchUrl, pageName, pageOptions, {
oauthsso: params.id, oauthsso: params.id,
}); });
@ -672,8 +671,8 @@ export class CoreLoginHelperProvider {
* *
* @param siteurl URL of the site where the SSO login will be performed. * @param siteurl URL of the site where the SSO login will be performed.
* @param typeOfLogin CoreConstants.LOGIN_SSO_CODE or CoreConstants.LOGIN_SSO_INAPP_CODE. * @param typeOfLogin CoreConstants.LOGIN_SSO_CODE or CoreConstants.LOGIN_SSO_INAPP_CODE.
* @param service The service to use. If not defined, external service will be used. * @param service The service to use. If not defined, core service will be used.
* @param launchUrl The URL to open for SSO. If not defined, local_mobile launch URL will be used. * @param launchUrl The URL to open for SSO. If not defined, default tool mobile launch URL will be used.
* @param pageName Name of the page to go once authenticated. If not defined, site initial page. * @param pageName Name of the page to go once authenticated. If not defined, site initial page.
* @param pageOptions Options of the state to go once authenticated. * @param pageOptions Options of the state to go once authenticated.
*/ */
@ -790,8 +789,8 @@ export class CoreLoginHelperProvider {
* Prepare the app to perform SSO login. * Prepare the app to perform SSO login.
* *
* @param siteUrl URL of the site where the SSO login will be performed. * @param siteUrl URL of the site where the SSO login will be performed.
* @param service The service to use. If not defined, external service will be used. * @param service The service to use. If not defined, core service will be used.
* @param launchUrl The URL to open for SSO. If not defined, local_mobile launch URL will be used. * @param launchUrl The URL to open for SSO. If not defined, default tool mobile launch URL will be used.
* @param pageName Name of the page to go once authenticated. If not defined, site initial page. * @param pageName Name of the page to go once authenticated. If not defined, site initial page.
* @param pageOptions Options of the page to go once authenticated. * @param pageOptions Options of the page to go once authenticated.
* @param urlParams Other params to add to the URL. * @param urlParams Other params to add to the URL.
@ -806,8 +805,8 @@ export class CoreLoginHelperProvider {
urlParams?: CoreUrlParams, urlParams?: CoreUrlParams,
): string { ): string {
service = service || CoreConstants.CONFIG.wsextservice; service = service || CoreConstants.CONFIG.wsservice;
launchUrl = launchUrl || siteUrl + '/local/mobile/launch.php'; launchUrl = launchUrl || siteUrl + '/admin/tool/mobile/launch.php';
const passport = Math.random() * 1000; const passport = Math.random() * 1000;
let loginUrl = launchUrl + '?service=' + service; let loginUrl = launchUrl + '?service=' + service;
@ -896,10 +895,6 @@ export class CoreLoginHelperProvider {
// Check authentication method. // Check authentication method.
const result = await CoreSites.checkSite(siteUrl); const result = await CoreSites.checkSite(siteUrl);
if (result.warning) {
CoreDomUtils.showErrorModal(result.warning, true, 4000);
}
if (this.isSSOLoginNeeded(result.code)) { if (this.isSSOLoginNeeded(result.code)) {
// SSO. User needs to authenticate in a browser. Check if we need to display a message. // SSO. User needs to authenticate in a browser. Check if we need to display a message.
if (!CoreApp.isSSOAuthenticationOngoing() && !this.waitingForBrowser) { if (!CoreApp.isSSOAuthenticationOngoing() && !this.waitingForBrowser) {

View File

@ -267,7 +267,6 @@ export class CoreSettingsHelperProvider {
CoreUtils.ignoreErrors(CoreFilepool.invalidateAllFiles(siteId)), CoreUtils.ignoreErrors(CoreFilepool.invalidateAllFiles(siteId)),
// Invalidate and synchronize site data. // Invalidate and synchronize site data.
site.invalidateWsCache(), site.invalidateWsCache(),
this.checkSiteLocalMobile(site),
CoreSites.updateSiteInfo(site.getId()), CoreSites.updateSiteInfo(site.getId()),
CoreCronDelegate.forceSyncExecution(site.getId()), CoreCronDelegate.forceSyncExecution(site.getId()),
// eslint-disable-next-line arrow-body-style // eslint-disable-next-line arrow-body-style
@ -284,27 +283,6 @@ export class CoreSettingsHelperProvider {
} }
} }
/**
* Check if local_mobile was added to the site.
*
* @param site Site to check.
* @return Promise resolved if no action needed.
*/
protected async checkSiteLocalMobile(site: CoreSite): Promise<void> {
try {
// Check if local_mobile was installed in Moodle.
await site.checkIfLocalMobileInstalledAndNotUsed();
} catch {
// Not added, nothing to do.
return;
}
// Local mobile was added. Throw invalid session to force reconnect and create a new token.
CoreEvents.trigger(CoreEvents.SESSION_EXPIRED, {}, site.getId());
throw new CoreError(Translate.instant('core.lostconnection'));
}
/** /**
* Upgrades from Font size to new zoom level. * Upgrades from Font size to new zoom level.
*/ */

View File

@ -27,7 +27,6 @@ import { CoreConstants } from '@/core/constants';
import { import {
CoreSite, CoreSite,
CoreSiteWSPreSets, CoreSiteWSPreSets,
LocalMobileResponse,
CoreSiteInfo, CoreSiteInfo,
CoreSiteConfig, CoreSiteConfig,
CoreSitePublicConfigResponse, CoreSitePublicConfigResponse,
@ -73,7 +72,6 @@ export class CoreSitesProvider {
protected static readonly INVALID_VERSION = -1; protected static readonly INVALID_VERSION = -1;
protected logger: CoreLogger; protected logger: CoreLogger;
protected services = {};
protected sessionRestored = false; protected sessionRestored = false;
protected currentSite?: CoreSite; protected currentSite?: CoreSite;
protected sites: { [s: string]: CoreSite } = {}; protected sites: { [s: string]: CoreSite } = {};
@ -182,8 +180,6 @@ export class CoreSitesProvider {
* @return A promise resolved when the site is checked. * @return A promise resolved when the site is checked.
*/ */
async checkSiteWithProtocol(siteUrl: string, protocol: string): Promise<CoreSiteCheckResponse> { async checkSiteWithProtocol(siteUrl: string, protocol: string): Promise<CoreSiteCheckResponse> {
let publicConfig: CoreSitePublicConfigResponse | undefined;
// Now, replace the siteUrl with the protocol. // Now, replace the siteUrl with the protocol.
siteUrl = siteUrl.replace(/^https?:\/\//i, protocol); siteUrl = siteUrl.replace(/^https?:\/\//i, protocol);
@ -222,82 +218,59 @@ export class CoreSitesProvider {
} }
} }
// Site exists. Create a temporary site to check if local_mobile is installed. // Site exists. Create a temporary site to fetch its info.
const temporarySite = CoreSitesFactory.makeSite(undefined, siteUrl); const temporarySite = CoreSitesFactory.makeSite(undefined, siteUrl);
let data: LocalMobileResponse; let config: CoreSitePublicConfigResponse | undefined;
try { try {
data = await temporarySite.checkLocalMobilePlugin(); config = await temporarySite.getPublicConfig();
// Check that the user can authenticate.
if (!config.enablewebservices) {
throw new CoreSiteError({
message: Translate.instant('core.login.webservicesnotenabled'),
});
} else if (!config.enablemobilewebservice) {
throw new CoreSiteError({
message: Translate.instant('core.login.mobileservicesnotenabled'),
});
} else if (config.maintenanceenabled) {
let message = Translate.instant('core.sitemaintenance');
if (config.maintenancemessage) {
message += config.maintenancemessage;
}
throw new CoreSiteError({
message,
});
}
} catch (error) { } catch (error) {
// Local mobile check returned an error. This only happens if the plugin is installed and it returns an error. // Error, check if not supported.
throw new CoreSiteError({ if (error.available === 1) {
message: error.message, // Service supported but an error happened. Return error.
critical: true, if (error.errorcode == 'codingerror') {
}); // This could be caused by a redirect. Check if it's the case.
} const redirect = await CoreUtils.checkRedirect(siteUrl);
data.service = data.service || CoreConstants.CONFIG.wsservice; if (redirect) {
this.services[siteUrl] = data.service; // No need to store it in DB. error.error = Translate.instant('core.login.sitehasredirect');
} else {
if (data.coreSupported || (data.code != CoreConstants.LOGIN_SSO_CODE && data.code != CoreConstants.LOGIN_SSO_INAPP_CODE)) { // We can't be sure if there is a redirect or not. Display cannot connect error.
// SSO using local_mobile not needed, try to get the site public config. error.error = Translate.instant('core.cannotconnecttrouble');
try {
const config = await temporarySite.getPublicConfig();
publicConfig = config;
// Check that the user can authenticate.
if (!config.enablewebservices) {
throw new CoreSiteError({
message: Translate.instant('core.login.webservicesnotenabled'),
});
} else if (!config.enablemobilewebservice) {
throw new CoreSiteError({
message: Translate.instant('core.login.mobileservicesnotenabled'),
});
} else if (config.maintenanceenabled) {
let message = Translate.instant('core.sitemaintenance');
if (config.maintenancemessage) {
message += config.maintenancemessage;
} }
throw new CoreSiteError({
message,
});
} }
// Everything ok. throw new CoreSiteError({
if (data.code === 0) { message: error.error,
data.code = config.typeoflogin; errorcode: error.errorcode,
} critical: true,
} catch (error) { });
// Error, check if not supported.
if (error.available === 1) {
// Service supported but an error happened. Return error.
if (error.errorcode == 'codingerror') {
// This could be caused by a redirect. Check if it's the case.
const redirect = await CoreUtils.checkRedirect(siteUrl);
if (redirect) {
error.error = Translate.instant('core.login.sitehasredirect');
} else {
// We can't be sure if there is a redirect or not. Display cannot connect error.
error.error = Translate.instant('core.cannotconnecttrouble');
}
}
throw new CoreSiteError({
message: error.error,
errorcode: error.errorcode,
critical: true,
});
}
} }
} }
siteUrl = temporarySite.getURL(); siteUrl = temporarySite.getURL();
return { siteUrl, code: data.code, warning: data.warning, service: data.service, config: publicConfig }; return { siteUrl, code: config?.typeoflogin || 0, service: CoreConstants.CONFIG.wsservice, config };
} }
/** /**
@ -367,10 +340,7 @@ export class CoreSitesProvider {
throw new CoreNetworkError(); throw new CoreNetworkError();
} }
if (!service) { service = service || CoreConstants.CONFIG.wsservice;
service = this.determineService(siteUrl);
}
const params = { const params = {
username, username,
password, password,
@ -573,25 +543,10 @@ export class CoreSitesProvider {
/** /**
* Function for determine which service we should use (default or extended plugin). * Function for determine which service we should use (default or extended plugin).
* *
* @param siteUrl The site URL.
* @return The service shortname. * @return The service shortname.
* @deprecated since app 4.0
*/ */
determineService(siteUrl: string): string { determineService(): string {
// We need to try siteUrl in both https or http (due to loginhttps setting).
// First http://
siteUrl = siteUrl.replace('https://', 'http://');
if (this.services[siteUrl]) {
return this.services[siteUrl];
}
// Now https://
siteUrl = siteUrl.replace('http://', 'https://');
if (this.services[siteUrl]) {
return this.services[siteUrl];
}
// Return default service.
return CoreConstants.CONFIG.wsservice; return CoreConstants.CONFIG.wsservice;
} }
@ -839,37 +794,24 @@ export class CoreSitesProvider {
return false; return false;
} }
// Check if local_mobile was installed to Moodle. let config: CoreSitePublicConfigResponse | undefined;
try { try {
await site.checkIfLocalMobileInstalledAndNotUsed(); config = await site.getPublicConfig();
// Local mobile was added. Throw invalid session to force reconnect and create a new token.
CoreEvents.trigger(CoreEvents.SESSION_EXPIRED, {
pageName,
options: pageOptions,
}, siteId);
return false;
} catch (error) { } catch (error) {
let config: CoreSitePublicConfigResponse | undefined; // Error getting config, maybe the user is offline.
}
try { try {
config = await site.getPublicConfig(); await this.checkApplication(config);
} catch (error) {
// Error getting config, probably the site doesn't have the WS
}
try { this.login(siteId);
await this.checkApplication(config); // Update site info. We don't block the UI.
this.updateSiteInfo(siteId);
this.login(siteId); return true;
// Update site info. We don't block the UI. } catch (error) {
this.updateSiteInfo(siteId); return false;
return true;
} catch (error) {
return false;
}
} }
} }
@ -1499,13 +1441,12 @@ export class CoreSitesProvider {
* Check if a WS is available in the current site, if any. * Check if a WS is available in the current site, if any.
* *
* @param method WS name. * @param method WS name.
* @param checkPrefix When true also checks with the compatibility prefix.
* @return Whether the WS is available. * @return Whether the WS is available.
*/ */
wsAvailableInCurrentSite(method: string, checkPrefix: boolean = true): boolean { wsAvailableInCurrentSite(method: string): boolean {
const site = this.getCurrentSite(); const site = this.getCurrentSite();
return site ? site.wsAvailable(method, checkPrefix) : false; return site ? site.wsAvailable(method) : false;
} }
/** /**
@ -1744,7 +1685,7 @@ export type CoreSiteCheckResponse = {
service: string; service: string;
/** /**
* Code of the warning message to show to the user. * Code of the warning message to show to the user. @deprecated since app 4.0
*/ */
warning?: string; warning?: string;

View File

@ -32,7 +32,6 @@ export interface EnvironmentConfig {
default_lang: string; default_lang: string;
languages: Record<string, string>; languages: Record<string, string>;
wsservice: string; wsservice: string;
wsextservice: string;
demo_sites: Record<string, CoreSitesDemoSiteData>; demo_sites: Record<string, CoreSitesDemoSiteData>;
zoomlevels: Record<CoreZoomLevel, number>; zoomlevels: Record<CoreZoomLevel, number>;
customurlscheme: string; customurlscheme: string;