forked from EVOgeek/Vmeda.Online
		
	MOBILE-4009 courses: Pass isGuest param on navigation
This commit is contained in:
		
							parent
							
								
									f4e6613f2c
								
							
						
					
					
						commit
						e8e2b94b15
					
				| @ -25,6 +25,7 @@ import { | |||||||
|     CoreCourseModulePrefetchDelegate, |     CoreCourseModulePrefetchDelegate, | ||||||
|     CoreCourseModulePrefetchHandler } from '@features/course/services/module-prefetch-delegate'; |     CoreCourseModulePrefetchHandler } from '@features/course/services/module-prefetch-delegate'; | ||||||
| import { CoreCourses } from '@features/courses/services/courses'; | import { CoreCourses } from '@features/courses/services/courses'; | ||||||
|  | import { CoreCoursesHelper } from '@features/courses/services/courses-helper'; | ||||||
| import { CoreNavigator } from '@services/navigator'; | import { CoreNavigator } from '@services/navigator'; | ||||||
| import { CoreSites } from '@services/sites'; | import { CoreSites } from '@services/sites'; | ||||||
| import { CoreDomUtils } from '@services/utils/dom'; | import { CoreDomUtils } from '@services/utils/dom'; | ||||||
| @ -103,7 +104,9 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { | |||||||
|             this.title = Translate.instant('core.sitehome.sitehome'); |             this.title = Translate.instant('core.sitehome.sitehome'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest'); |         this.isGuest = CoreNavigator.getRouteBooleanParam('isGuest') ?? | ||||||
|  |             (await CoreCourseHelper.courseUsesGuestAccessInfo(this.courseId)).guestAccess; | ||||||
|  | 
 | ||||||
|         this.initialSectionId = CoreNavigator.getRouteNumberParam('sectionId'); |         this.initialSectionId = CoreNavigator.getRouteNumberParam('sectionId'); | ||||||
| 
 | 
 | ||||||
|         this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); |         this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); | ||||||
|  | |||||||
| @ -75,6 +75,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { | |||||||
|     @Input() initialSectionId?: number; // The section to load first (by ID).
 |     @Input() initialSectionId?: number; // The section to load first (by ID).
 | ||||||
|     @Input() initialSectionNumber?: number; // The section to load first (by number).
 |     @Input() initialSectionNumber?: number; // The section to load first (by number).
 | ||||||
|     @Input() moduleId?: number; // The module ID to scroll to. Must be inside the initial selected section.
 |     @Input() moduleId?: number; // The module ID to scroll to. Must be inside the initial selected section.
 | ||||||
|  |     @Input() isGuest?: boolean; // If user is accessing as a guest.
 | ||||||
| 
 | 
 | ||||||
|     // eslint-disable-next-line @typescript-eslint/no-explicit-any
 |     // eslint-disable-next-line @typescript-eslint/no-explicit-any
 | ||||||
|     @ViewChildren(CoreDynamicComponent) dynamicComponents?: QueryList<CoreDynamicComponent<any>>; |     @ViewChildren(CoreDynamicComponent) dynamicComponents?: QueryList<CoreDynamicComponent<any>>; | ||||||
| @ -462,6 +463,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { | |||||||
|                 params: { |                 params: { | ||||||
|                     title: this.course.fullname, |                     title: this.course.fullname, | ||||||
|                     sectionId: selectedId, |                     sectionId: selectedId, | ||||||
|  |                     isGuest: this.isGuest, | ||||||
|                 }, |                 }, | ||||||
|             }, |             }, | ||||||
|         ); |         ); | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ | |||||||
| 
 | 
 | ||||||
|     <core-loading [hideUntil]="dataLoaded && !updatingData"> |     <core-loading [hideUntil]="dataLoaded && !updatingData"> | ||||||
|         <core-course-format [course]="course" [sections]="sections" [initialSectionId]="sectionId" [initialSectionNumber]="sectionNumber" |         <core-course-format [course]="course" [sections]="sections" [initialSectionId]="sectionId" [initialSectionNumber]="sectionNumber" | ||||||
|             [moduleId]="moduleId" class="core-course-format-{{course.format}}" *ngIf="dataLoaded && sections"> |             [moduleId]="moduleId" class="core-course-format-{{course.format}}" *ngIf="dataLoaded && sections" [isGuest]="isGuest"> | ||||||
|         </core-course-format> |         </core-course-format> | ||||||
|     </core-loading> |     </core-loading> | ||||||
| </ion-content> | </ion-content> | ||||||
|  | |||||||
| @ -64,6 +64,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon | |||||||
|     moduleId?: number; |     moduleId?: number; | ||||||
|     displayEnableDownload = false; |     displayEnableDownload = false; | ||||||
|     displayRefresher = false; |     displayRefresher = false; | ||||||
|  |     isGuest?: boolean; | ||||||
| 
 | 
 | ||||||
