From d46bc0601f2b6c4ec13a7d3222483de2c38152ef Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 21 Jan 2022 14:41:39 +0100 Subject: [PATCH] MOBILE-3966 core: Support new disabled features values --- src/addons/badges/services/handlers/user.ts | 18 +++++++++-- src/addons/blog/services/handlers/user.ts | 31 +++++++++++++++++-- .../competency/services/handlers/user.ts | 25 ++++++++++++++- .../services/handlers/user.ts | 2 +- .../privatefiles/services/handlers/user.ts | 21 ++++++++++++- .../features/grades/services/handlers/user.ts | 17 +++++++++- .../components/user-menu/user-menu.html | 2 +- .../components/user-menu/user-menu.ts | 2 ++ src/core/services/utils/text.ts | 1 + 9 files changed, 110 insertions(+), 9 deletions(-) diff --git a/src/addons/badges/services/handlers/user.ts b/src/addons/badges/services/handlers/user.ts index a15acfed3..21d4363c8 100644 --- a/src/addons/badges/services/handlers/user.ts +++ b/src/addons/badges/services/handlers/user.ts @@ -21,6 +21,7 @@ import { CoreUserProfileHandlerData, } from '@features/user/services/user-delegate'; import { CoreNavigator } from '@services/navigator'; +import { CoreSites } from '@services/sites'; import { makeSingleton } from '@singletons'; import { AddonBadges } from '../badges'; @@ -30,7 +31,7 @@ import { AddonBadges } from '../badges'; @Injectable({ providedIn: 'root' }) export class AddonBadgesUserHandlerService implements CoreUserProfileHandler { - name = 'AddonBadges'; + name = 'AddonBadges:fakename'; // This name doesn't match any disabled feature, they'll be checked in isEnabledForContext. priority = 50; type = CoreUserDelegateService.TYPE_NEW_PAGE; @@ -49,11 +50,24 @@ export class AddonBadgesUserHandlerService implements CoreUserProfileHandler { courseId: number, navOptions?: CoreCourseUserAdminOrNavOptionIndexed, ): Promise { + // Check if feature is disabled. + const currentSite = CoreSites.getCurrentSite(); + if (!currentSite) { + return false; + } + + if (context === CoreUserDelegateContext.USER_MENU) { + if (currentSite.isFeatureDisabled('CoreUserDelegate_AddonBadges:account')) { + return false; + } + } else if (currentSite.isFeatureDisabled('CoreUserDelegate_AddonBadges')) { + return false; + } + if (navOptions && navOptions.badges !== undefined) { return navOptions.badges; } - // If we reach here, it means we are opening the user site profile. return true; } diff --git a/src/addons/blog/services/handlers/user.ts b/src/addons/blog/services/handlers/user.ts index 566b361bf..9f221a69b 100644 --- a/src/addons/blog/services/handlers/user.ts +++ b/src/addons/blog/services/handlers/user.ts @@ -13,8 +13,14 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreUserProfileHandler, CoreUserProfileHandlerData, CoreUserDelegateService } from '@features/user/services/user-delegate'; +import { + CoreUserProfileHandler, + CoreUserProfileHandlerData, + CoreUserDelegateService, + CoreUserDelegateContext, +} from '@features/user/services/user-delegate'; import { CoreNavigator } from '@services/navigator'; +import { CoreSites } from '@services/sites'; import { makeSingleton } from '@singletons'; import { AddonBlog } from '../blog'; @@ -24,7 +30,7 @@ import { AddonBlog } from '../blog'; @Injectable({ providedIn: 'root' }) export class AddonBlogUserHandlerService implements CoreUserProfileHandler { - name = 'AddonBlog:blogs'; + name = 'AddonBlog'; // This name doesn't match any disabled feature, they'll be checked in isEnabledForContext. priority = 300; type = CoreUserDelegateService.TYPE_NEW_PAGE; @@ -35,6 +41,27 @@ export class AddonBlogUserHandlerService implements CoreUserProfileHandler { return AddonBlog.isPluginEnabled(); } + /** + * @inheritdoc + */ + async isEnabledForContext(context: CoreUserDelegateContext): Promise { + // Check if feature is disabled. + const currentSite = CoreSites.getCurrentSite(); + if (!currentSite) { + return false; + } + + if (context === CoreUserDelegateContext.USER_MENU) { + if (currentSite.isFeatureDisabled('CoreUserDelegate_AddonBlog:account')) { + return false; + } + } else if (currentSite.isFeatureDisabled('CoreUserDelegate_AddonBlog:blogs')) { + return false; + } + + return true; + } + /** * @inheritdoc */ diff --git a/src/addons/competency/services/handlers/user.ts b/src/addons/competency/services/handlers/user.ts index 9f8b28379..c6659d82d 100644 --- a/src/addons/competency/services/handlers/user.ts +++ b/src/addons/competency/services/handlers/user.ts @@ -24,6 +24,7 @@ import { } from '@features/user/services/user-delegate'; import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module'; import { CoreNavigator } from '@services/navigator'; +import { CoreSites } from '@services/sites'; import { makeSingleton } from '@singletons'; import { AddonCompetency } from '../competency'; @@ -33,7 +34,7 @@ import { AddonCompetency } from '../competency'; @Injectable( { providedIn: 'root' }) export class AddonCompetencyUserHandlerService implements CoreUserProfileHandler { - name = 'AddonCompetency:learningPlan'; + name = 'AddonCompetency'; // This name doesn't match any disabled feature, they'll be checked in isEnabledForContext. priority = 900; type = CoreUserDelegateService.TYPE_NEW_PAGE; cacheEnabled = true; @@ -45,6 +46,28 @@ export class AddonCompetencyUserHandlerService implements CoreUserProfileHandler return true; } + /** + * @inheritdoc + */ + async isEnabledForContext(context: CoreUserDelegateContext): Promise { + // Check if feature is disabled. + const currentSite = CoreSites.getCurrentSite(); + if (!currentSite) { + return false; + } + + if (context === CoreUserDelegateContext.USER_MENU) { + // This option used to belong to main menu, check the original disabled feature value. + if (currentSite.isFeatureDisabled('CoreMainMenuDelegate_AddonCompetency')) { + return false; + } + } else if (currentSite.isFeatureDisabled('CoreUserDelegate_AddonCompetency:learningPlan')) { + return false; + } + + return true; + } + /** * @inheritdoc */ diff --git a/src/addons/coursecompletion/services/handlers/user.ts b/src/addons/coursecompletion/services/handlers/user.ts index 69f47f71f..b6a08808c 100644 --- a/src/addons/coursecompletion/services/handlers/user.ts +++ b/src/addons/coursecompletion/services/handlers/user.ts @@ -30,7 +30,7 @@ import { AddonCourseCompletion } from '../coursecompletion'; @Injectable({ providedIn: 'root' }) export class AddonCourseCompletionUserHandlerService implements CoreUserProfileHandler { - name = 'AddonCourseCompletion'; + name = 'AddonCourseCompletion:viewCompletion'; type = CoreUserDelegateService.TYPE_NEW_PAGE; priority = 200; cacheEnabled = true; diff --git a/src/addons/privatefiles/services/handlers/user.ts b/src/addons/privatefiles/services/handlers/user.ts index f35aba520..d969f6e94 100644 --- a/src/addons/privatefiles/services/handlers/user.ts +++ b/src/addons/privatefiles/services/handlers/user.ts @@ -46,11 +46,30 @@ export class AddonPrivateFilesUserHandlerService implements CoreUserProfileHandl return AddonPrivateFiles.isPluginEnabled(); } + /** + * @inheritdoc + */ + async isEnabledForContext(context: CoreUserDelegateContext): Promise { + // Private files only available in user menu. + if (context !== CoreUserDelegateContext.USER_MENU) { + return false; + } + + // Check if feature is disabled. + const currentSite = CoreSites.getCurrentSite(); + if (!currentSite) { + return false; + } + + // This option used to belong to main menu, check the original disabled feature value. + return !currentSite.isFeatureDisabled('CoreMainMenuDelegate_AddonPrivateFiles'); + } + /** * @inheritdoc */ async isEnabledForUser(user: CoreUserProfile, context: CoreUserDelegateContext): Promise { - // Private files only available for the current user in user menu. + // Private files only available for the current user. return user.id == CoreSites.getCurrentSiteUserId() && context === CoreUserDelegateContext.USER_MENU; } diff --git a/src/core/features/grades/services/handlers/user.ts b/src/core/features/grades/services/handlers/user.ts index 61009832a..d6c6b5e30 100644 --- a/src/core/features/grades/services/handlers/user.ts +++ b/src/core/features/grades/services/handlers/user.ts @@ -36,7 +36,7 @@ import { makeSingleton } from '@singletons'; @Injectable({ providedIn: 'root' }) export class CoreGradesUserHandlerService implements CoreUserProfileHandler { - name = 'CoreGrades:viewGrades'; + name = 'CoreGrades'; // This name doesn't match any disabled feature, they'll be checked in isEnabledForContext. priority = 400; type = CoreUserDelegateService.TYPE_NEW_PAGE; cacheEnabled = true; @@ -52,6 +52,21 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { * @inheritdoc */ async isEnabledForContext(context: CoreUserDelegateContext, courseId: number): Promise { + // Check if feature is disabled. + const currentSite = CoreSites.getCurrentSite(); + if (!currentSite) { + return false; + } + + if (context === CoreUserDelegateContext.USER_MENU) { + // This option used to belong to main menu, check the original disabled feature value. + if (currentSite.isFeatureDisabled('CoreMainMenuDelegate_CoreGrades')) { + return false; + } + } else if (currentSite.isFeatureDisabled('CoreUserDelegate_CoreGrades:viewGrades')) { + return false; + } + if (context === CoreUserDelegateContext.COURSE) { return CoreUtils.ignoreErrors(CoreGrades.isPluginEnabledForCourse(courseId), false); } else { diff --git a/src/core/features/mainmenu/components/user-menu/user-menu.html b/src/core/features/mainmenu/components/user-menu/user-menu.html index b24ab93c7..67562de15 100644 --- a/src/core/features/mainmenu/components/user-menu/user-menu.html +++ b/src/core/features/mainmenu/components/user-menu/user-menu.html @@ -68,7 +68,7 @@ - +

{{ 'core.mainmenu.switchaccount' | translate }}

diff --git a/src/core/features/mainmenu/components/user-menu/user-menu.ts b/src/core/features/mainmenu/components/user-menu/user-menu.ts index dce64d9ea..d250ae0e7 100644 --- a/src/core/features/mainmenu/components/user-menu/user-menu.ts +++ b/src/core/features/mainmenu/components/user-menu/user-menu.ts @@ -49,6 +49,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { handlersLoaded = false; loaded = false; user?: CoreUserProfile; + displaySwitchAccount = true; protected subscription!: Subscription; @@ -60,6 +61,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { this.siteInfo = currentSite.getInfo(); this.siteName = currentSite.getSiteName(); this.siteUrl = currentSite.getURL(); + this.displaySwitchAccount = !currentSite.isFeatureDisabled('NoDelegate_SwitchAccount'); this.loaded = true; diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index 62df1a889..4c6d5f307 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -67,6 +67,7 @@ export class CoreTextUtilsProvider { { old: /files_sitefiles/g, new: 'AddonPrivateFilesSiteFiles' }, { old: /files_upload/g, new: 'AddonPrivateFilesUpload' }, { old: /_mmaModAssign/g, new: '_AddonModAssign' }, + { old: /_mmaModBigbluebuttonbn/g, new: '_AddonModBBB' }, { old: /_mmaModBook/g, new: '_AddonModBook' }, { old: /_mmaModChat/g, new: '_AddonModChat' }, { old: /_mmaModChoice/g, new: '_AddonModChoice' },