Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-83474

Incorrect URLs returned by WS mod_feedback_get_feedbacks_by_courses

      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:

      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:

      1. Create a Feedback activity.
      2.  Insert an image in After submission > Completion message.
      3. Open the activity and check the URL of the image.  The URL has a /0/ in the path: ".../mod_feedback/page_after_submit/0/...".
      4. Enable web services for mobile devices and create a web service token.
      5. 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'

      6. Find the "pageaftersubmitfiles" in the returned JSON.  See that he URL of the image has the /0/ in the path.
      7. Find the "page_after_submit" in the returned JSON. See that the URL of the image does not have the /0/ in the path.
      8.  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:

      1. 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.
      2. 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.

            pholden Paul Holden
            albert.gasset@moodle.com Albert Gasset
            Albert Gasset Albert Gasset
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 10 minutes
                10m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.