From f4e6613f2c19bfc4d96ae2a58aad98ae7723f1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 20 Jun 2023 15:38:09 +0200 Subject: [PATCH] MOBILE-4009 courses: Remove unused options of prefetch courses --- .../features/course/services/course-helper.ts | 71 +------------------ 1 file changed, 3 insertions(+), 68 deletions(-) diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index f9830defa..3931a5e5e 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -469,12 +469,6 @@ export class CoreCourseHelperProvider { let handlers: CoreCourseOptionsHandlerToDisplay[] = []; let menuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = []; let success = true; - let isGuest = false; - - if (options.canHaveGuestCourses) { - // Check if the user can only access as guest. - isGuest = await this.courseUsesGuestAccess(course.id, siteId); - } // Get the sections and the handlers. subPromises.push(CoreCourse.getSections(course.id, false, true).then((courseSections) => { @@ -483,12 +477,12 @@ export class CoreCourseHelperProvider { return; })); - subPromises.push(CoreCourseOptionsDelegate.getHandlersToDisplay(course, false, isGuest).then((cHandlers) => { + subPromises.push(CoreCourseOptionsDelegate.getHandlersToDisplay(course, false).then((cHandlers) => { handlers = cHandlers; return; })); - subPromises.push(CoreCourseOptionsDelegate.getMenuHandlersToDisplay(course, false, isGuest).then((mHandlers) => { + subPromises.push(CoreCourseOptionsDelegate.getMenuHandlersToDisplay(course, false).then((mHandlers) => { menuHandlers = mHandlers; return; @@ -597,55 +591,6 @@ export class CoreCourseHelperProvider { await CoreDomUtils.confirmDownloadSize(sizeSum, undefined, undefined, undefined, undefined, alwaysConfirm); } - /** - * Check whether a course is accessed using guest access. - * - * @param courseId Course ID. - * @param siteId Site ID. If not defined, current site. - * @returns Promise resolved with boolean: whether course is accessed using guest access. - */ - async courseUsesGuestAccess(courseId: number, siteId?: string): Promise { - try { - try { - // Check if user is enrolled. If enrolled, no guest access. - await CoreCourses.getUserCourse(courseId, false, siteId); - - return 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 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 false; - } - - const info = await CoreCourses.getCourseGuestEnrolmentInfo(method.id); - if (!info.status) { - // Not active, reject. - return false; - } - - // Don't allow guest access if it requires a password. - return !info.passwordrequired; - } catch { - return false; - } - } - /** * Create and return a section for "All sections". * @@ -1215,20 +1160,17 @@ export class CoreCourseHelperProvider { * * @param courses Courses array to prefetch. * @param prefetch Prefetch information to be updated. - * @param options Other options. * @returns Promise resolved when done. */ async prefetchCourses( courses: CoreCourseAnyCourseData[], prefetch: CorePrefetchStatusInfo, - options: CoreCoursePrefetchCoursesOptions = {}, ): Promise { prefetch.loading = true; prefetch.icon = CoreConstants.ICON_DOWNLOADING; prefetch.badge = ''; const prefetchOptions = { - ...options, onProgress: (progress) => { prefetch.badge = progress.count + ' / ' + progress.total; prefetch.badgeA11yText = Translate.instant('core.course.downloadcoursesprogressdescription', progress); @@ -2143,17 +2085,10 @@ export type CoreCoursePrefetchCourseOptions = { isGuest?: boolean; // Whether the user is guest. }; -/** - * Options for prefetch courses function. - */ -export type CoreCoursePrefetchCoursesOptions = { - canHaveGuestCourses?: boolean; // Whether the list of courses can contain courses with only guest access. -}; - /** * Options for confirm and prefetch courses function. */ -export type CoreCourseConfirmPrefetchCoursesOptions = CoreCoursePrefetchCoursesOptions & { +export type CoreCourseConfirmPrefetchCoursesOptions = { onProgress?: (data: CoreCourseCoursesProgress) => void; };