From 374929008e0d009bc8e559885a98a894f95e9e31 Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Thu, 17 Oct 2024 15:29:47 +0200 Subject: [PATCH] MOBILE-4616 feedback: Workaround for incorrect URLs in page after submit --- .../mod/feedback/components/index/index.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/addons/mod/feedback/components/index/index.ts b/src/addons/mod/feedback/components/index/index.ts index d1d020f8c..c76f6b961 100644 --- a/src/addons/mod/feedback/components/index/index.ts +++ b/src/addons/mod/feedback/components/index/index.ts @@ -20,6 +20,7 @@ import { CoreCourseContentsPage } from '@features/course/pages/contents/contents import { IonContent } from '@ionic/angular'; import { CoreGroupInfo, CoreGroups } from '@services/groups'; import { CoreNavigator } from '@services/navigator'; +import { CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreUtils } from '@services/utils/utils'; @@ -202,6 +203,8 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity try { this.feedback = await AddonModFeedback.getFeedback(this.courseId, this.module.id); + await this.fixPageAfterSubmitFileUrls(); + this.description = this.feedback.intro; this.dataRetrieved.emit(this.feedback); @@ -244,6 +247,29 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity } } + /** + * Fix incorrect file URLs in page after submit text. + * + * See bug MDL-83474. + */ + protected async fixPageAfterSubmitFileUrls(): Promise { + const site = await CoreSites.getSite(this.siteId); + + if (!site.isVersionGreaterEqualThan('4.2') + || !this.feedback?.page_after_submit + || !this.feedback.pageaftersubmitfiles) { + return; + } + + // Replace file URLs that do not have the /0/ in the path. + // Subdirectories are not allowed in this file area, so the sets of correct and incorrect URLs will never overlap. + for (const file of this.feedback.pageaftersubmitfiles) { + const incorrectUrl = file.fileurl.replace('/page_after_submit/0/', '/page_after_submit/'); + const incorrectUrlRegex = new RegExp(CoreText.escapeForRegex(incorrectUrl), 'g'); + this.feedback.page_after_submit = this.feedback.page_after_submit.replace(incorrectUrlRegex, file.fileurl); + } + } + /** * Convenience function to get feedback overview data. */