Skip to content

Commit 8ea6c00

Browse files
authored
Merge pull request #4216 from albertgasset/MOBILE-4616-feedback
MOBILE-4616 feedback: Workaround for incorrect URLs in page after submit
2 parents 47bb276 + 3749290 commit 8ea6c00

File tree

1 file changed

+26
-0
lines changed
  • src/addons/mod/feedback/components/index

1 file changed

+26
-0
lines changed

src/addons/mod/feedback/components/index/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { CoreCourseContentsPage } from '@features/course/pages/contents/contents
2020
import { IonContent } from '@ionic/angular';
2121
import { CoreGroupInfo, CoreGroups } from '@services/groups';
2222
import { CoreNavigator } from '@services/navigator';
23+
import { CoreSites } from '@services/sites';
2324
import { CoreText } from '@singletons/text';
2425
import { CoreTimeUtils } from '@services/utils/time';
2526
import { CoreUtils } from '@services/utils/utils';
@@ -202,6 +203,8 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
202203
try {
203204
this.feedback = await AddonModFeedback.getFeedback(this.courseId, this.module.id);
204205

206+
await this.fixPageAfterSubmitFileUrls();
207+
205208
this.description = this.feedback.intro;
206209
this.dataRetrieved.emit(this.feedback);
207210

@@ -244,6 +247,29 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
244247
}
245248
}
246249

250+
/**
251+
* Fix incorrect file URLs in page after submit text.
252+
*
253+
* See bug MDL-83474.
254+
*/
255+
protected async fixPageAfterSubmitFileUrls(): Promise<void> {
256+
const site = await CoreSites.getSite(this.siteId);
257+
258+
if (!site.isVersionGreaterEqualThan('4.2')
259+
|| !this.feedback?.page_after_submit
260+
|| !this.feedback.pageaftersubmitfiles) {
261+
return;
262+
}
263+
264+
// Replace file URLs that do not have the /0/ in the path.
265+
// Subdirectories are not allowed in this file area, so the sets of correct and incorrect URLs will never overlap.
266+
for (const file of this.feedback.pageaftersubmitfiles) {
267+
const incorrectUrl = file.fileurl.replace('/page_after_submit/0/', '/page_after_submit/');
268+
const incorrectUrlRegex = new RegExp(CoreText.escapeForRegex(incorrectUrl), 'g');
269+
this.feedback.page_after_submit = this.feedback.page_after_submit.replace(incorrectUrlRegex, file.fileurl);
270+
}
271+
}
272+
247273
/**
248274
* Convenience function to get feedback overview data.
249275
*/

0 commit comments

Comments
 (0)