Skip to content

Commit

Permalink
Merge pull request #4219 from crazyserver/MOBILE-4616
Browse files Browse the repository at this point in the history
Mobile 4616
  • Loading branch information
alfonso-salces authored Oct 21, 2024
2 parents 8ea6c00 + 1c9d096 commit b88c7ba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
29 changes: 2 additions & 27 deletions src/addons/storagemanager/pages/course-storage/course-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import {
CoreCourseModulePrefetchDelegate,
CoreCourseModulePrefetchHandler } from '@features/course/services/module-prefetch-delegate';
import { CoreCourseAnyCourseData, CoreCourses } from '@features/courses/services/courses';
import { CoreCourses } from '@features/courses/services/courses';
import { AccordionGroupChangeEventDetail } from '@ionic/angular';
import { CoreLoadings } from '@services/loadings';
import { CoreNavigator } from '@services/navigator';
Expand Down Expand Up @@ -612,31 +612,6 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
this.changeDetectorRef.markForCheck();
}

/**
* Get the course object.
*
* @param courseId Course ID.
* @returns Promise resolved with the course object if found.
*/
protected async getCourse(courseId: number): Promise<CoreCourseAnyCourseData | undefined> {
try {
// Check if user is enrolled. If enrolled, no guest access.
return await CoreCourses.getUserCourse(courseId, true);
} 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.
return await CoreCourses.getCourse(courseId);
} catch {
// Ignore errors.
}

return await CoreCourses.getCourseByField('id', this.courseId);

}

/**
* Prefetch the whole course.
*
Expand All @@ -646,7 +621,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy {
event.stopPropagation();
event.preventDefault();

const course = await this.getCourse(this.courseId);
const course = await CoreCourseHelper.getCourseInfo(this.courseId);
if (!course) {
CoreDomUtils.showErrorModal('core.course.errordownloadingcourse', true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { CoreCourse } from '@features/course/services/course';
import { CoreCourseHelper, CoreCourseModuleData } from '@features/course/services/course-helper';
import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses';
import { CoreCourseAnyCourseData } from '@features/courses/services/courses';
import { CoreGradesFormattedRow, CoreGradesFormattedTableRow, CoreGradesHelper } from '@features/grades/services/grades-helper';
import { CoreNetwork } from '@services/network';
import { CoreFilepool } from '@services/filepool';
Expand Down Expand Up @@ -73,7 +73,7 @@ export class CoreCourseModuleSummaryComponent implements OnInit, OnDestroy {
grades?: CoreGradesFormattedRow[];
blog = false; // If blog is available.
isOnline = false; // If the app is online or not.
course?: CoreEnrolledCourseData;
course?: CoreCourseAnyCourseData;
modicon = '';
moduleNameTranslated = '';
isTeacher = false;
Expand Down Expand Up @@ -272,12 +272,7 @@ export class CoreCourseModuleSummaryComponent implements OnInit, OnDestroy {
* Fetch course.
*/
protected async fetchCourse(): Promise<void> {
try {
this.course = await CoreCourses.getUserCourse(this.courseId, true);
} catch {
// The user is not enrolled in the course. Use getCourses to see if it's an admin/manager and can see the course.
this.course = await CoreCourses.getCourse(this.courseId);
}
this.course = await CoreCourseHelper.getCourseInfo(this.courseId);

this.isTeacher = await CoreUtils.ignoreErrors(CoreCourseHelper.guessIsTeacher(this.courseId, this.course), false);
}
Expand Down
24 changes: 24 additions & 0 deletions src/core/features/course/services/course-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,30 @@ export class CoreCourseHelperProvider {
return !!adminOptions[courseId]?.['reports'];
}

/**
* Get the course object whatever the user is enrolled or not..
*
* @param courseId Course ID.
* @returns Promise resolved with the course object if found.
*/
async getCourseInfo(courseId: number): Promise<CoreCourseAnyCourseData | undefined> {
try {
// Check if user is enrolled. If enrolled, no guest access.
return await CoreCourses.getUserCourse(courseId, true);
} 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.
return await CoreCourses.getCourse(courseId);
} catch {
// Ignore errors.
}

return await CoreCourses.getCourseByField('id', courseId);
}

/**
* Get the completion status of a module.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { makeSingleton } from '@singletons';
export class CoreSearchGlobalSearchLinkHandlerService extends CoreContentLinksHandlerBase {

name = 'CoreSearchSearchLinkHandler';
pattern = /\/search\/index\.php.*/;
pattern = /\/search/;

/**
* @inheritdoc
Expand Down

0 comments on commit b88c7ba

Please sign in to comment.