Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBILE-4616 feedback: Workaround for incorrect URLs in page after submit #4216

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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