-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.5
Feedback uses a itemid of 0 for files in the file area "page_after_submit", and it expects the itemid to be present in the URL, otherwise pluginfile.php does not find the file. The plugin passes an itemid of 0 to function file_rewrite_pluginfile_urls to achieve this. When the text is formatted by the exporter, the URLs are processed by \core_external\util::format_text, which does not put the itemid of 0 in the URL. See the difference in both functions:
- https://github.com/moodle/moodle/blob/v4.5.0/lib/filelib.php#L518
- https://github.com/moodle/moodle/blob/v4.5.0/lib/external/classes/util.php#L546
Before 4.2, the function used by the exporter was external_format_text, which called file_rewrite_pluginfile_urls, so both functions behaved the same way.
Steps to reproduce:
- Create a Feedback activity.
- Insert an image in After submission > Completion message.
- Open the activity and check the URL of the image. The URL has a /0/ in the path: ".../mod_feedback/page_after_submit/0/...".
- Enable web services for mobile devices and create a web service token.
- Call service {{mod_feedback_get_feedbacks_by_courses}} with the id of the course (replace WWWROOT, COURSEID and WSTOKEN):
curl 'WWWROOT/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_feedback_get_feedbacks_by_courses&courseids[0]=COURSEID&wstoken=WSTOKEN'
- Find the "pageaftersubmitfiles" in the returned JSON. See that he URL of the image has the /0/ in the path.
- Find the "page_after_submit" in the returned JSON. See that the URL of the image does not have the /0/ in the path.
- Add a "token" parameter to the URL without the /0/ and try to download it in a browser or using curl. It fails with error "Sorry, the requested file could not be found"
Possible solutions:
- Change \core_external\util::format_text to behave the same as file_rewrite_pluginfile_urls when itemid is 0. This potentially affects other code, but it will prevent similar bugs in the future.
- Remove the itemid of 0 from all the URLs of "page_after_submit", by passing null instead of 0 to file_rewrite_pluginfile_urls, and changing {{pluginfile.php }}accordingly.