From 2a7f7e89779b9a33c4506865618cf404ad48c115 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 29 Jul 2020 06:23:54 +0200 Subject: [PATCH] MOBILE-3454 filters: Support disabling check text filters --- src/assets/lang/en.json | 1 + src/core/filter/providers/filter.ts | 55 +++++++++++++++++-- src/core/filter/providers/helper.ts | 4 +- .../providers/pushnotifications.ts | 2 +- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index ec064e2dd..93dcadfc1 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1914,6 +1914,7 @@ "core.openmodinbrowser": "Open {{$a}} in browser", "core.othergroups": "Other groups", "core.pagea": "Page {{$a}}", + "core.parentlanguage": "", "core.paymentinstant": "Use the button below to pay and be enrolled within minutes!", "core.percentagenumber": "{{$a}}%", "core.phone": "Phone", diff --git a/src/core/filter/providers/filter.ts b/src/core/filter/providers/filter.ts index a404d5616..cfc5bc66d 100644 --- a/src/core/filter/providers/filter.ts +++ b/src/core/filter/providers/filter.ts @@ -65,10 +65,10 @@ export class CoreFilterProvider { } /** - * Returns whether or not WS get available in context is avalaible. + * Returns whether or not WS get available in context is available. * * @param siteId Site ID. If not defined, current site. - * @return Promise resolved with true if ws is avalaible, false otherwise. + * @return Promise resolved with true if ws is available, false otherwise. * @since 3.4 */ canGetAvailableInContext(siteId?: string): Promise { @@ -78,10 +78,10 @@ export class CoreFilterProvider { } /** - * Returns whether or not WS get available in context is avalaible in a certain site. + * Returns whether or not WS get available in context is available in a certain site. * * @param site Site. If not defined, current site. - * @return Promise resolved with true if ws is avalaible, false otherwise. + * @return Promise resolved with true if ws is available, false otherwise. * @since 3.4 */ canGetAvailableInContextInSite(site?: CoreSite): boolean { @@ -90,6 +90,53 @@ export class CoreFilterProvider { return site.wsAvailable('core_filters_get_available_in_context'); } + /** + * Returns whether or not we can get the available filters: the WS is available and the feature isn't disabled. + * + * @param siteId Site ID. If not defined, current site. + * @return Promise resolved with boolean: whethe can get filters. + */ + async canGetFilters(siteId?: string): Promise { + const wsAvailable = await this.canGetAvailableInContext(siteId); + const disabled = await this.checkFiltersDisabled(siteId); + + return wsAvailable && !disabled; + } + + /** + * Returns whether or not we can get the available filters: the WS is available and the feature isn't disabled. + * + * @param site Site. If not defined, current site. + * @return Promise resolved with boolean: whethe can get filters. + */ + canGetFiltersInSite(site?: CoreSite): boolean { + return this.canGetAvailableInContextInSite(site) && this.checkFiltersDisabledInSite(site); + } + + /** + * Returns whether or not checking the available filters is disabled in the site. + * + * @param siteId Site ID. If not defined, current site. + * @return Promise resolved with boolean: whether it's disabled. + */ + async checkFiltersDisabled(siteId?: string): Promise { + const site = await this.sitesProvider.getSite(siteId); + + return this.checkFiltersDisabledInSite(site); + } + + /** + * Returns whether or not checking the available filters is disabled in the site. + * + * @param site Site. If not defined, current site. + * @return Whether it's disabled. + */ + checkFiltersDisabledInSite(site?: CoreSite): boolean { + site = site || this.sitesProvider.getCurrentSite(); + + return site.isFeatureDisabled('CoreFilterDelegate'); + } + /** * Given some HTML code, this function returns the text as safe HTML. * diff --git a/src/core/filter/providers/helper.ts b/src/core/filter/providers/helper.ts index ed0c13460..fb167b9bc 100644 --- a/src/core/filter/providers/helper.ts +++ b/src/core/filter/providers/helper.ts @@ -173,7 +173,7 @@ export class CoreFilterHelperProvider { /** * Get the filters in a certain context, performing some checks like the site version. - * It's recommended to use this function instead of canGetAvailableInContext because this function will check if + * It's recommended to use this function instead of canGetFilters + getEnabledFilters because this function will check if * it's really needed to call the WS. * * @param contextLevel The context level. @@ -193,7 +193,7 @@ export class CoreFilterHelperProvider { return this.sitesProvider.getSite(siteId).then((site) => { siteId = site.getId(); - return this.filterProvider.canGetAvailableInContext(siteId).then((canGet) => { + return this.filterProvider.canGetFilters(siteId).then((canGet) => { if (!canGet) { options.filter = true; diff --git a/src/core/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts index fea3bbc0d..28cd94d28 100644 --- a/src/core/pushnotifications/providers/pushnotifications.ts +++ b/src/core/pushnotifications/providers/pushnotifications.ts @@ -471,7 +471,7 @@ export class CorePushNotificationsProvider { extraFeatures = this.utils.isTrueOrOne(data.extrafeatures); // Get the filters to apply to text and message. Don't use FIlterHelper to prevent circular dependencies. - this.filterProvider.canGetAvailableInContext(site.getId()).then((canGet) => { + this.filterProvider.canGetFilters(site.getId()).then((canGet) => { if (!canGet) { // We cannot check which filters are available, apply them all. return this.filterDelegate.getEnabledFilters(options.contextLevel, options.instanceId);