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

Invalid return parameters definition in core_files_get_files Web Service

    XMLWordPrintable

    Details

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

      Inside the Miscellanous category create a course named "Test course: S"

      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 any user that can view the courses in that category 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: Verify that the Miscellaneous category context id is 3

       
      curl 'http://localhost/m/stable_27/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=3&component=&filearea=&itemid=0&filepath=&filename=Miscellaneous&wsfunction=core_files_get_files&wstoken=a94d048ece53cd8284c35af81eebee72' --compressed
      
      

      You should receive a JSON string containing a list of parent directories and also a list including the courses in that category

      Show
      Inside the Miscellanous category create a course named "Test course: S" 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 any user that can view the courses in that category 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: Verify that the Miscellaneous category context id is 3   curl 'http://localhost/m/stable_27/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=3&component=&filearea=&itemid=0&filepath=&filename=Miscellaneous&wsfunction=core_files_get_files&wstoken=a94d048ece53cd8284c35af81eebee72' --compressed You should receive a JSON string containing a list of parent directories and also a list including the courses in that category
    • Affected Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-46586-master

      Description

      filename params should be always PARAM_TEXT because some times files are directories with names that doesn't match the PARAM_FILE rules. This happens mainly when browsing the "files tree" structure that includes category and course names

      For example, browsing the file tree inside a course category may fail if a course with a name "Test course: S" exists

      {"exception":"invalid_response_exception","errorcode":"invalidresponse","message":"Invalid response value detected","debuginfo":"files => Invalid response value detected: filename => Invalid response value detected: Invalid external api response: the value is \"Test course: S\", the server was expecting \"file\" type"}
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jleyva Juan Leyva
              Reporter:
              jleyva Juan Leyva
              Peer reviewer:
              Mark Nelson
              Integrator:
              Dan Poltawski
              Tester:
              Jetha Chan
              Participants:
              Component watchers:
              Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

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