diff --git a/src/core/course/pages/section/section.ts b/src/core/course/pages/section/section.ts index b33a10b48..a0b293a74 100644 --- a/src/core/course/pages/section/section.ts +++ b/src/core/course/pages/section/section.ts @@ -122,11 +122,15 @@ export class CoreCourseSectionPage implements OnDestroy { */ protected loadData(refresh?: boolean): Promise { // First of all, get the course because the data might have changed. - return this.coursesProvider.getUserCourse(this.course.id).then((course) => { + return this.coursesProvider.getUserCourse(this.course.id).catch(() => { + // Error getting the course, probably guest access. + }).then((course) => { const promises = []; let promise; - this.course = course; + if (course) { + this.course = course; + } // Get the completion status. if (this.course.enablecompletion === false) { diff --git a/src/core/courses/pages/course-preview/course-preview.html b/src/core/courses/pages/course-preview/course-preview.html index 0e9916dd7..c01bec3db 100644 --- a/src/core/courses/pages/course-preview/course-preview.html +++ b/src/core/courses/pages/course-preview/course-preview.html @@ -10,7 +10,7 @@ - +

{{course.categoryname}}

@@ -41,24 +41,15 @@

{{ 'core.courses.notenrollable' | translate }}

-
+

{{ 'core.course.downloadcourse' | translate }}

- +

{{ 'core.course.contents' | translate }}

- - - -

{{ handler.data.title | translate }}

-
-
- - -
diff --git a/src/core/courses/pages/course-preview/course-preview.ts b/src/core/courses/pages/course-preview/course-preview.ts index 966148945..81a97cb18 100644 --- a/src/core/courses/pages/course-preview/course-preview.ts +++ b/src/core/courses/pages/course-preview/course-preview.ts @@ -36,8 +36,7 @@ import { CoreCourseHelperProvider } from '../../../course/providers/helper'; export class CoreCoursesCoursePreviewPage implements OnDestroy { course: any; isEnrolled: boolean; - handlersShouldBeShown = true; - handlersLoaded: boolean; + canAccessCourse = true; component = 'CoreCoursesCoursePreview'; selfEnrolInstances: any[] = []; paypalEnabled: boolean; @@ -206,19 +205,17 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { // Success retrieving the course, we can assume the user has permissions to view it. this.course.fullname = course.fullname || this.course.fullname; this.course.summary = course.summary || this.course.summary; - - return this.loadCourseHandlers(refresh, false); + this.canAccessCourse = true; }).catch(() => { // The user is not an admin/manager. Check if we can provide guest access to the course. return this.canAccessAsGuest().then((passwordRequired) => { if (!passwordRequired) { - return this.loadCourseHandlers(refresh, true); + this.canAccessCourse = true; } else { - return Promise.reject(null); + this.canAccessCourse = false; } }).catch(() => { - this.course._handlers = []; - this.handlersShouldBeShown = false; + this.canAccessCourse = false; }); }); }).finally(() => { @@ -226,25 +223,11 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { }); } - /** - * Load course nav handlers. - * - * @param {boolean} refresh Whether the user is refreshing the data. - * @param {boolean} guest Whether it's guest access. - */ - protected loadCourseHandlers(refresh: boolean, guest: boolean): Promise { - return this.courseOptionsDelegate.getHandlersToDisplay(this.course, refresh, guest, true).then((handlers) => { - this.course._handlers = handlers; - this.handlersShouldBeShown = true; - this.handlersLoaded = true; - }); - } - /** * Open the course. */ openCourse(): void { - if (!this.handlersShouldBeShown) { + if (!this.canAccessCourse) { // Course cannot be opened. return; } @@ -435,8 +418,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { * Prefetch the course. */ prefetchCourse(): void { - this.courseHelper.confirmAndPrefetchCourse(this.prefetchCourseData, this.course, undefined, this.course._handlers) - .catch((error) => { + this.courseHelper.confirmAndPrefetchCourse(this.prefetchCourseData, this.course).catch((error) => { if (!this.pageDestroyed) { this.domUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true); }