forked from EVOgeek/Vmeda.Online
		
	MOBILE-3966 core: Support new disabled features values
This commit is contained in:
		
							parent
							
								
									101faf20aa
								
							
						
					
					
						commit
						d46bc0601f
					
				| @ -21,6 +21,7 @@ import { | |||||||
|     CoreUserProfileHandlerData, |     CoreUserProfileHandlerData, | ||||||
| } from '@features/user/services/user-delegate'; | } from '@features/user/services/user-delegate'; | ||||||
| import { CoreNavigator } from '@services/navigator'; | import { CoreNavigator } from '@services/navigator'; | ||||||
|  | import { CoreSites } from '@services/sites'; | ||||||
| import { makeSingleton } from '@singletons'; | import { makeSingleton } from '@singletons'; | ||||||
| import { AddonBadges } from '../badges'; | import { AddonBadges } from '../badges'; | ||||||
| 
 | 
 | ||||||
| @ -30,7 +31,7 @@ import { AddonBadges } from '../badges'; | |||||||
| @Injectable({ providedIn: 'root' }) | @Injectable({ providedIn: 'root' }) | ||||||
| export class AddonBadgesUserHandlerService implements CoreUserProfileHandler { | 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; |     priority = 50; | ||||||
|     type = CoreUserDelegateService.TYPE_NEW_PAGE; |     type = CoreUserDelegateService.TYPE_NEW_PAGE; | ||||||
| 
 | 
 | ||||||
| @ -49,11 +50,24 @@ export class AddonBadgesUserHandlerService implements CoreUserProfileHandler { | |||||||
|         courseId: number, |         courseId: number, | ||||||
|         navOptions?: CoreCourseUserAdminOrNavOptionIndexed, |         navOptions?: CoreCourseUserAdminOrNavOptionIndexed, | ||||||
|     ): Promise<boolean> { |     ): Promise<boolean> { | ||||||
|  |         // 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) { |         if (navOptions && navOptions.badges !== undefined) { | ||||||
|             return navOptions.badges; |             return navOptions.badges; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // If we reach here, it means we are opening the user site profile.
 |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -13,8 +13,14 @@ | |||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
| import { Injectable } from '@angular/core'; | 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 { CoreNavigator } from '@services/navigator'; | ||||||
|  | import { CoreSites } from '@services/sites'; | ||||||
| import { makeSingleton } from '@singletons'; | import { makeSingleton } from '@singletons'; | ||||||
| import { AddonBlog } from '../blog'; | import { AddonBlog } from '../blog'; | ||||||
| 
 | 
 | ||||||
| @ -24,7 +30,7 @@ import { AddonBlog } from '../blog'; | |||||||
| @Injectable({ providedIn: 'root' }) | @Injectable({ providedIn: 'root' }) | ||||||
| export class AddonBlogUserHandlerService implements CoreUserProfileHandler { | 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; |     priority = 300; | ||||||
|     type = CoreUserDelegateService.TYPE_NEW_PAGE; |     type = CoreUserDelegateService.TYPE_NEW_PAGE; | ||||||
| 
 | 
 | ||||||
| @ -35,6 +41,27 @@ export class AddonBlogUserHandlerService implements CoreUserProfileHandler { | |||||||
|         return AddonBlog.isPluginEnabled(); |         return AddonBlog.isPluginEnabled(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * @inheritdoc | ||||||
|  |      */ | ||||||
|  |     async isEnabledForContext(context: CoreUserDelegateContext): Promise<boolean> { | ||||||
|  |         // 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 |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|  | |||||||
| @ -24,6 +24,7 @@ import { | |||||||
| } from '@features/user/services/user-delegate'; | } from '@features/user/services/user-delegate'; | ||||||
| import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module'; | import { PARTICIPANTS_PAGE_NAME } from '@features/user/user.module'; | ||||||
| import { CoreNavigator } from '@services/navigator'; | import { CoreNavigator } from '@services/navigator'; | ||||||
|  | import { CoreSites } from '@services/sites'; | ||||||
| import { makeSingleton } from '@singletons'; | import { makeSingleton } from '@singletons'; | ||||||
| import { AddonCompetency } from '../competency'; | import { AddonCompetency } from '../competency'; | ||||||
| 
 | 
 | ||||||
| @ -33,7 +34,7 @@ import { AddonCompetency } from '../competency'; | |||||||
| @Injectable( { providedIn: 'root' }) | @Injectable( { providedIn: 'root' }) | ||||||
| export class AddonCompetencyUserHandlerService implements CoreUserProfileHandler { | 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; |     priority = 900; | ||||||
|     type = CoreUserDelegateService.TYPE_NEW_PAGE; |     type = CoreUserDelegateService.TYPE_NEW_PAGE; | ||||||
|     cacheEnabled = true; |     cacheEnabled = true; | ||||||
| @ -45,6 +46,28 @@ export class AddonCompetencyUserHandlerService implements CoreUserProfileHandler | |||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * @inheritdoc | ||||||
|  |      */ | ||||||
|  |     async isEnabledForContext(context: CoreUserDelegateContext): Promise<boolean> { | ||||||
|  |         // 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 |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ import { AddonCourseCompletion } from '../coursecompletion'; | |||||||
| @Injectable({ providedIn: 'root' }) | @Injectable({ providedIn: 'root' }) | ||||||
| export class AddonCourseCompletionUserHandlerService implements CoreUserProfileHandler { | export class AddonCourseCompletionUserHandlerService implements CoreUserProfileHandler { | ||||||
| 
 | 
 | ||||||
|     name = 'AddonCourseCompletion'; |     name = 'AddonCourseCompletion:viewCompletion'; | ||||||
|     type = CoreUserDelegateService.TYPE_NEW_PAGE; |     type = CoreUserDelegateService.TYPE_NEW_PAGE; | ||||||
|     priority = 200; |     priority = 200; | ||||||
|     cacheEnabled = true; |     cacheEnabled = true; | ||||||
|  | |||||||
| @ -46,11 +46,30 @@ export class AddonPrivateFilesUserHandlerService implements CoreUserProfileHandl | |||||||
|         return AddonPrivateFiles.isPluginEnabled(); |         return AddonPrivateFiles.isPluginEnabled(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * @inheritdoc | ||||||
|  |      */ | ||||||
|  |     async isEnabledForContext(context: CoreUserDelegateContext): Promise<boolean> { | ||||||
|  |         // 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 |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|     async isEnabledForUser(user: CoreUserProfile, context: CoreUserDelegateContext): Promise<boolean> { |     async isEnabledForUser(user: CoreUserProfile, context: CoreUserDelegateContext): Promise<boolean> { | ||||||
|         // 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; |         return user.id == CoreSites.getCurrentSiteUserId() && context === CoreUserDelegateContext.USER_MENU; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -36,7 +36,7 @@ import { makeSingleton } from '@singletons'; | |||||||
| @Injectable({ providedIn: 'root' }) | @Injectable({ providedIn: 'root' }) | ||||||
| export class CoreGradesUserHandlerService implements CoreUserProfileHandler { | 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; |     priority = 400; | ||||||
|     type = CoreUserDelegateService.TYPE_NEW_PAGE; |     type = CoreUserDelegateService.TYPE_NEW_PAGE; | ||||||
|     cacheEnabled = true; |     cacheEnabled = true; | ||||||
| @ -52,6 +52,21 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { | |||||||
|      * @inheritdoc |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|     async isEnabledForContext(context: CoreUserDelegateContext, courseId: number): Promise<boolean> { |     async isEnabledForContext(context: CoreUserDelegateContext, courseId: number): Promise<boolean> { | ||||||
|  |         // 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) { |         if (context === CoreUserDelegateContext.COURSE) { | ||||||
|             return CoreUtils.ignoreErrors(CoreGrades.isPluginEnabledForCourse(courseId), false); |             return CoreUtils.ignoreErrors(CoreGrades.isPluginEnabledForCourse(courseId), false); | ||||||
|         } else { |         } else { | ||||||
|  | |||||||
| @ -68,7 +68,7 @@ | |||||||
|     </ion-list> |     </ion-list> | ||||||
| </ion-content> | </ion-content> | ||||||
| <ion-footer> | <ion-footer> | ||||||
|     <ion-item button lines="full" (click)="switchAccounts($event)" detail="true" class="ion-text-wrap"> |     <ion-item *ngIf="displaySwitchAccount" button lines="full" (click)="switchAccounts($event)" detail="true" class="ion-text-wrap"> | ||||||
|         <ion-icon name="fas-exchange-alt" slot="start" aria-hidden="true"></ion-icon> |         <ion-icon name="fas-exchange-alt" slot="start" aria-hidden="true"></ion-icon> | ||||||
|         <ion-label> |         <ion-label> | ||||||
|             <p class="item-heading">{{ 'core.mainmenu.switchaccount' | translate }}</p> |             <p class="item-heading">{{ 'core.mainmenu.switchaccount' | translate }}</p> | ||||||
|  | |||||||
| @ -49,6 +49,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { | |||||||
|     handlersLoaded = false; |     handlersLoaded = false; | ||||||
|     loaded = false; |     loaded = false; | ||||||
|     user?: CoreUserProfile; |     user?: CoreUserProfile; | ||||||
|  |     displaySwitchAccount = true; | ||||||
| 
 | 
 | ||||||
|     protected subscription!: Subscription; |     protected subscription!: Subscription; | ||||||
| 
 | 
 | ||||||
| @ -60,6 +61,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy { | |||||||
|         this.siteInfo = currentSite.getInfo(); |         this.siteInfo = currentSite.getInfo(); | ||||||
|         this.siteName = currentSite.getSiteName(); |         this.siteName = currentSite.getSiteName(); | ||||||
|         this.siteUrl = currentSite.getURL(); |         this.siteUrl = currentSite.getURL(); | ||||||
|  |         this.displaySwitchAccount = !currentSite.isFeatureDisabled('NoDelegate_SwitchAccount'); | ||||||
| 
 | 
 | ||||||
|         this.loaded = true; |         this.loaded = true; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -67,6 +67,7 @@ export class CoreTextUtilsProvider { | |||||||
|         { old: /files_sitefiles/g, new: 'AddonPrivateFilesSiteFiles' }, |         { old: /files_sitefiles/g, new: 'AddonPrivateFilesSiteFiles' }, | ||||||
|         { old: /files_upload/g, new: 'AddonPrivateFilesUpload' }, |         { old: /files_upload/g, new: 'AddonPrivateFilesUpload' }, | ||||||
|         { old: /_mmaModAssign/g, new: '_AddonModAssign' }, |         { old: /_mmaModAssign/g, new: '_AddonModAssign' }, | ||||||
|  |         { old: /_mmaModBigbluebuttonbn/g, new: '_AddonModBBB' }, | ||||||
|         { old: /_mmaModBook/g, new: '_AddonModBook' }, |         { old: /_mmaModBook/g, new: '_AddonModBook' }, | ||||||
|         { old: /_mmaModChat/g, new: '_AddonModChat' }, |         { old: /_mmaModChat/g, new: '_AddonModChat' }, | ||||||
|         { old: /_mmaModChoice/g, new: '_AddonModChoice' }, |         { old: /_mmaModChoice/g, new: '_AddonModChoice' }, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user