Skip to content

Commit

Permalink
Merge pull request #4216 from albertgasset/MOBILE-4616-feedback
Browse files Browse the repository at this point in the history
MOBILE-4616 feedback: Workaround for incorrect URLs in page after submit
  • Loading branch information
crazyserver authored Oct 17, 2024
2 parents 47bb276 + 3749290 commit 8ea6c00
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/addons/mod/feedback/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<void> {
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.
*/
Expand Down

0 comments on commit 8ea6c00

Please sign in to comment.