From 71784abfad617f5bde73f0e5d969b1667846d69a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 12 May 2023 14:46:40 +0200 Subject: [PATCH 1/2] MOBILE-4270 filter: Fix text loading forever if get filters failed --- src/core/features/filter/services/filter-helper.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/features/filter/services/filter-helper.ts b/src/core/features/filter/services/filter-helper.ts index 70378e5a0..627518c59 100644 --- a/src/core/features/filter/services/filter-helper.ts +++ b/src/core/features/filter/services/filter-helper.ts @@ -216,7 +216,7 @@ export class CoreFilterHelperProvider { options.filter = true; // We cannot check which filters are available, apply them all. - return CoreFilterDelegate.getEnabledFilters(contextLevel, instanceId); + return await CoreFilterDelegate.getEnabledFilters(contextLevel, instanceId); } const courseId = options.courseId; @@ -239,21 +239,21 @@ export class CoreFilterHelperProvider { // Get all the modules filters with a single call to decrease the number of WS calls. const getFilters = () => this.getCourseModulesContexts(courseId, siteId); - return this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); + return await this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); } else if (contextLevel == 'course') { // If enrolled, get all enrolled courses filters with a single call to decrease number of WS calls. const getFilters = () => this.getCourseContexts(instanceId, siteId); - return this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); + return await this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); } else if (contextLevel == 'block' && courseId && CoreCourse.canGetCourseBlocks(site)) { // Get all the course blocks filters with a single call to decrease number of WS calls. const getFilters = () => this.getBlocksContexts(courseId, siteId); - return this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); + return await this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); } - return CoreFilter.getAvailableInContext(contextLevel, instanceId, siteId); + return await CoreFilter.getAvailableInContext(contextLevel, instanceId, siteId); } catch (error) { this.logger.error('Error getting filters, return an empty array', error, contextLevel, instanceId); From 060e66011b5c2051108c3e1a1fa96795db1c47f5 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 17 May 2023 13:28:21 +0200 Subject: [PATCH 2/2] MOBILE-4270 push: Fix treat undefined customdata in push click handlers --- .../mod/forum/services/handlers/push-click.ts | 10 ++++++++-- .../mod/lesson/services/handlers/push-click.ts | 15 ++++++++++++--- .../mod/quiz/services/handlers/push-click.ts | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/addons/mod/forum/services/handlers/push-click.ts b/src/addons/mod/forum/services/handlers/push-click.ts index fb520cc3e..b0889d412 100644 --- a/src/addons/mod/forum/services/handlers/push-click.ts +++ b/src/addons/mod/forum/services/handlers/push-click.ts @@ -24,6 +24,7 @@ import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { AddonModForumModuleHandlerService } from './module'; +import { isSafeNumber } from '@/core/utils/types'; /** * Handler for forum push notifications clicks. @@ -44,7 +45,8 @@ export class AddonModForumPushClickHandlerService implements CorePushNotificatio async handles(notification: NotificationData): Promise { return CoreUtils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_forum' - && notification.name == 'posts'; + && notification.name == 'posts' + && !!(notification.contexturl || notification.customdata?.postid); } /** @@ -58,13 +60,17 @@ export class AddonModForumPushClickHandlerService implements CorePushNotificatio const data = notification.customdata || {}; const courseId = Number(notification.courseid); const discussionId = Number(contextUrlParams.d || data.discussionid); - const cmId = Number(data.cmid); + const cmId = data.cmid && Number(data.cmid); const pageParams: Params = { forumId: Number(data.instance), cmId, courseId, }; + if (!isSafeNumber(discussionId)) { + return; + } + if (data.postid || contextUrlParams.urlHash) { pageParams.postId = Number(data.postid || contextUrlParams.urlHash.replace('p', '')); } diff --git a/src/addons/mod/lesson/services/handlers/push-click.ts b/src/addons/mod/lesson/services/handlers/push-click.ts index 6d644198b..6a63059be 100644 --- a/src/addons/mod/lesson/services/handlers/push-click.ts +++ b/src/addons/mod/lesson/services/handlers/push-click.ts @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { isSafeNumber } from '@/core/utils/types'; import { Injectable } from '@angular/core'; import { CoreGrades } from '@features/grades/services/grades'; @@ -38,8 +39,12 @@ export class AddonModLessonPushClickHandlerService implements CorePushNotificati * @returns Whether the notification click is handled by this handler. */ async handles(notification: NotificationData): Promise { - if (CoreUtils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_lesson' && - notification.name == 'graded_essay') { + if ( + CoreUtils.isTrueOrOne(notification.notif) && + notification.moodlecomponent == 'mod_lesson' && + notification.name == 'graded_essay' && + notification.customdata?.cmid + ) { return CoreGrades.isPluginEnabledForCourse(Number(notification.courseid), notification.site); } @@ -53,11 +58,15 @@ export class AddonModLessonPushClickHandlerService implements CorePushNotificati * @param notification The notification to check. * @returns Promise resolved when done. */ - handleClick(notification: NotificationData): Promise { + async handleClick(notification: NotificationData): Promise { const data = notification.customdata || {}; const courseId = Number(notification.courseid); const moduleId = Number(data.cmid); + if (!isSafeNumber(moduleId)) { + return; + } + return CoreGradesHelper.goToGrades(courseId, undefined, moduleId, notification.site); } diff --git a/src/addons/mod/quiz/services/handlers/push-click.ts b/src/addons/mod/quiz/services/handlers/push-click.ts index d8c916ed7..58c4d11aa 100644 --- a/src/addons/mod/quiz/services/handlers/push-click.ts +++ b/src/addons/mod/quiz/services/handlers/push-click.ts @@ -22,6 +22,7 @@ import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { AddonModQuiz } from '../quiz'; import { AddonModQuizHelper } from '../quiz-helper'; +import { isSafeNumber } from '@/core/utils/types'; /** * Handler for quiz push notifications clicks. @@ -43,7 +44,8 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification */ async handles(notification: AddonModQuizPushNotificationData): Promise { return CoreUtils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_quiz' && - this.SUPPORTED_NAMES.indexOf(notification.name ?? '') != -1; + this.SUPPORTED_NAMES.indexOf(notification.name ?? '') !== -1 && + !!(notification.customdata?.instance || notification.contexturl); } /** @@ -57,7 +59,12 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification const data = notification.customdata || {}; const courseId = Number(notification.courseid); - if (notification.name == 'submission') { + if ( + notification.name === 'submission' && + data.instance !== undefined && + contextUrlParams.attempt !== undefined && + contextUrlParams.page !== undefined + ) { // A student made a submission, go to view the attempt. return AddonModQuizHelper.handleReviewLink( Number(contextUrlParams.attempt), @@ -69,6 +76,9 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification // Open the activity. const moduleId = Number(contextUrlParams.id); + if (!isSafeNumber(moduleId)) { + return; + } await CoreUtils.ignoreErrors(AddonModQuiz.invalidateContent(moduleId, courseId, notification.site));