diff --git a/src/addons/badges/services/handlers/badge-link.ts b/src/addons/badges/services/handlers/badge-link.ts index d41c7047f..52e41e02b 100644 --- a/src/addons/badges/services/handlers/badge-link.ts +++ b/src/addons/badges/services/handlers/badge-link.ts @@ -35,8 +35,8 @@ export class AddonBadgesBadgeLinkHandlerService extends CoreContentLinksHandlerB getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath(`/badges/${params.hash}`, { siteId }); + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath(`/badges/${params.hash}`, { siteId }); }, }]; } diff --git a/src/addons/badges/services/handlers/mybadges-link.ts b/src/addons/badges/services/handlers/mybadges-link.ts index 0dd2f3bfa..52205bfb4 100644 --- a/src/addons/badges/services/handlers/mybadges-link.ts +++ b/src/addons/badges/services/handlers/mybadges-link.ts @@ -36,8 +36,8 @@ export class AddonBadgesMyBadgesLinkHandlerService extends CoreContentLinksHandl */ getActions(): CoreContentLinksAction[] { return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath('/badges', { siteId }); + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath('/badges', { siteId }); }, }]; } diff --git a/src/addons/blog/services/handlers/index-link.ts b/src/addons/blog/services/handlers/index-link.ts index add0dcafb..af292cdc4 100644 --- a/src/addons/blog/services/handlers/index-link.ts +++ b/src/addons/blog/services/handlers/index-link.ts @@ -44,8 +44,8 @@ export class AddonBlogIndexLinkHandlerService extends CoreContentLinksHandlerBas params.tagid ? pageParams['tagId'] = parseInt(params.tagid, 10) : null; return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath('/blog', { params: pageParams, siteId }); + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath('/blog', { params: pageParams, siteId }); }, }]; } diff --git a/src/addons/calendar/services/handlers/view-link.ts b/src/addons/calendar/services/handlers/view-link.ts index 087962300..57dfd0c15 100644 --- a/src/addons/calendar/services/handlers/view-link.ts +++ b/src/addons/calendar/services/handlers/view-link.ts @@ -47,7 +47,7 @@ export class AddonCalendarViewLinkHandlerService extends CoreContentLinksHandler params: Record, ): CoreContentLinksAction[] | Promise { return [{ - action: (siteId?: string): void => { + action: async (siteId?: string): Promise => { if (!params.view || params.view == 'month' || params.view == 'mini' || params.view == 'minithree') { // Monthly view, open the calendar tab. const stateParams: Params = { @@ -59,7 +59,7 @@ export class AddonCalendarViewLinkHandlerService extends CoreContentLinksHandler stateParams.year = momentInstance.year(); stateParams.month = momentInstance.month() + 1; - CoreNavigator.navigateToSitePath('/calendar/index', { + await CoreNavigator.navigateToSitePath('/calendar/index', { params: stateParams, siteId, preferCurrentTab: false, @@ -77,7 +77,7 @@ export class AddonCalendarViewLinkHandlerService extends CoreContentLinksHandler stateParams.month = momentInstance.month() + 1; stateParams.day = momentInstance.date(); - CoreNavigator.navigateToSitePath('/calendar/day', { params: stateParams, siteId }); + await CoreNavigator.navigateToSitePath('/calendar/day', { params: stateParams, siteId }); } else if (params.view == 'upcoming' || params.view == 'upcoming_mini') { // Upcoming view, open the calendar tab. @@ -86,7 +86,7 @@ export class AddonCalendarViewLinkHandlerService extends CoreContentLinksHandler upcoming: true, }; - CoreNavigator.navigateToSitePath('/calendar/index', { + await CoreNavigator.navigateToSitePath('/calendar/index', { params: stateParams, siteId, preferCurrentTab: false, diff --git a/src/addons/competency/services/handlers/competency-link.ts b/src/addons/competency/services/handlers/competency-link.ts index c1ae3bfc5..c804f5618 100644 --- a/src/addons/competency/services/handlers/competency-link.ts +++ b/src/addons/competency/services/handlers/competency-link.ts @@ -38,9 +38,9 @@ export class AddonCompetencyCompetencyLinkHandlerService extends CoreContentLink courseId = courseId || parseInt(params.courseid || params.cid, 10); return [{ - action: (siteId: string): void => { + action: async (siteId: string): Promise => { if (courseId) { - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( `${COURSE_PAGE_NAME}/${courseId}/${ADDON_COMPETENCY_COMPETENCIES_PAGE}`, { params: { userId: params.userid }, @@ -52,7 +52,7 @@ export class AddonCompetencyCompetencyLinkHandlerService extends CoreContentLink } if (params.planid) { - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( `${ADDON_COMPETENCY_LEARNING_PLANS_PAGE}/competencies/${params.planid}`, { params: { userId: params.userid }, diff --git a/src/addons/competency/services/handlers/plan-link.ts b/src/addons/competency/services/handlers/plan-link.ts index 01aa234e3..fbf9e9f35 100644 --- a/src/addons/competency/services/handlers/plan-link.ts +++ b/src/addons/competency/services/handlers/plan-link.ts @@ -35,8 +35,8 @@ export class AddonCompetencyPlanLinkHandlerService extends CoreContentLinksHandl */ getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath( + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath( `${ADDON_COMPETENCY_LEARNING_PLANS_PAGE}/${params.id}`, { siteId }, ); diff --git a/src/addons/competency/services/handlers/plans-link.ts b/src/addons/competency/services/handlers/plans-link.ts index b88e76723..838381e17 100644 --- a/src/addons/competency/services/handlers/plans-link.ts +++ b/src/addons/competency/services/handlers/plans-link.ts @@ -35,8 +35,8 @@ export class AddonCompetencyPlansLinkHandlerService extends CoreContentLinksHand */ getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath( + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath( ADDON_COMPETENCY_LEARNING_PLANS_PAGE, { params: { userId: params.userid }, siteId }, ); diff --git a/src/addons/competency/services/handlers/user-competency-link.ts b/src/addons/competency/services/handlers/user-competency-link.ts index d6ddc5210..47a861baa 100644 --- a/src/addons/competency/services/handlers/user-competency-link.ts +++ b/src/addons/competency/services/handlers/user-competency-link.ts @@ -35,8 +35,8 @@ export class AddonCompetencyUserCompetencyLinkHandlerService extends CoreContent */ getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath( + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath( `${ADDON_COMPETENCY_COMPETENCIES_PAGE}/${params.id}/${ADDON_COMPETENCY_SUMMARY_PAGE}`, { siteId }, ); diff --git a/src/addons/coursecompletion/services/handlers/completionstatus-link.ts b/src/addons/coursecompletion/services/handlers/completionstatus-link.ts index 2c218be0e..96ec5fe40 100644 --- a/src/addons/coursecompletion/services/handlers/completionstatus-link.ts +++ b/src/addons/coursecompletion/services/handlers/completionstatus-link.ts @@ -53,7 +53,7 @@ export class AddonCourseCompletionStatusLinkHandlerService extends CoreContentLi userId, }; - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( '/coursecompletion', { params: pageParams, siteId }, ); diff --git a/src/addons/messages/services/handlers/contact-request-link.ts b/src/addons/messages/services/handlers/contact-request-link.ts index fee8765e5..132832b6a 100644 --- a/src/addons/messages/services/handlers/contact-request-link.ts +++ b/src/addons/messages/services/handlers/contact-request-link.ts @@ -35,8 +35,8 @@ export class AddonMessagesContactRequestLinkHandlerService extends CoreContentLi */ getActions(): CoreContentLinksAction[] | Promise { return [{ - action: (siteId): void => { - CoreNavigator.navigateToSitePath('/messages/contacts', { siteId }); + action: async (siteId): Promise => { + await CoreNavigator.navigateToSitePath('/messages/contacts', { siteId }); }, }]; } diff --git a/src/addons/messages/services/handlers/discussion-link.ts b/src/addons/messages/services/handlers/discussion-link.ts index bd36e065a..2a5573aaa 100644 --- a/src/addons/messages/services/handlers/discussion-link.ts +++ b/src/addons/messages/services/handlers/discussion-link.ts @@ -45,9 +45,9 @@ export class AddonMessagesDiscussionLinkHandlerService extends CoreContentLinksH params: Record, ): CoreContentLinksAction[] | Promise { return [{ - action: (siteId): void => { + action: async (siteId): Promise => { const userId = parseInt(params.id || params.user2, 10); - CoreNavigator.navigateToSitePath(`/messages/discussion/user/${userId}`, { siteId }); + await CoreNavigator.navigateToSitePath(`/messages/discussion/user/${userId}`, { siteId }); }, }]; } diff --git a/src/addons/messages/services/handlers/index-link.ts b/src/addons/messages/services/handlers/index-link.ts index 86bd38432..77ef15ad0 100644 --- a/src/addons/messages/services/handlers/index-link.ts +++ b/src/addons/messages/services/handlers/index-link.ts @@ -38,7 +38,7 @@ export class AddonMessagesIndexLinkHandlerService extends CoreContentLinksHandle getActions(): CoreContentLinksAction[] | Promise { return [{ action: async (siteId): Promise => { - CoreNavigator.navigateToSitePath(AddonMessagesMainMenuHandlerService.PAGE_NAME, { + await CoreNavigator.navigateToSitePath(AddonMessagesMainMenuHandlerService.PAGE_NAME, { siteId, preferCurrentTab: false, }); diff --git a/src/addons/mod/data/services/handlers/approve-link.ts b/src/addons/mod/data/services/handlers/approve-link.ts index f6802bca2..de72ddf00 100644 --- a/src/addons/mod/data/services/handlers/approve-link.ts +++ b/src/addons/mod/data/services/handlers/approve-link.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Params } from '@angular/router'; import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; import { makeSingleton } from '@singletons'; @@ -34,14 +33,14 @@ export class AddonModDataApproveLinkHandlerService extends CoreContentLinksHandl /** * @inheritdoc */ - getActions(siteIds: string[], url: string, params: Params, courseId?: number): CoreContentLinksAction[] { + getActions(siteIds: string[], url: string, params: Record, courseId?: number): CoreContentLinksAction[] { return [{ - action: (siteId): void => { + action: async (siteId): Promise => { const dataId = parseInt(params.d, 10); const entryId = parseInt(params.approve, 10) || parseInt(params.disapprove, 10); const approve = parseInt(params.approve, 10) ? true : false; - AddonModDataHelper.approveOrDisapproveEntry(dataId, entryId, approve, courseId, siteId); + await AddonModDataHelper.approveOrDisapproveEntry(dataId, entryId, approve, courseId, siteId); }, }]; } @@ -49,7 +48,7 @@ export class AddonModDataApproveLinkHandlerService extends CoreContentLinksHandl /** * @inheritdoc */ - async isEnabled(siteId: string, url: string, params: Params): Promise { + async isEnabled(siteId: string, url: string, params: Record): Promise { if (params.d === undefined || (params.approve === undefined && params.disapprove === undefined)) { // Required fields not defined. Cannot treat the URL. return false; diff --git a/src/addons/mod/data/services/handlers/delete-link.ts b/src/addons/mod/data/services/handlers/delete-link.ts index 71b0d8125..d768c995a 100644 --- a/src/addons/mod/data/services/handlers/delete-link.ts +++ b/src/addons/mod/data/services/handlers/delete-link.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Params } from '@angular/router'; import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; import { makeSingleton } from '@singletons'; @@ -33,13 +32,13 @@ export class AddonModDataDeleteLinkHandlerService extends CoreContentLinksHandle /** * @inheritdoc */ - getActions(siteIds: string[], url: string, params: Params, courseId?: number): CoreContentLinksAction[] { + getActions(siteIds: string[], url: string, params: Record, courseId?: number): CoreContentLinksAction[] { return [{ - action: (siteId): void => { + action: async (siteId): Promise => { const dataId = parseInt(params.d, 10); const entryId = parseInt(params.delete, 10); - AddonModDataHelper.showDeleteEntryModal(dataId, entryId, courseId, siteId); + await AddonModDataHelper.showDeleteEntryModal(dataId, entryId, courseId, siteId); }, }]; } @@ -47,7 +46,7 @@ export class AddonModDataDeleteLinkHandlerService extends CoreContentLinksHandle /** * @inheritdoc */ - async isEnabled(siteId: string, url: string, params: Params): Promise { + async isEnabled(siteId: string, url: string, params: Record): Promise { if (params.d === undefined || params.delete === undefined) { // Required fields not defined. Cannot treat the URL. return false; diff --git a/src/addons/mod/data/services/handlers/edit-link.ts b/src/addons/mod/data/services/handlers/edit-link.ts index bcabe86bd..5895ca54a 100644 --- a/src/addons/mod/data/services/handlers/edit-link.ts +++ b/src/addons/mod/data/services/handlers/edit-link.ts @@ -37,7 +37,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB /** * @inheritdoc */ - getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] { + getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ action: async (siteId): Promise => { const modal = await CoreDomUtils.showModalLoading(); @@ -54,7 +54,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB title: module.name, }; - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( `${AddonModDataModuleHandlerService.PAGE_NAME}/${module.course}/${module.id}/edit/${rId}`, { siteId, params: pageParams }, ); @@ -69,7 +69,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB /** * @inheritdoc */ - async isEnabled(siteId: string, url: string, params: Params): Promise { + async isEnabled(siteId: string, url: string, params: Record): Promise { if (params.d === undefined) { // Id not defined. Cannot treat the URL. return false; diff --git a/src/addons/mod/data/services/handlers/show-link.ts b/src/addons/mod/data/services/handlers/show-link.ts index f30535768..fb6c417b5 100644 --- a/src/addons/mod/data/services/handlers/show-link.ts +++ b/src/addons/mod/data/services/handlers/show-link.ts @@ -38,7 +38,7 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB /** * @inheritdoc */ - getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] { + getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ action: async (siteId): Promise => { const modal = await CoreDomUtils.showModalLoading(); @@ -65,7 +65,7 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB pageParams.offset = page || 0; } - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( `${AddonModDataModuleHandlerService.PAGE_NAME}/${module.course}/${module.id}/${rId}`, { siteId, params: pageParams }, ); @@ -80,7 +80,7 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB /** * @inheritdoc */ - async isEnabled(siteId: string, url: string, params: Params): Promise { + async isEnabled(siteId: string, url: string, params: Record): Promise { if (params.d === undefined) { // Id not defined. Cannot treat the URL. return false; diff --git a/src/addons/mod/feedback/services/handlers/analysis-link.ts b/src/addons/mod/feedback/services/handlers/analysis-link.ts index f1b38c0dc..128fc9859 100644 --- a/src/addons/mod/feedback/services/handlers/analysis-link.ts +++ b/src/addons/mod/feedback/services/handlers/analysis-link.ts @@ -53,7 +53,7 @@ export class AddonModFeedbackAnalysisLinkHandlerService extends CoreContentLinks siteId, ); - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}`, { params: { diff --git a/src/addons/mod/feedback/services/handlers/complete-link.ts b/src/addons/mod/feedback/services/handlers/complete-link.ts index 7ae34e1a5..8b1f2ebb6 100644 --- a/src/addons/mod/feedback/services/handlers/complete-link.ts +++ b/src/addons/mod/feedback/services/handlers/complete-link.ts @@ -49,7 +49,7 @@ export class AddonModFeedbackCompleteLinkHandlerService extends CoreContentLinks { siteId, readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE }, ); - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/form`, { params: { diff --git a/src/addons/mod/feedback/services/handlers/print-link.ts b/src/addons/mod/feedback/services/handlers/print-link.ts index bb6d4d099..9196b9e59 100644 --- a/src/addons/mod/feedback/services/handlers/print-link.ts +++ b/src/addons/mod/feedback/services/handlers/print-link.ts @@ -49,7 +49,7 @@ export class AddonModFeedbackPrintLinkHandlerService extends CoreContentLinksHan { siteId, readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE }, ); - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/form`, { params: { diff --git a/src/addons/mod/feedback/services/handlers/show-entries-link.ts b/src/addons/mod/feedback/services/handlers/show-entries-link.ts index 30f3b7c15..e59816bc1 100644 --- a/src/addons/mod/feedback/services/handlers/show-entries-link.ts +++ b/src/addons/mod/feedback/services/handlers/show-entries-link.ts @@ -34,8 +34,8 @@ export class AddonModFeedbackShowEntriesLinkHandlerService extends CoreContentLi */ getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ - action: (siteId: string) => { - AddonModFeedbackHelper.handleShowEntriesLink(params, siteId); + action: async (siteId: string) => { + await AddonModFeedbackHelper.handleShowEntriesLink(params, siteId); }, }]; } diff --git a/src/addons/mod/forum/services/handlers/discussion-link.ts b/src/addons/mod/forum/services/handlers/discussion-link.ts index f00ed9ed5..4ca540b09 100644 --- a/src/addons/mod/forum/services/handlers/discussion-link.ts +++ b/src/addons/mod/forum/services/handlers/discussion-link.ts @@ -36,7 +36,7 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH getActions( siteIds: string[], url: string, - params: Params, + params: Record, courseId?: number, data?: { instance?: string; cmid?: string; postid?: string }, ): CoreContentLinksAction[] | Promise { @@ -46,10 +46,10 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH // However canreply will be false. return [{ - action: (siteId): void => { + action: async (siteId): Promise => { const discussionId = parseInt(params.d, 10); const cmId = data?.cmid && Number(data.cmid); - courseId = courseId || (params.courseid && Number(params.courseid)) || (params.cid && Number(params.cid)); + courseId = Number(courseId || params.courseid || params.cid); const pageParams: Params = { forumId: data?.instance && parseInt(data.instance, 10), @@ -65,7 +65,7 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH pageParams.parent = parseInt(params.parent); } - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( `${AddonModForumModuleHandlerService.PAGE_NAME}/discussion/${discussionId}`, { siteId, params: pageParams }, ); @@ -73,13 +73,6 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH }]; } - /** - * @inheritdoc - */ - async isEnabled(): Promise { - return true; - } - } export const AddonModForumDiscussionLinkHandler = makeSingleton(AddonModForumDiscussionLinkHandlerService); diff --git a/src/addons/mod/forum/services/handlers/post-link.ts b/src/addons/mod/forum/services/handlers/post-link.ts index 8ac9b1143..8376524bc 100644 --- a/src/addons/mod/forum/services/handlers/post-link.ts +++ b/src/addons/mod/forum/services/handlers/post-link.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Params } from '@angular/router'; import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; import { CoreCourse } from '@features/course/services/course'; @@ -40,7 +39,7 @@ export class AddonModForumPostLinkHandlerService extends CoreContentLinksHandler getActions( siteIds: string[], url: string, - params: Params, + params: Record, ): CoreContentLinksAction[] | Promise { return [{ action: async (siteId): Promise => { @@ -69,7 +68,7 @@ export class AddonModForumPostLinkHandlerService extends CoreContentLinksHandler /** * @inheritdoc */ - async isEnabled(siteId: string, url: string, params: Params): Promise { + async isEnabled(siteId: string, url: string, params: Record): Promise { return params.forum !== undefined; } diff --git a/src/addons/mod/h5pactivity/services/handlers/report-link.ts b/src/addons/mod/h5pactivity/services/handlers/report-link.ts index d14933783..a2dc36862 100644 --- a/src/addons/mod/h5pactivity/services/handlers/report-link.ts +++ b/src/addons/mod/h5pactivity/services/handlers/report-link.ts @@ -87,10 +87,10 @@ export class AddonModH5PActivityReportLinkHandlerService extends CoreContentLink * @param courseId Course ID. * @param siteId Site ID. */ - protected openAttemptResults(cmId: number, attemptId: number, courseId: number, siteId: string): void { + protected async openAttemptResults(cmId: number, attemptId: number, courseId: number, siteId: string): Promise { const path = AddonModH5PActivityModuleHandlerService.PAGE_NAME + `/${courseId}/${cmId}/attemptresults/${attemptId}`; - CoreNavigator.navigateToSitePath(path, { + await CoreNavigator.navigateToSitePath(path, { siteId, }); } diff --git a/src/addons/mod/lesson/services/handlers/index-link.ts b/src/addons/mod/lesson/services/handlers/index-link.ts index d1f01f87a..96670924d 100644 --- a/src/addons/mod/lesson/services/handlers/index-link.ts +++ b/src/addons/mod/lesson/services/handlers/index-link.ts @@ -52,16 +52,16 @@ export class AddonModLessonIndexLinkHandlerService extends CoreContentLinksModul courseId?: number, ): CoreContentLinksAction[] | Promise { - courseId = Number(courseId || params.courseid || params.cid); + const cId = Number(courseId || params.courseid || params.cid); return [{ - action: (siteId): void => { + action: async (siteId): Promise => { /* Ignore the pageid param. If we open the lesson player with a certain page and the user hasn't started the lesson, an error is thrown: could not find lesson_timer records. */ if (params.userpassword) { - this.navigateToModuleWithPassword(parseInt(params.id, 10), courseId!, params.userpassword, siteId); + await this.navigateToModuleWithPassword(parseInt(params.id, 10), cId, params.userpassword, siteId); } else { - CoreCourseHelper.navigateToModule(parseInt(params.id, 10), { + await CoreCourseHelper.navigateToModule(parseInt(params.id, 10), { courseId, siteId, }); diff --git a/src/addons/mod/lesson/services/handlers/report-link.ts b/src/addons/mod/lesson/services/handlers/report-link.ts index 469ce28ef..92d432b18 100644 --- a/src/addons/mod/lesson/services/handlers/report-link.ts +++ b/src/addons/mod/lesson/services/handlers/report-link.ts @@ -47,12 +47,12 @@ export class AddonModLessonReportLinkHandlerService extends CoreContentLinksHand params: Record, ): CoreContentLinksAction[] | Promise { return [{ - action: (siteId) => { + action: async (siteId) => { if (!params.action || params.action == 'reportoverview') { // Go to overview. - this.openReportOverview(Number(params.id), Number(params.group), siteId); + await this.openReportOverview(Number(params.id), Number(params.group), siteId); } else if (params.action == 'reportdetail') { - this.openUserRetake(Number(params.id), Number(params.userid), Number(params.try), siteId); + await this.openUserRetake(Number(params.id), Number(params.userid), Number(params.try), siteId); } }, }]; diff --git a/src/addons/mod/quiz/services/handlers/review-link.ts b/src/addons/mod/quiz/services/handlers/review-link.ts index 2adb28518..6b4ea6d38 100644 --- a/src/addons/mod/quiz/services/handlers/review-link.ts +++ b/src/addons/mod/quiz/services/handlers/review-link.ts @@ -49,10 +49,10 @@ export class AddonModQuizReviewLinkHandlerService extends CoreContentLinksHandle const quizId = data?.instance ? Number(data.instance) : undefined; return [{ - action: (siteId): void => { + action: async (siteId): Promise => { const attemptId = parseInt(params.attempt, 10); const page = parseInt(params.page, 10); - AddonModQuizHelper.handleReviewLink(attemptId, page, quizId, siteId); + await AddonModQuizHelper.handleReviewLink(attemptId, page, quizId, siteId); }, }]; } diff --git a/src/addons/mod/scorm/services/handlers/player-link.ts b/src/addons/mod/scorm/services/handlers/player-link.ts index 0f8eba860..2042d98b1 100644 --- a/src/addons/mod/scorm/services/handlers/player-link.ts +++ b/src/addons/mod/scorm/services/handlers/player-link.ts @@ -56,7 +56,7 @@ export class AddonModScormPlayerLinkHandlerService extends CoreContentLinksHandl }; if (cmId) { - CoreCourseHelper.navigateToModule( + await CoreCourseHelper.navigateToModule( cmId, { courseId, @@ -65,7 +65,7 @@ export class AddonModScormPlayerLinkHandlerService extends CoreContentLinksHandl }, ); } else { - CoreCourseHelper.navigateToModuleByInstance( + await CoreCourseHelper.navigateToModuleByInstance( instanceId, 'scorm', { diff --git a/src/addons/mod/wiki/services/handlers/edit-link.ts b/src/addons/mod/wiki/services/handlers/edit-link.ts index 68e3a5140..6a252a795 100644 --- a/src/addons/mod/wiki/services/handlers/edit-link.ts +++ b/src/addons/mod/wiki/services/handlers/edit-link.ts @@ -62,7 +62,7 @@ export class AddonModWikiEditLinkHandlerService extends CoreContentLinksHandlerB section = params.section.replace(/\+/g, ' '); } - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( AddonModWikiModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/edit`, { params: { diff --git a/src/addons/mod/wiki/services/handlers/page-or-map-link.ts b/src/addons/mod/wiki/services/handlers/page-or-map-link.ts index 9b995e3bd..5d6b63360 100644 --- a/src/addons/mod/wiki/services/handlers/page-or-map-link.ts +++ b/src/addons/mod/wiki/services/handlers/page-or-map-link.ts @@ -67,7 +67,7 @@ export class AddonModWikiPageOrMapLinkHandlerService extends CoreContentLinksHan timestamp: Date.now(), })); - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( AddonModWikiModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/page/${hash}`, { params: { diff --git a/src/addons/notifications/services/handlers/notifications-link.ts b/src/addons/notifications/services/handlers/notifications-link.ts index 9d560d165..bc6b8808a 100644 --- a/src/addons/notifications/services/handlers/notifications-link.ts +++ b/src/addons/notifications/services/handlers/notifications-link.ts @@ -35,8 +35,8 @@ export class AddonNotificationsLinkHandlerService extends CoreContentLinksHandle */ getActions(): CoreContentLinksAction[] { return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath(AddonNotificationsMainMenuHandlerService.PAGE_NAME, { + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath(AddonNotificationsMainMenuHandlerService.PAGE_NAME, { preferCurrentTab: false, siteId, }); diff --git a/src/addons/notifications/services/handlers/preferences-link.ts b/src/addons/notifications/services/handlers/preferences-link.ts index a2ab6da07..e91e65d30 100644 --- a/src/addons/notifications/services/handlers/preferences-link.ts +++ b/src/addons/notifications/services/handlers/preferences-link.ts @@ -37,8 +37,11 @@ export class AddonNotificationsPreferencesLinkHandlerService extends CoreContent */ getActions(): CoreContentLinksAction[] { return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath(`preferences/${AddonNotificationsSettingsHandlerService.PAGE_NAME}`, { siteId }); + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath( + `preferences/${AddonNotificationsSettingsHandlerService.PAGE_NAME}`, + { siteId }, + ); }, }]; } diff --git a/src/core/features/contentlinks/classes/module-grade-handler.ts b/src/core/features/contentlinks/classes/module-grade-handler.ts index 424acd2ee..02be1dff5 100644 --- a/src/core/features/contentlinks/classes/module-grade-handler.ts +++ b/src/core/features/contentlinks/classes/module-grade-handler.ts @@ -76,7 +76,7 @@ export class CoreContentLinksModuleGradeHandler extends CoreContentLinksHandlerB const site = await CoreSites.getSite(siteId); if (!params.userid || Number(params.userid) == site.getUserId()) { // No user specified or current user. Navigate to module. - CoreCourseHelper.navigateToModule( + await CoreCourseHelper.navigateToModule( Number(params.id), { courseId: courseIdentifier, @@ -86,10 +86,10 @@ export class CoreContentLinksModuleGradeHandler extends CoreContentLinksHandlerB ); } else if (this.canReview) { // Use the goToReview function. - this.goToReview(url, params, courseIdentifier, siteId); + await this.goToReview(url, params, courseIdentifier, siteId); } else { // Not current user and cannot review it in the app, open it in browser. - site.openInBrowserWithAutoLogin(url); + await site.openInBrowserWithAutoLogin(url); } modal.dismiss(); diff --git a/src/core/features/contentlinks/classes/module-index-handler.ts b/src/core/features/contentlinks/classes/module-index-handler.ts index c3e3086fb..6729d1eaa 100644 --- a/src/core/features/contentlinks/classes/module-index-handler.ts +++ b/src/core/features/contentlinks/classes/module-index-handler.ts @@ -87,8 +87,8 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB const instanceId = parseInt(params[this.instanceIdParam], 10); return [{ - action: (siteId) => { - CoreCourseHelper.navigateToModuleByInstance( + action: async (siteId) => { + await CoreCourseHelper.navigateToModuleByInstance( instanceId, this.modName, { @@ -103,8 +103,8 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB } return [{ - action: (siteId) => { - CoreCourseHelper.navigateToModule( + action: async (siteId) => { + await CoreCourseHelper.navigateToModule( parseInt(params.id, 10), { courseId, diff --git a/src/core/features/contentlinks/classes/module-list-handler.ts b/src/core/features/contentlinks/classes/module-list-handler.ts index 79747f5ab..55798c24f 100644 --- a/src/core/features/contentlinks/classes/module-list-handler.ts +++ b/src/core/features/contentlinks/classes/module-list-handler.ts @@ -60,8 +60,8 @@ export class CoreContentLinksModuleListHandler extends CoreContentLinksHandlerBa ): CoreContentLinksAction[] | Promise { return [{ - action: (siteId): void => { - CoreNavigator.navigateToSitePath('course/' + params.id + '/list-mod-type', { + action: async (siteId): Promise => { + await CoreNavigator.navigateToSitePath('course/' + params.id + '/list-mod-type', { params: { modName: this.modName, title: this.title || Translate.instant('addon.mod_' + this.modName + '.modulenameplural'), diff --git a/src/core/features/contentlinks/services/contentlinks-delegate.ts b/src/core/features/contentlinks/services/contentlinks-delegate.ts index cab896e32..fdad022f5 100644 --- a/src/core/features/contentlinks/services/contentlinks-delegate.ts +++ b/src/core/features/contentlinks/services/contentlinks-delegate.ts @@ -118,7 +118,7 @@ export interface CoreContentLinksAction { * * @param siteId The site ID. */ - action(siteId: string): void; + action(siteId: string): Promise; } /** diff --git a/src/core/features/courses/services/handlers/course-link.ts b/src/core/features/courses/services/handlers/course-link.ts index 9d9353e8e..9903c7ecd 100644 --- a/src/core/features/courses/services/handlers/course-link.ts +++ b/src/core/features/courses/services/handlers/course-link.ts @@ -50,7 +50,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler getActions( siteIds: string[], url: string, - params: Params, + params: Record, ): CoreContentLinksAction[] | Promise { const courseId = parseInt(params.id, 10); const sectionId = params.sectionid ? parseInt(params.sectionid, 10) : undefined; @@ -78,7 +78,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler } return [{ - action: (siteId): void => { + action: async (siteId): Promise => { siteId = siteId || CoreSites.getCurrentSiteId(); if (siteId === CoreSites.getCurrentSiteId()) { // Check if we already are in the course index page. @@ -87,15 +87,15 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler CoreCourse.selectCourseTab('', pageParams); return; - } else { - this.actionOpen(courseId, url, pageParams).catch(() => { - // Ignore errors. - }); } - } else { - // Make the course the new history root (to avoid "loops" in history). - CoreCourseHelper.getAndOpenCourse(courseId, pageParams, siteId); + + await CoreUtils.ignoreErrors(this.actionOpen(courseId, url, pageParams)); + + return; } + + // Make the course the new history root (to avoid "loops" in history). + await CoreCourseHelper.getAndOpenCourse(courseId, pageParams, siteId); }, }]; } @@ -103,7 +103,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler /** * @inheritdoc */ - async isEnabled(siteId: string, url: string, params: Params): Promise { + async isEnabled(siteId: string, url: string, params: Record): Promise { const courseId = parseInt(params.id, 10); if (!courseId) { diff --git a/src/core/features/courses/services/handlers/courses-index-link.ts b/src/core/features/courses/services/handlers/courses-index-link.ts index 4ca26a580..600ad455e 100644 --- a/src/core/features/courses/services/handlers/courses-index-link.ts +++ b/src/core/features/courses/services/handlers/courses-index-link.ts @@ -33,9 +33,9 @@ export class CoreCoursesIndexLinkHandlerService extends CoreContentLinksHandlerB /** * @inheritdoc */ - getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] { + getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ - action: (siteId): void => { + action: async (siteId): Promise => { let pageName = CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME; const pageParams: Params = {}; @@ -46,7 +46,7 @@ export class CoreCoursesIndexLinkHandlerService extends CoreContentLinksHandlerB pageParams.mode = 'all'; } - CoreNavigator.navigateToSitePath(pageName, { params: pageParams, siteId }); + await CoreNavigator.navigateToSitePath(pageName, { params: pageParams, siteId }); }, }]; } diff --git a/src/core/features/courses/services/handlers/dashboard-link.ts b/src/core/features/courses/services/handlers/dashboard-link.ts index b6f6cdee5..f67daebf9 100644 --- a/src/core/features/courses/services/handlers/dashboard-link.ts +++ b/src/core/features/courses/services/handlers/dashboard-link.ts @@ -36,9 +36,9 @@ export class CoreCoursesDashboardLinkHandlerService extends CoreContentLinksHand */ getActions(): CoreContentLinksAction[] | Promise { return [{ - action: (siteId): void => { + action: async (siteId): Promise => { // Use redirect to select the tab. - CoreNavigator.navigateToSitePath( + await CoreNavigator.navigateToSitePath( `/${CoreMainMenuHomeHandlerService.PAGE_NAME}/${CoreDashboardHomeHandlerService.PAGE_NAME}`, { siteId, diff --git a/src/core/features/courses/services/handlers/my-courses-link.ts b/src/core/features/courses/services/handlers/my-courses-link.ts index 23b26f353..8f94249ea 100644 --- a/src/core/features/courses/services/handlers/my-courses-link.ts +++ b/src/core/features/courses/services/handlers/my-courses-link.ts @@ -16,7 +16,6 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; import { makeSingleton } from '@singletons'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; -import { Params } from '@angular/router'; import { CoreNavigator } from '@services/navigator'; /** * Handler to treat links to my courses page. @@ -36,26 +35,22 @@ export class CoreCoursesMyCoursesLinkHandlerService extends CoreContentLinksHand params: Record, ): CoreContentLinksAction[] | Promise { return [{ - action: (): void => { - this.actionOpen({ - sort: params.sort || undefined, - filter: params.filter || undefined, - search: params.search || undefined, - layout: params.layout || undefined, - }); + action: async (): Promise => { + await CoreNavigator.navigate( + '/main/courses/my', + { + params: { + sort: params.sort || undefined, + filter: params.filter || undefined, + search: params.search || undefined, + layout: params.layout || undefined, + }, + }, + ); }, }]; } - /** - * Open my courses. - * - * @param params Params to send to the new page. - */ - protected actionOpen(params: Params): void { - CoreNavigator.navigate('/main/courses/my', { params }); - } - } export const CoreCoursesMyCoursesLinkHandler = makeSingleton(CoreCoursesMyCoursesLinkHandlerService); diff --git a/src/core/features/dataprivacy/components/newrequest/newrequest.ts b/src/core/features/dataprivacy/components/newrequest/newrequest.ts index 7e75e4e6b..fb603eae5 100644 --- a/src/core/features/dataprivacy/components/newrequest/newrequest.ts +++ b/src/core/features/dataprivacy/components/newrequest/newrequest.ts @@ -33,6 +33,7 @@ import { ModalController } from '@singletons'; export class CoreDataPrivacyNewRequestComponent implements OnInit { @Input() accessInfo?: CoreDataPrivacyGetAccessInformationWSResponse; + @Input() createType?: CoreDataPrivacyDataRequestType; message = ''; @@ -65,9 +66,24 @@ export class CoreDataPrivacyNewRequestComponent implements OnInit { return; } - // Just in case only deleting is allowed, change the default type. - if (!this.accessInfo.cancreatedatadownloadrequest && this.accessInfo.cancreatedatadeletionrequest){ - this.typeControl.setValue(CoreDataPrivacyDataRequestType.DATAREQUEST_TYPE_DELETE); + switch (this.createType) { + case CoreDataPrivacyDataRequestType.DATAREQUEST_TYPE_EXPORT: + if (this.accessInfo?.cancreatedatadownloadrequest) { + this.typeControl.setValue(this.createType); + + } + break; + case CoreDataPrivacyDataRequestType.DATAREQUEST_TYPE_DELETE: + if (this.accessInfo?.cancreatedatadeletionrequest) { + this.typeControl.setValue(this.createType); + } + break; + default: + // Just in case only deleting is allowed, change the default type. + if (!this.accessInfo.cancreatedatadownloadrequest && this.accessInfo.cancreatedatadeletionrequest){ + this.typeControl.setValue(CoreDataPrivacyDataRequestType.DATAREQUEST_TYPE_DELETE); + } + break; } } diff --git a/src/core/features/dataprivacy/dataprivacy.module.ts b/src/core/features/dataprivacy/dataprivacy.module.ts index 6891562d4..d0c6a22ce 100644 --- a/src/core/features/dataprivacy/dataprivacy.module.ts +++ b/src/core/features/dataprivacy/dataprivacy.module.ts @@ -19,6 +19,9 @@ import { Routes } from '@angular/router'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CoreDataPrivacyComponentsModule } from './components/components.module'; import { CORE_DATAPRIVACY_PAGE_NAME } from './constants'; +import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreDataPrivacyDataRequestsLinkHandler } from './services/handlers/datarequests-link'; +import { CoreDataPrivacyCreateDataRequestLinkHandler } from './services/handlers/createdatarequest-link'; const routes: Routes = [ { @@ -38,6 +41,8 @@ const routes: Routes = [ multi: true, useValue: () => { CoreUserDelegate.registerHandler(CoreDataPrivacyUserHandler.instance); + CoreContentLinksDelegate.registerHandler(CoreDataPrivacyDataRequestsLinkHandler.instance); + CoreContentLinksDelegate.registerHandler(CoreDataPrivacyCreateDataRequestLinkHandler.instance); }, }, ], diff --git a/src/core/features/dataprivacy/pages/main/main.ts b/src/core/features/dataprivacy/pages/main/main.ts index dfbc8a23f..037f59970 100644 --- a/src/core/features/dataprivacy/pages/main/main.ts +++ b/src/core/features/dataprivacy/pages/main/main.ts @@ -17,9 +17,11 @@ import { CoreDataPrivacyContactDPOComponent } from '@features/dataprivacy/compon import { CoreDataPrivacyNewRequestComponent } from '@features/dataprivacy/components/newrequest/newrequest'; import { CoreDataPrivacy, + CoreDataPrivacyDataRequestType, CoreDataPrivacyGetAccessInformationWSResponse, CoreDataPrivacyRequest, } from '@features/dataprivacy/services/dataprivacy'; +import { CoreNavigator } from '@services/navigator'; import { CoreScreen } from '@services/screen'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; @@ -46,13 +48,33 @@ export class CoreDataPrivacyMainPage implements OnInit { * @inheritdoc */ async ngOnInit(): Promise { - this.fetchContent(); - this.isTablet = CoreScreen.isTablet; this.layoutSubscription = CoreScreen.layoutObservable.subscribe(() => { this.isTablet = CoreScreen.isTablet; }); + + await this.fetchContent(); + + const createType = CoreNavigator.getRouteNumberParam('createType') as CoreDataPrivacyDataRequestType; + + switch (createType) { + case CoreDataPrivacyDataRequestType.DATAREQUEST_TYPE_EXPORT: + if (this.accessInfo?.cancreatedatadownloadrequest) { + this.newRequest(createType); + } + break; + case CoreDataPrivacyDataRequestType.DATAREQUEST_TYPE_DELETE: + if (this.accessInfo?.cancreatedatadeletionrequest) { + this.newRequest(createType); + } + break; + case CoreDataPrivacyDataRequestType.DATAREQUEST_TYPE_OTHERS: + if (this.accessInfo?.cancontactdpo) { + this.contactDPO(); + } + break; + } } /** @@ -111,12 +133,13 @@ export class CoreDataPrivacyMainPage implements OnInit { /** * Open the new request modal. */ - async newRequest(): Promise { + async newRequest(createType?: CoreDataPrivacyDataRequestType): Promise { // Create and show the modal. const succeed = await CoreDomUtils.openModal({ component: CoreDataPrivacyNewRequestComponent, componentProps: { accessInfo: this.accessInfo, + createType, }, }); diff --git a/src/core/features/dataprivacy/services/handlers/createdatarequest-link.ts b/src/core/features/dataprivacy/services/handlers/createdatarequest-link.ts new file mode 100644 index 000000000..eeb9f376c --- /dev/null +++ b/src/core/features/dataprivacy/services/handlers/createdatarequest-link.ts @@ -0,0 +1,62 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { Params } from '@angular/router'; +import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; +import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; +import { CORE_DATAPRIVACY_PAGE_NAME } from '@features/dataprivacy/constants'; +import { CoreNavigator } from '@services/navigator'; +import { makeSingleton } from '@singletons'; +import { CoreDataPrivacy } from '../dataprivacy'; + +/** + * Handler to treat data requests creation links. + */ +@Injectable({ providedIn: 'root' }) +export class CoreDataPrivacyCreateDataRequestLinkHandlerService extends CoreContentLinksHandlerBase { + + name = 'CoreDataPrivacyCreateDataRequestLinkHandler'; + pattern = /\/admin\/tool\/dataprivacy\/createdatarequest\.php.*([?&]type=\d+)/; + + /** + * @inheritdoc + */ + getActions( + siteIds: string[], + url: string, + params: Record, + ): CoreContentLinksAction[] | Promise { + + const pageParams: Params = { + createType: Number(params.type), + }; + + return [{ + action: async (siteId): Promise => { + await CoreNavigator.navigateToSitePath(CORE_DATAPRIVACY_PAGE_NAME, { params: pageParams, siteId }); + }, + }]; + } + + /** + * @inheritdoc + */ + async isEnabled(): Promise { + return await CoreDataPrivacy.isEnabled(); + } + +} + +export const CoreDataPrivacyCreateDataRequestLinkHandler = makeSingleton(CoreDataPrivacyCreateDataRequestLinkHandlerService); diff --git a/src/core/features/dataprivacy/services/handlers/datarequests-link.ts b/src/core/features/dataprivacy/services/handlers/datarequests-link.ts new file mode 100644 index 000000000..ce7fb8d0e --- /dev/null +++ b/src/core/features/dataprivacy/services/handlers/datarequests-link.ts @@ -0,0 +1,52 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; +import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; +import { CORE_DATAPRIVACY_PAGE_NAME } from '@features/dataprivacy/constants'; +import { CoreNavigator } from '@services/navigator'; +import { makeSingleton } from '@singletons'; +import { CoreDataPrivacy } from '../dataprivacy'; + +/** + * Handler to treat data requests links. + */ +@Injectable({ providedIn: 'root' }) +export class CoreDataPrivacyDataRequestsLinkHandlerService extends CoreContentLinksHandlerBase { + + name = 'CoreDataPrivacyDataRequestsLinkHandler'; + pattern = /\/admin\/tool\/dataprivacy\/mydatarequests\.php/; + + /** + * @inheritdoc + */ + getActions(): CoreContentLinksAction[] { + return [{ + action: async (siteId): Promise => { + await CoreNavigator.navigateToSitePath(CORE_DATAPRIVACY_PAGE_NAME, { siteId }); + }, + }]; + } + + /** + * @inheritdoc + */ + async isEnabled(): Promise { + return await CoreDataPrivacy.isEnabled(); + } + +} + +export const CoreDataPrivacyDataRequestsLinkHandler = makeSingleton(CoreDataPrivacyDataRequestsLinkHandlerService); diff --git a/src/core/features/dataprivacy/services/handlers/user.ts b/src/core/features/dataprivacy/services/handlers/user.ts index 60698c03d..679daf47d 100644 --- a/src/core/features/dataprivacy/services/handlers/user.ts +++ b/src/core/features/dataprivacy/services/handlers/user.ts @@ -32,7 +32,7 @@ export class CoreDataPrivacyUserHandlerService implements CoreUserProfileHandler protected pageName = CORE_DATAPRIVACY_PAGE_NAME; type = CoreUserProfileHandlerType.LIST_ACCOUNT_ITEM; - name = 'CoreDataPrivacyDelegate'; + name = 'CoreDataPrivacy'; priority = 100; /** diff --git a/src/core/features/dataprivacy/tests/datarequests-link.test.ts b/src/core/features/dataprivacy/tests/datarequests-link.test.ts new file mode 100644 index 000000000..f757e5d54 --- /dev/null +++ b/src/core/features/dataprivacy/tests/datarequests-link.test.ts @@ -0,0 +1,71 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { CoreDataPrivacyDataRequestsLinkHandler } from '@features/dataprivacy/services/handlers/datarequests-link'; +import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper'; +import { mockSingleton } from '@/testing/utils'; +import { CoreSites } from '@services/sites'; +import { CoreSite } from '@classes/sites/site'; +import { CoreNavigator } from '@services/navigator'; +import { CORE_DATAPRIVACY_PAGE_NAME } from '@features/dataprivacy/constants'; +import { CoreDataPrivacyCreateDataRequestLinkHandler } from '../services/handlers/createdatarequest-link'; +import { CoreDataPrivacy } from '../services/dataprivacy'; + +describe('CoreDataPrivacyDataRequestsLinkHandlerService', () => { + + let site: CoreSite; + + beforeAll(() => { + site = new CoreSite('siteId', 'https://school.edu', ''); + + mockSingleton(CoreDataPrivacy, { + isEnabled: () => Promise.resolve(true), + }); + + CoreContentLinksDelegate.registerHandler(CoreDataPrivacyDataRequestsLinkHandler.instance); + CoreContentLinksDelegate.registerHandler(CoreDataPrivacyCreateDataRequestLinkHandler.instance); + + mockSingleton(CoreNavigator, ['navigateToSitePath']); + mockSingleton(CoreSites, { + isLoggedIn: () => true, + getCurrentSiteId: () => site.id, + getSiteIdsFromUrl: () => Promise.resolve([site.id]), + getSite: () => Promise.resolve(site), + }); + }); + + it('opens data privacy page', async () => { + await CoreContentLinksHelper.handleLink('https://school.edu/admin/tool/dataprivacy/mydatarequests.php'); + + expect(CoreNavigator.navigateToSitePath).toHaveBeenCalledWith(CORE_DATAPRIVACY_PAGE_NAME, { siteId: site.id }); + }); + + it('opens data request modal', async () => { + await CoreContentLinksHelper.handleLink('https://school.edu/admin/tool/dataprivacy/createdatarequest.php?type=1'); + + expect(CoreNavigator.navigateToSitePath).toHaveBeenCalledWith( + CORE_DATAPRIVACY_PAGE_NAME, + { params: { createType: 1 }, siteId: site.id }, + ); + + await CoreContentLinksHelper.handleLink('https://school.edu/admin/tool/dataprivacy/createdatarequest.php?type=3'); + + expect(CoreNavigator.navigateToSitePath).toHaveBeenCalledWith( + CORE_DATAPRIVACY_PAGE_NAME, + { params: { createType: 3 }, siteId: site.id }, + ); + }); + +}); diff --git a/src/core/features/grades/services/handlers/overview-link.ts b/src/core/features/grades/services/handlers/overview-link.ts index f6f36cd5d..2e5b4fad9 100644 --- a/src/core/features/grades/services/handlers/overview-link.ts +++ b/src/core/features/grades/services/handlers/overview-link.ts @@ -36,8 +36,8 @@ export class CoreGradesOverviewLinkHandlerService extends CoreContentLinksHandle */ getActions(): CoreContentLinksAction[] | Promise { return [{ - action: siteId => { - CoreNavigator.navigateToSitePath(GRADES_PAGE_NAME, { siteId }); + action: async siteId => { + await CoreNavigator.navigateToSitePath(GRADES_PAGE_NAME, { siteId }); }, }]; } diff --git a/src/core/features/grades/services/handlers/report-link.ts b/src/core/features/grades/services/handlers/report-link.ts index bd9c75f2e..4ca1ef6a5 100644 --- a/src/core/features/grades/services/handlers/report-link.ts +++ b/src/core/features/grades/services/handlers/report-link.ts @@ -43,11 +43,11 @@ export class CoreGradesReportLinkHandlerService extends CoreContentLinksHandlerB data = data || {}; return [{ - action: (siteId): void => { + action: async (siteId): Promise => { const userId = params.userid ? parseInt(params.userid, 10) : undefined; const moduleId = data?.cmid && parseInt(data.cmid, 10) || undefined; - CoreGradesHelper.goToGrades(courseIdentifier, userId, moduleId, siteId); + await CoreGradesHelper.goToGrades(courseIdentifier, userId, moduleId, siteId); }, }]; } diff --git a/src/core/features/grades/services/handlers/user-link.ts b/src/core/features/grades/services/handlers/user-link.ts index 4741fccd3..b4958326d 100644 --- a/src/core/features/grades/services/handlers/user-link.ts +++ b/src/core/features/grades/services/handlers/user-link.ts @@ -43,11 +43,11 @@ export class CoreGradesUserLinkHandlerService extends CoreContentLinksHandlerBas data = data || {}; return [{ - action: (siteId): void => { + action: async (siteId): Promise => { const userId = params.user ? parseInt(params.user, 10) : undefined; const moduleId = data?.cmid && parseInt(data.cmid, 10) || undefined; - CoreGradesHelper.goToGrades(courseIdentifier, userId, moduleId, siteId); + await CoreGradesHelper.goToGrades(courseIdentifier, userId, moduleId, siteId); }, }]; } diff --git a/src/core/features/reportbuilder/services/handlers/reportbuilder-link.ts b/src/core/features/reportbuilder/services/handlers/reportbuilder-link.ts index 3d24974ba..351f5acf3 100644 --- a/src/core/features/reportbuilder/services/handlers/reportbuilder-link.ts +++ b/src/core/features/reportbuilder/services/handlers/reportbuilder-link.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Params } from '@angular/router'; import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; import { CoreNavigator } from '@services/navigator'; @@ -34,10 +33,13 @@ export class CoreReportBuilderLinkHandlerService extends CoreContentLinksHandler /** * @inheritdoc */ - getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] { + getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ action: async (siteId): Promise => { - CoreNavigator.navigateToSitePath(`${CoreReportBuilderHandlerService.PAGE_NAME}/${params.id || ''}`, { siteId }); + await CoreNavigator.navigateToSitePath( + `${CoreReportBuilderHandlerService.PAGE_NAME}/${params.id || ''}`, + { siteId }, + ); }, }]; } diff --git a/src/core/features/search/services/handlers/global-search-link.ts b/src/core/features/search/services/handlers/global-search-link.ts index fb5d887e7..bf767628a 100644 --- a/src/core/features/search/services/handlers/global-search-link.ts +++ b/src/core/features/search/services/handlers/global-search-link.ts @@ -41,8 +41,8 @@ export class CoreSearchGlobalSearchLinkHandlerService extends CoreContentLinksHa */ getActions(siteIds: string[], url: string, params: Record): CoreContentLinksAction[] { return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath(CORE_SEARCH_PAGE_NAME, { + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath(CORE_SEARCH_PAGE_NAME, { siteId, params: { query: params.q, diff --git a/src/core/features/sitehome/services/handlers/index-link.ts b/src/core/features/sitehome/services/handlers/index-link.ts index 755e14a53..c01a85d2b 100644 --- a/src/core/features/sitehome/services/handlers/index-link.ts +++ b/src/core/features/sitehome/services/handlers/index-link.ts @@ -46,8 +46,8 @@ export class CoreSiteHomeIndexLinkHandlerService extends CoreContentLinksHandler } return [{ - action: (siteId: string): void => { - CoreNavigator.navigateToSitePath( + action: async (siteId: string): Promise => { + await CoreNavigator.navigateToSitePath( `/${CoreMainMenuHomeHandlerService.PAGE_NAME}/${CoreSiteHomeHomeHandlerService.PAGE_NAME}`, { preferCurrentTab: false, diff --git a/src/core/features/tag/services/handlers/index-link.ts b/src/core/features/tag/services/handlers/index-link.ts index ffccbd5ff..9e73ae9ec 100644 --- a/src/core/features/tag/services/handlers/index-link.ts +++ b/src/core/features/tag/services/handlers/index-link.ts @@ -38,7 +38,7 @@ export class CoreTagIndexLinkHandlerService extends CoreContentLinksHandlerBase params: Record, ): CoreContentLinksAction[] | Promise { return [{ - action: (siteId): void => { + action: async (siteId): Promise => { const pageParams = { tagId: parseInt(params.id, 10) || 0, tagName: params.tag || '', @@ -50,11 +50,11 @@ export class CoreTagIndexLinkHandlerService extends CoreContentLinksHandlerBase }; if (!pageParams.tagId && (!pageParams.tagName || !pageParams.collectionId)) { - CoreNavigator.navigateToSitePath('/tag/search', { siteId }); + await CoreNavigator.navigateToSitePath('/tag/search', { siteId }); } else if (pageParams.areaId) { - CoreNavigator.navigateToSitePath('/tag/index-area', { params: pageParams, siteId }); + await CoreNavigator.navigateToSitePath('/tag/index-area', { params: pageParams, siteId }); } else { - CoreNavigator.navigateToSitePath('/tag/index', { params: pageParams, siteId }); + await CoreNavigator.navigateToSitePath('/tag/index', { params: pageParams, siteId }); } }, }]; diff --git a/src/core/features/tag/services/handlers/search-link.ts b/src/core/features/tag/services/handlers/search-link.ts index 18659e6fb..f2c047f24 100644 --- a/src/core/features/tag/services/handlers/search-link.ts +++ b/src/core/features/tag/services/handlers/search-link.ts @@ -38,13 +38,13 @@ export class CoreTagSearchLinkHandlerService extends CoreContentLinksHandlerBase params: Record, ): CoreContentLinksAction[] | Promise { return [{ - action: (siteId): void => { + action: async (siteId): Promise => { const pageParams = { collectionId: parseInt(params.tc, 10) || 0, query: params.query || '', }; - CoreNavigator.navigateToSitePath('/tag/search', { params: pageParams, siteId }); + await CoreNavigator.navigateToSitePath('/tag/search', { params: pageParams, siteId }); }, }]; } diff --git a/src/core/features/user/services/handlers/profile-link.ts b/src/core/features/user/services/handlers/profile-link.ts index 34ddfcf1d..b7b24471f 100644 --- a/src/core/features/user/services/handlers/profile-link.ts +++ b/src/core/features/user/services/handlers/profile-link.ts @@ -52,7 +52,7 @@ export class CoreUserProfileLinkHandlerService extends CoreContentLinksHandlerBa userId, }; - CoreNavigator.navigateToSitePath('/user', { params: pageParams, siteId }); + await CoreNavigator.navigateToSitePath('/user', { params: pageParams, siteId }); }, }]; }