MOBILE-4498 tags: Use advanced features to check if tags are enabled

main
Pau Ferrer Ocaña 2024-02-28 15:37:49 +01:00
parent cca9a3b784
commit 3cc03713ae
8 changed files with 79 additions and 10 deletions

View File

@ -93,6 +93,7 @@ jobs:
"@core_search"
"@core_settings"
"@core_siteplugins"
"@core_tag"
"@core_user"
"@core_usertour"
)

View File

@ -18,6 +18,8 @@ import { CoreBlockHandlerData } from '@features/block/services/block-delegate';
import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler';
import { AddonBlockBlogTagsComponent } from '../components/blogtags/blogtags';
import { makeSingleton } from '@singletons';
import { CoreTag } from '@features/tag/services/tag';
import { AddonBlog } from '@addons/blog/services/blog';
/**
* Block handler.
@ -28,6 +30,16 @@ export class AddonBlockBlogTagsHandlerService extends CoreBlockBaseHandler {
name = 'AddonBlockBlogTags';
blockName = 'blog_tags';
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
const tags = await CoreTag.areTagsAvailable();
const blogs = await AddonBlog.isPluginEnabled();
return blogs && tags;
}
/**
* Returns the data needed to render the block.
*

View File

@ -18,6 +18,7 @@ import { CoreBlockHandlerData } from '@features/block/services/block-delegate';
import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler';
import { AddonBlockTagsComponent } from '../components/tags/tags';
import { makeSingleton } from '@singletons';
import { CoreTag } from '@features/tag/services/tag';
/**
* Block handler.
@ -28,6 +29,13 @@ export class AddonBlockTagsHandlerService extends CoreBlockBaseHandler {
name = 'AddonBlockTags';
blockName = 'tags';
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return await CoreTag.areTagsAvailable();
}
/**
* Returns the data needed to render the block.
*

View File

@ -111,6 +111,15 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
}
}
/**
* Check if the delegate is enabled so handlers are not updated if not..
*
* @returns Whether the delegate is enabled.
*/
async isEnabled(): Promise<boolean> {
return true;
}
/**
* Execute a certain function in a enabled handler.
* If the handler isn't found or function isn't defined, call the same function in the default handler.
@ -315,6 +324,12 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
* @returns Resolved when done.
*/
async updateHandlers(): Promise<void> {
const enabled = await this.isEnabled();
if (!enabled) {
return;
}
const promises: Promise<void>[] = [];
const now = Date.now();
@ -329,7 +344,7 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
try {
await Promise.all(promises);
} catch (e) {
} catch {
// Never reject
}

View File

@ -15,7 +15,6 @@
import { Injectable } from '@angular/core';
import { CoreTag } from '../tag';
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';
/**
@ -35,13 +34,7 @@ export class CoreTagMainMenuHandlerService implements CoreMainMenuHandler {
* @returns Whether or not the handler is enabled on a site level.
*/
async isEnabled(): Promise<boolean> {
const available = await CoreTag.areTagsAvailable();
if (!available) {
return false;
}
// The only way to check whether tags are enabled on web is to perform a WS call.
return CoreUtils.promiseWorks(CoreTag.getTagCollections());
return await CoreTag.areTagsAvailable();
}
/**

View File

@ -15,6 +15,7 @@
import { Injectable, Type } from '@angular/core';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { makeSingleton } from '@singletons';
import { CoreTag } from './tag';
/**
* Interface that all tag area handlers must implement.
@ -53,6 +54,13 @@ export class CoreTagAreaDelegateService extends CoreDelegate<CoreTagAreaHandler>
super('CoreTagAreaDelegate', true);
}
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return CoreTag.areTagsAvailable();
}
/**
* Returns the display name string for this area.
*

View File

@ -53,7 +53,8 @@ export class CoreTagProvider {
areTagsAvailableInSite(site?: CoreSite): boolean {
site = site || CoreSites.getCurrentSite();
return !!site && site.wsAvailable('core_tag_get_tagindex_per_area') &&
return !!site && site.canUseAdvancedFeature('usetags') &&
site.wsAvailable('core_tag_get_tagindex_per_area') &&
site.wsAvailable('core_tag_get_tag_cloud') &&
site.wsAvailable('core_tag_get_tag_collections') &&
!site.isFeatureDisabled('NoDelegate_CoreTag');

View File

@ -0,0 +1,31 @@
@core_tag @app @javascript
Feature: Tag navigation
Background:
Given the following "users" exist:
| username | firstname | lastname | email | interests |
| user1 | User | 1 | user1@example.com | Cat |
| user2 | User | 2 | user1@example.com | Cat, Dog |
| user3 | User | 3 | user1@example.com | Dog |
And the following "courses" exist:
| fullname | shortname | tags |
| Course 1 | c1 | Cat, Dog |
| Course 2 | c2 | Cat |
| Course 3 | c3 | Cat |
| Course 4 | c4 | Cat |
| Course 5 | c5 | Cat |
| Course 6 | c6 | Cat |
| Course 7 | c7 | Cat |
Scenario: Tag menu item is found in the more menu when completion is enabled
Given I entered the app as "user1"
When I press the more menu button in the app
And I press "Tags" in the app
Then I should find "Cat" in the app
Then I should find "Dog" in the app
Given the following config values are set as admin:
| usetags | 0 |
And I entered the app as "user1"
When I press the more menu button in the app
Then I should not find "Tags" in the app