|     protected formatOptions?: Record<string, unknown>; |     protected formatOptions?: Record<string, unknown>; | ||||||
|     protected completionObserver?: CoreEventObserver; |     protected completionObserver?: CoreEventObserver; | ||||||
| @ -92,6 +93,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon | |||||||
|         this.sectionId = CoreNavigator.getRouteNumberParam('sectionId'); |         this.sectionId = CoreNavigator.getRouteNumberParam('sectionId'); | ||||||
|         this.sectionNumber = CoreNavigator.getRouteNumberParam('sectionNumber'); |         this.sectionNumber = CoreNavigator.getRouteNumberParam('sectionNumber'); | ||||||
|         this.moduleId = CoreNavigator.getRouteNumberParam('moduleId'); |         this.moduleId = CoreNavigator.getRouteNumberParam('moduleId'); | ||||||
|  |         this.isGuest = CoreNavigator.getRouteBooleanParam('isGuest'); | ||||||
| 
 | 
 | ||||||
|         this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => { |         this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => { | ||||||
|             if (this.modulesHaveCompletion) { |             if (this.modulesHaveCompletion) { | ||||||
|  | |||||||
| @ -143,7 +143,9 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy { | |||||||
| 
 | 
 | ||||||
|         this.firstTabName = CoreNavigator.getRouteParam('selectedTab'); |         this.firstTabName = CoreNavigator.getRouteParam('selectedTab'); | ||||||
|         this.module = CoreNavigator.getRouteParam<CoreCourseModuleData>('module'); |         this.module = CoreNavigator.getRouteParam<CoreCourseModuleData>('module'); | ||||||
|         this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest'); |         this.isGuest = CoreNavigator.getRouteBooleanParam('isGuest') ?? | ||||||
|  |             (!!this.course && (await CoreCourseHelper.courseUsesGuestAccessInfo(this.course.id)).guestAccess); | ||||||
|  | 
 | ||||||
|         this.modNavOptions = CoreNavigator.getRouteParam<CoreNavigationOptions>('modNavOptions'); |         this.modNavOptions = CoreNavigator.getRouteParam<CoreNavigationOptions>('modNavOptions'); | ||||||
|         this.openModule = CoreNavigator.getRouteBooleanParam('openModule') ?? true; // If false, just scroll to module.
 |         this.openModule = CoreNavigator.getRouteBooleanParam('openModule') ?? true; // If false, just scroll to module.
 | ||||||
|         if (!this.modNavOptions) { |         if (!this.modNavOptions) { | ||||||
|  | |||||||
| @ -591,6 +591,57 @@ export class CoreCourseHelperProvider { | |||||||
|         await CoreDomUtils.confirmDownloadSize(sizeSum, undefined, undefined, undefined, undefined, alwaysConfirm); |         await CoreDomUtils.confirmDownloadSize(sizeSum, undefined, undefined, undefined, undefined, alwaysConfirm); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Check whether a course is accessed using guest access and if requires password to enter. | ||||||
|  |      * | ||||||
|  |      * @param courseId Course ID. | ||||||
|  |      * @param siteId Site ID. If not defined, current site. | ||||||
|  |      * @returns Promise resolved with guestAccess and passwordRequired booleans. | ||||||
|  |      */ | ||||||
|  |     async courseUsesGuestAccessInfo( | ||||||
|  |         courseId: number, | ||||||
|  |         siteId?: string, | ||||||
|  |     ): Promise<{guestAccess: boolean; passwordRequired?: boolean}> { | ||||||
|  |         try { | ||||||
|  |             try { | ||||||
|  |                 // Check if user is enrolled. If enrolled, no guest access.
 | ||||||
|  |                 await CoreCourses.getUserCourse(courseId, false, siteId); | ||||||
|  | 
 | ||||||
|  |                 return { guestAccess: false }; | ||||||
|  |             } catch { | ||||||
|  |                 // Ignore errors.
 | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             try { | ||||||
|  |                 // The user is not enrolled in the course. Use getCourses to see if it's an admin/manager and can see the course.
 | ||||||
|  |                 await CoreCourses.getCourse(courseId, siteId); | ||||||
|  | 
 | ||||||
|  |                 return { guestAccess: false }; | ||||||
|  |             } catch { | ||||||
|  |                 // Ignore errors.
 | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             // Check if guest access is enabled.
 | ||||||
|  |             const enrolmentMethods = await CoreCourses.getCourseEnrolmentMethods(courseId, siteId); | ||||||
|  | 
 | ||||||
|  |             const method = enrolmentMethods.find((method) => method.type === 'guest'); | ||||||
|  | 
 | ||||||
|  |             if (!method) { | ||||||
|  |                 return { guestAccess: false }; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             const info = await CoreCourses.getCourseGuestEnrolmentInfo(method.id); | ||||||
|  | 
 | ||||||
|  |             // Don't allow guest access if it requires a password and it's available.
 | ||||||
|  |             return { | ||||||
|  |                 guestAccess: !!info.status && !info.passwordrequired, | ||||||
|  |                 passwordRequired: info.passwordrequired, | ||||||
|  |             }; | ||||||
|  |         } catch { | ||||||
|  |             return { guestAccess: false }; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Create and return a section for "All sections". |      * Create and return a section for "All sections". | ||||||
|      * |      * | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user