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

External function core_user_external::add_user_private_files is broken

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. As admin, enable "Mobile services": Plugins ► Web Services ► Mobile
      2. Create a Token for the student user:
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      3. Upload a file to get a draft item id
        curl -i -F filedata=@/Users/juanleyvadelgado/Documents/mypdf.pdf “http://localhost/m/stable_master/webservice/upload.php?token=ffbe3a3002f235bf9d01fd9369e10b66&filearea=draft"
      4. Next, you can do a CURL REST call simulating a WS client with the student user.
        • You need to replace the wstoken, draftid (with the itemid you got in the previous curl call) and the URL of your moodle instance

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data ‘draftid=14&wsfunction=core_user_add_user_private_files&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool"

      5. Go to Moodle web version and check that the file was successfully uploaded to the user private files area.
      6. Now, upload a different pdf but we the same name
      7. Call the WS again but using the new draft id
      8. Check that the pdf in Moodle was updated and now you see under the same name the new document
      9. Now, upload a different document but not calling to the WS to move the files
      10. Using the draft item id you got in the previous step, upload a new different document, for doing this you must add an extra parameter to the curl call that upload files, after &filearea=draft add &itemid=draftitemid
      11. Call the WS now with the itemid, and check that both new files were added to my private files
      Show
      As admin, enable "Mobile services": Plugins ► Web Services ► Mobile Create a Token for the student user: Click on Site administration ► Plugins ► Web services ► Manage tokens Upload a file to get a draft item id curl -i -F filedata=@/Users/juanleyvadelgado/Documents/mypdf.pdf “ http://localhost/m/stable_master/webservice/upload.php?token=ffbe3a3002f235bf9d01fd9369e10b66&filearea=draft " Next, you can do a CURL REST call simulating a WS client with the student user. You need to replace the wstoken, draftid (with the itemid you got in the previous curl call) and the URL of your moodle instance curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data ‘draftid=14&wsfunction=core_user_add_user_private_files&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool" Go to Moodle web version and check that the file was successfully uploaded to the user private files area. Now, upload a different pdf but we the same name Call the WS again but using the new draft id Check that the pdf in Moodle was updated and now you see under the same name the new document Now, upload a different document but not calling to the WS to move the files Using the draft item id you got in the previous step, upload a new different document, for doing this you must add an extra parameter to the curl call that upload files, after &filearea=draft add &itemid=draftitemid Call the WS now with the itemid, and check that both new files were added to my private files
    • Affected Branches:
      MOODLE_31_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-54869-master

      Description

      I was trying to use the WebService core_user_add_user_private_files to upload a file to private files in the Mobile app, but I got an error 500.

      The function uses file_save_draft_area_files but it doesn't include the file lib/filelib.php.

      Another thing I noticed is that, once this is fixed, this WebService deletes what the user has in private files and stores what's in the draft area. AFAIK this means we can't use it to upload a new file unless we upload ALL the private files to the draft area along with the new file. Am I wrong? Was this intended when the WS was created?

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  11/Jul/16