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

Invalid $itemid conversion in core_files_get_files Web Service

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.7.1
    • Fix Version/s: 2.6.6, 2.7.3
    • Component/s: Web Services
    • Labels:
    • Testing Instructions:
      Hide

      Upload a couple of files to your private file area

      Enable "Mobile services" Plugins / Web Services / Services

      Create a new service in the same page, include in that service the function: core_files_get_files

      Create a Token for the same user you used to upload files to your private files area and for the service you created before:
      Click on Site administration ► Plugins ► Web services ► Manage tokens
      Click add, select user and service

      Next, you can do a CURL REST call simulating a WS client request:

      You need to change:

      • The URL pointing to your Moodle site
      • The wstoken value: The one you created
      • The contextid: The context_user instance id for the user you created the token

      curl 'http://localhost/moodlebugs/webservice/rest/server.php?moodlewsrestformat=json' -H 'Pragma: no-cache' -H 'Origin: file://' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, /; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data 'contextid=5&component=user&filearea=private&itemid=0&filepath=&filename=&wsfunction=core_files_get_files&wstoken=1c64c9f95d565cab6e1285e75356ce35' --compressed

      You should receive a JSON string containing a list of the files in your private area

      Show
      Upload a couple of files to your private file area Enable "Mobile services" Plugins / Web Services / Services Create a new service in the same page, include in that service the function: core_files_get_files Create a Token for the same user you used to upload files to your private files area and for the service you created before: Click on Site administration ► Plugins ► Web services ► Manage tokens Click add, select user and service Next, you can do a CURL REST call simulating a WS client request: You need to change: The URL pointing to your Moodle site The wstoken value: The one you created The contextid: The context_user instance id for the user you created the token curl 'http://localhost/moodlebugs/webservice/rest/server.php?moodlewsrestformat=json' -H 'Pragma: no-cache' -H 'Origin: file:// ' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: es,en;q=0.8,de-DE;q=0.6,de;q=0.4' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1798.0 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, / ; q=0.01' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data 'contextid=5&component=user&filearea=private&itemid=0&filepath=&filename=&wsfunction=core_files_get_files&wstoken=1c64c9f95d565cab6e1285e75356ce35' --compressed You should receive a JSON string containing a list of the files in your private area
    • Affected Branches:
      MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-46587-master

      Description

      $itemid can be legitimately 0 in some cases (like user private files area) the current core_files_get_files external function assign "null" to that value in case if empty

      This makes that this function can't be used to retrieve user private area files

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  10/Nov/14