MOBILE-4498 tags: Use advanced features to check if tags are enabled
parent
cca9a3b784
commit
3cc03713ae
|
@ -93,6 +93,7 @@ jobs:
|
||||||
"@core_search"
|
"@core_search"
|
||||||
"@core_settings"
|
"@core_settings"
|
||||||
"@core_siteplugins"
|
"@core_siteplugins"
|
||||||
|
"@core_tag"
|
||||||
"@core_user"
|
"@core_user"
|
||||||
"@core_usertour"
|
"@core_usertour"
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,6 +18,8 @@ import { CoreBlockHandlerData } from '@features/block/services/block-delegate';
|
||||||
import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler';
|
import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler';
|
||||||
import { AddonBlockBlogTagsComponent } from '../components/blogtags/blogtags';
|
import { AddonBlockBlogTagsComponent } from '../components/blogtags/blogtags';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
import { CoreTag } from '@features/tag/services/tag';
|
||||||
|
import { AddonBlog } from '@addons/blog/services/blog';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block handler.
|
* Block handler.
|
||||||
|
@ -28,6 +30,16 @@ export class AddonBlockBlogTagsHandlerService extends CoreBlockBaseHandler {
|
||||||
name = 'AddonBlockBlogTags';
|
name = 'AddonBlockBlogTags';
|
||||||
blockName = 'blog_tags';
|
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.
|
* Returns the data needed to render the block.
|
||||||
*
|
*
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { CoreBlockHandlerData } from '@features/block/services/block-delegate';
|
||||||
import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler';
|
import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler';
|
||||||
import { AddonBlockTagsComponent } from '../components/tags/tags';
|
import { AddonBlockTagsComponent } from '../components/tags/tags';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
import { CoreTag } from '@features/tag/services/tag';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block handler.
|
* Block handler.
|
||||||
|
@ -28,6 +29,13 @@ export class AddonBlockTagsHandlerService extends CoreBlockBaseHandler {
|
||||||
name = 'AddonBlockTags';
|
name = 'AddonBlockTags';
|
||||||
blockName = 'tags';
|
blockName = 'tags';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async isEnabled(): Promise<boolean> {
|
||||||
|
return await CoreTag.areTagsAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the data needed to render the block.
|
* Returns the data needed to render the block.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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.
|
* 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.
|
* 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.
|
* @returns Resolved when done.
|
||||||
*/
|
*/
|
||||||
async updateHandlers(): Promise<void> {
|
async updateHandlers(): Promise<void> {
|
||||||
|
const enabled = await this.isEnabled();
|
||||||
|
|
||||||
|
if (!enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
|
@ -329,7 +344,7 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
} catch (e) {
|
} catch {
|
||||||
// Never reject
|
// Never reject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CoreTag } from '../tag';
|
import { CoreTag } from '../tag';
|
||||||
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate';
|
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
|
||||||
import { makeSingleton } from '@singletons';
|
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.
|
* @returns Whether or not the handler is enabled on a site level.
|
||||||
*/
|
*/
|
||||||
async isEnabled(): Promise<boolean> {
|
async isEnabled(): Promise<boolean> {
|
||||||
const available = await CoreTag.areTagsAvailable();
|
return 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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
import { Injectable, Type } from '@angular/core';
|
import { Injectable, Type } from '@angular/core';
|
||||||
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
|
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
import { CoreTag } from './tag';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface that all tag area handlers must implement.
|
* Interface that all tag area handlers must implement.
|
||||||
|
@ -53,6 +54,13 @@ export class CoreTagAreaDelegateService extends CoreDelegate<CoreTagAreaHandler>
|
||||||
super('CoreTagAreaDelegate', true);
|
super('CoreTagAreaDelegate', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async isEnabled(): Promise<boolean> {
|
||||||
|
return CoreTag.areTagsAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the display name string for this area.
|
* Returns the display name string for this area.
|
||||||
*
|
*
|
||||||
|
|
|
@ -53,7 +53,8 @@ export class CoreTagProvider {
|
||||||
areTagsAvailableInSite(site?: CoreSite): boolean {
|
areTagsAvailableInSite(site?: CoreSite): boolean {
|
||||||
site = site || CoreSites.getCurrentSite();
|
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_cloud') &&
|
||||||
site.wsAvailable('core_tag_get_tag_collections') &&
|
site.wsAvailable('core_tag_get_tag_collections') &&
|
||||||
!site.isFeatureDisabled('NoDelegate_CoreTag');
|
!site.isFeatureDisabled('NoDelegate_CoreTag');
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue