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

Incorrect URLs returned by WS mod_feedback_get_feedbacks_by_courses

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.5
    • Feedback, Web Services
    • MOODLE_405_STABLE
    • MDL-83474-404
    • MDL-83474-405
    • Hide
      1. Log in as admin
      2. Enable/configure web services
      3. Create a token to use the Moodle mobile web service
      4. Create a course
      5. Make a note of the course ID from the URL:

        /course/view.php?id=<COURSEID>
        

      6. Add a Feedback activity to course
        • After submission > Completion message: <insert a picture of an owl>
      7. Run the following command:

        $ curl --silent "<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json" --data "wstoken=<TOKEN>&wsfunction=mod_feedback_get_feedbacks_by_courses&courseids[0]=<COURSEID>" | python -m "json.tool"
        

      8. Copy the image URL from the "page_after_submit" property in the returned structure
      9. Append the following to the image URL and access in browser:

        ?token=<TOKEN>
        

      10. Confirm image is downloaded correctly
      11. Enjoy your owl
      Show
      Log in as admin Enable/configure web services Create a token to use the Moodle mobile web service Create a course Make a note of the course ID from the URL: /course/view.php?id=<COURSEID> Add a Feedback activity to course After submission > Completion message: <insert a picture of an owl> Run the following command: $ curl --silent "<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json" --data "wstoken=<TOKEN>&wsfunction=mod_feedback_get_feedbacks_by_courses&courseids[0]=<COURSEID>" | python -m "json.tool" Copy the image URL from the "page_after_submit" property in the returned structure Append the following to the image URL and access in browser: ?token=<TOKEN> Confirm image is downloaded correctly Enjoy your owl
    • Hide

      Code verified against automated checks.

      Checked MDL-83474 using repository: https://github.com/paulholden/moodle/

      More information about this report

      Built on: Wed Jan 8 02:02:03 PM UTC 2025

      Show
      Code verified against automated checks. Checked MDL-83474 using repository: https://github.com/paulholden/moodle/ MOODLE_404_STABLE (0 errors / 0 warnings) [branch: MDL-83474-404 | CI Job ] MOODLE_405_STABLE (0 errors / 0 warnings) [branch: MDL-83474-405 | CI Job ] main (0 errors / 0 warnings) [branch: MDL-83474 | CI Job ] More information about this report Built on: Wed Jan 8 02:02:03 PM UTC 2025

      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
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

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