From ca8b223e784bc14bbfcb269afd3547644a1c29c3 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 5 May 2021 17:57:17 +0200 Subject: [PATCH] MOBILE-3320 login: Check application everywhere --- .../features/login/pages/reconnect/reconnect.ts | 2 +- src/core/features/login/pages/site/site.ts | 4 ++-- .../features/login/services/handlers/cron.ts | 5 ++--- src/core/services/sites.ts | 17 ++++++++--------- src/core/services/urlschemes.ts | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/core/features/login/pages/reconnect/reconnect.ts b/src/core/features/login/pages/reconnect/reconnect.ts index 275b52e71..8eeb846b1 100644 --- a/src/core/features/login/pages/reconnect/reconnect.ts +++ b/src/core/features/login/pages/reconnect/reconnect.ts @@ -112,7 +112,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy { this.siteConfig = config; - await CoreSites.checkRequiredMinimumVersion(config); + await CoreSites.checkApplication(config); // Check logoURL if user avatar is not set. if (this.userAvatar.startsWith(this.siteUrl + '/theme/image.php')) { diff --git a/src/core/features/login/pages/site/site.ts b/src/core/features/login/pages/site/site.ts index 7eb62e9c8..7f94f447c 100644 --- a/src/core/features/login/pages/site/site.ts +++ b/src/core/features/login/pages/site/site.ts @@ -349,7 +349,7 @@ export class CoreLoginSitePage implements OnInit { */ protected async login(response: CoreSiteCheckResponse, foundSite?: CoreLoginSiteInfoExtended): Promise { try { - await CoreSites.checkApplication(response); + await CoreSites.checkApplication(response.config); CoreForms.triggerFormSubmittedEvent(this.formElement, true); @@ -545,7 +545,7 @@ export class CoreLoginSitePage implements OnInit { // Check if site uses SSO. const response = await CoreSites.checkSite(siteUrl); - await CoreSites.checkApplication(response); + await CoreSites.checkApplication(response.config); if (!CoreLoginHelper.isSSOLoginNeeded(response.code)) { // No SSO, go to credentials page. diff --git a/src/core/features/login/services/handlers/cron.ts b/src/core/features/login/services/handlers/cron.ts index 826306c60..2add95869 100644 --- a/src/core/features/login/services/handlers/cron.ts +++ b/src/core/features/login/services/handlers/cron.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreSitePublicConfigResponse } from '@classes/site'; import { CoreCronHandler } from '@services/cron'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -40,9 +39,9 @@ export class CoreLoginCronHandlerService implements CoreCronHandler { // Do not check twice in the same 10 minutes. const site = await CoreSites.getSite(siteId); - const config = await CoreUtils.ignoreErrors(site.getPublicConfig(), > {}); + const config = await CoreUtils.ignoreErrors(site.getPublicConfig()); - CoreUtils.ignoreErrors(CoreSites.checkApplication( config)); + CoreUtils.ignoreErrors(CoreSites.checkApplication(config)); } /** diff --git a/src/core/services/sites.ts b/src/core/services/sites.ts index a022d4783..21f4eea6c 100644 --- a/src/core/services/sites.ts +++ b/src/core/services/sites.ts @@ -707,20 +707,19 @@ export class CoreSitesProvider { /** * Check the app for a site and show a download dialogs if necessary. * - * @param response Data obtained during site check. + * @param config Config object of the site. */ - async checkApplication(response: CoreSiteCheckResponse): Promise { - await this.checkRequiredMinimumVersion(response.config); + async checkApplication(config?: CoreSitePublicConfigResponse): Promise { + await this.checkRequiredMinimumVersion(config); } /** * Check the required minimum version of the app for a site and shows a download dialog. * - * @param config Config object of the site. - * @param siteId ID of the site to check. Current site id will be used otherwise. + * @param config Config object of the site. * @return Resolved with if meets the requirements, rejected otherwise. */ - async checkRequiredMinimumVersion(config?: CoreSitePublicConfigResponse, siteId?: string): Promise { + protected async checkRequiredMinimumVersion(config?: CoreSitePublicConfigResponse): Promise { if (!config || !config.tool_mobile_minimumversion) { return; } @@ -736,7 +735,7 @@ export class CoreSitesProvider { default: config.tool_mobile_setuplink, }; - siteId = siteId || this.getCurrentSiteId(); + const siteId = this.getCurrentSiteId(); const downloadUrl = CoreApp.getAppStoreUrl(storesConfig); @@ -838,7 +837,7 @@ export class CoreSitesProvider { } try { - await this.checkRequiredMinimumVersion(config); + await this.checkApplication(config); this.login(siteId); // Update site info. We don't block the UI. @@ -1301,7 +1300,7 @@ export class CoreSitesProvider { * @param siteid Site's ID. * @return A promise resolved when the site is updated. */ - async updateSiteInfo(siteId: string): Promise { + async updateSiteInfo(siteId?: string): Promise { const site = await this.getSite(siteId); try { diff --git a/src/core/services/urlschemes.ts b/src/core/services/urlschemes.ts index c5f40582d..7cbe49670 100644 --- a/src/core/services/urlschemes.ts +++ b/src/core/services/urlschemes.ts @@ -66,7 +66,7 @@ export class CoreCustomURLSchemesProvider { data.siteUrl = result.siteUrl; - await CoreSites.checkApplication(result); + await CoreSites.checkApplication(result.config); } return CoreSites.newSite(