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

H5P player should accept webservice/pluginfile.php and tokenpluginfile.php URLs

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.8, 3.9
    • Fix Version/s: 3.9
    • Component/s: H5P
    • Testing Instructions:
      Hide

      Notice: You need to be able to use CURL in a console.

      Setup

      1. Login as admin.
      2. Create a course "Course 1".
      3. Ensure webservices is enabled (Site Administration > Advanced features), select "Enable Webservices" (enablewebservices).
      4. Enable "Mobile services": Site administration ► Mobile app ► Mobile settings
      5. Click on Site administration ► Plugins ► Web services ► Manage tokens
      6. Create one token for the user admin to service (Mobile Service).

      Testing Scenario 1: Call WS using pluginfile.php to get a valid export H5P.

      1. Login as admin.
      2. Go to the "Course 1".
      3. Add a new activity page,
      4. Edit the page content of the new activity page and upload an H5P file attached in the issue arithmetic-quiz.h5p using the "Manage files" button in the Atto editor.
      5. Now click the "Link" button, click "Browse repositories", select "Embedded files" and select the h5p file you just uploaded.
      6. Save the changes.
      7. YOURURLH5PFILE: Copy the URL of the h5p file. Be sure, the URL has in the path 'http://YOURMOODLESITE/pluginfile.php/...'.
      8. Next, you can do a CURL REST in the console, call simulating a WS client:
        • You need to replace the wstoken for the token created for the admin user in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7.

          curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=YOURURLH5PFILE&frame=0&export=0&copyright=0&embed=0&wstoken=WSTOKEN' | python -m "json.tool"

      1. Expected result: Check that the responses's values have this kind of structure:

        {
            "files": [
                {
                    "filename": "arithmetic-quiz.h5p",
                    "filepath": "/",
                    "filesize": 752717,
                    "fileurl": "http://YOURMOODLESITE/pluginfile.php/1/core_h5p/export/arithmetic-quiz-14-14.h5p",
                    "mimetype": "application/zip",
                    "timemodified": 1580289548
                }
            ],
            "warnings": []
        }

      2. Confirm that: the fileurl value in the response from the CURL call you should get the file using a new tab on the browser and the fileurl has in the path 'http://YOURMOODLESITE/pluginfile.php/...'.

      Testing Scenario 2: Call WS using webservice/pluginfile.php to get a valid export H5P.

      1. You have to do a little change in the URL of the h5p file that you had copied in the previous scenario "Test 1".
      2. YOURURLH5PFILEWITHWEBSERVICESPLUGINFILE: Please, replace "pluginfile.php" for "webservice/pluginfile.php" in the copied URL. You should have the next path 'http://YOURMOODLESITE/webservice/pluginfile.php/....'.
      3. Next, you can do a CURL REST in the console, call simulating a WS client:
        • You need to replace the wstoken for the token created for the admin user in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7.

          curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=YOURURLH5PFILEWITHWEBSERVICESPLUGINFILE&frame=0&export=0&copyright=0&embed=0&wstoken=WSTOKEN' | python -m "json.tool"

      1. Expected result: Check that the response's values has this kind of structure:

        {
            "files": [
                {
                    "filename": "arithmetic-quiz.h5p",
                    "filepath": "/",
                    "filesize": 752717,
                    "fileurl": "http://YOURMOODLESITE/webservice/pluginfile.php/1/core_h5p/export/arithmetic-quiz-14-14.h5p",
                    "mimetype": "application/zip",
                    "timemodified": 1580289548
                }
            ],
            "warnings": []
        }

      2. Confirm that: the fileurl value in the response from the CURL call you should get the file using a new tab on the browser and the fileurl has in the path 'http://YOURMOODLESITE/webservice/pluginfile.php/...'.

      Testing Scenario 3:  Call WS using tokenpluginfile.php to get a valid export H5P.

      1. First, you need to get a userprivateaccesskey to use tokenpluginfile.php properly. To do that, you have to run the next command on the console:

        curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_webservice_get_site_info&wstoken=WSTOKEN' | python -m "json.tool" | grep 'userprivateaccesskey'

      1. USERPRIVATEACCESSKEY: the value will be the value returned in the console associated to the "userprivateaccesskey" field.
      2. Now, you have to do a little change in the URL of the h5p file that you had copied in the previous scenario "Test 1".
      3. YOURURLH5PFILETOKENPLUGINFILE: Please, replace "pluginfile.php" for "tokenpluginfile.php/USERPRIVATEACCESSKEY" in the copied URL. You should have the next path 'http://YOURMOODLESITE/tokenpluginfile.php/USERPRIVATEACCESSKEY/....'
      4. Next, you can do a CURL REST in the console, call simulating a WS client:
        • You need to replace the wstoken for the token created for the admin user in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7.

          curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=YOURURLH5PFILETOKENPLUGINFILE&frame=0&export=0&copyright=0&embed=0&wstoken=WSTOKEN' | python -m "json.tool"

      1. Expected result: Check that the responses's values have this kind of structure:

        {
            "files": [
                {
                    "filename": "arithmetic-quiz.h5p",
                    "filepath": "/",
                    "filesize": 752717,
                    "fileurl": "http://YOURMOODLESITE/tokenpluginfile.php/USERPRIVATEACCESSKEY/1/core_h5p/export/arithmetic-quiz-14-14.h5p",
                    "mimetype": "application/zip",
                    "timemodified": 1580289548
                }
            ],
            "warnings": []
        }

      2. Confirm that: the fileurl value in the response from the CURL call you should get the file using a new tab on the browser and the fileurl has in the path 'http://YOURMOODLESITE/tokenpluginfile.php/USERPRIVATEACCESSKEY/...'.
         
      Show
      Notice: You need to be able to use CURL in a console . Setup Login as admin. Create a course "Course 1". Ensure webservices is enabled (Site Administration > Advanced features), select "Enable Webservices" ( enablewebservices ). Enable "Mobile services": Site administration ► Mobile app ► Mobile settings Click on Site administration ► Plugins ► Web services ► Manage tokens Create one token for the user admin to service (Mobile Service). Testing Scenario 1: Call WS using pluginfile.php to get a valid export H5P. Login as admin. Go to the "Course 1". Add a new activity page, Edit the page content of the new activity page and upload an H5P file attached in the issue arithmetic-quiz.h5p using the "Manage files" button in the Atto editor. Now click the "Link" button, click "Browse repositories", select "Embedded files" and select the h5p file you just uploaded. Save the changes. YOURURLH5PFILE: Copy the URL of the h5p file. Be sure, the URL has in the path 'http://YOURMOODLESITE/pluginfile.php/...'. Next, you can do a CURL REST in the console, call simulating a WS client: You need to replace the wstoken for the token created for the admin user in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7. curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=YOURURLH5PFILE&frame=0&export=0&copyright=0&embed=0&wstoken=WSTOKEN' | python -m "json.tool" Expected result: Check that the responses's values have this kind of structure: { "files": [ { "filename": "arithmetic-quiz.h5p", "filepath": "/", "filesize": 752717, "fileurl": "http://YOURMOODLESITE/pluginfile.php/1/core_h5p/export/arithmetic-quiz-14-14.h5p", "mimetype": "application/zip", "timemodified": 1580289548 } ], "warnings": [] } Confirm that : the fileurl value in the response from the CURL call you should get the file using a new tab on the browser and the fileurl has in the path 'http://YOURMOODLESITE/pluginfile.php/...'. Testing Scenario 2: Call WS using webservice/pluginfile.php to get a valid export H5P. You have to do a little change in the URL of the h5p file that you had copied in the previous scenario "Test 1". YOURURLH5PFILEWITHWEBSERVICESPLUGINFILE: Please, replace "pluginfile.php" for "webservice/pluginfile.php" in the copied URL. You should have the next path 'http://YOURMOODLESITE/webservice/pluginfile.php/....'. Next, you can do a CURL REST in the console, call simulating a WS client: You need to replace the wstoken for the token created for the admin user in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7. curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=YOURURLH5PFILEWITHWEBSERVICESPLUGINFILE&frame=0&export=0&copyright=0&embed=0&wstoken=WSTOKEN' | python -m "json.tool" Expected result: Check that the response's values has this kind of structure: { "files": [ { "filename": "arithmetic-quiz.h5p", "filepath": "/", "filesize": 752717, "fileurl": "http://YOURMOODLESITE/webservice/pluginfile.php/1/core_h5p/export/arithmetic-quiz-14-14.h5p", "mimetype": "application/zip", "timemodified": 1580289548 } ], "warnings": [] } Confirm that : the fileurl value in the response from the CURL call you should get the file using a new tab on the browser and the fileurl has in the path 'http://YOURMOODLESITE/webservice/pluginfile.php/...'. Testing Scenario 3:  Call WS using tokenpluginfile.php to get a valid export H5P. First, you need to get a userprivateaccesskey to use tokenpluginfile.php properly. To do that, you have to run the next command on the console: curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_webservice_get_site_info&wstoken=WSTOKEN' | python -m "json.tool" | grep 'userprivateaccesskey' USERPRIVATEACCESSKEY: the value will be the value returned in the console associated to the "userprivateaccesskey" field. Now, you have to do a little change in the URL of the h5p file that you had copied in the previous scenario "Test 1". YOURURLH5PFILETOKENPLUGINFILE : Please, replace "pluginfile.php" for "tokenpluginfile.php/USERPRIVATEACCESSKEY" in the copied URL. You should have the next path 'http://YOURMOODLESITE/tokenpluginfile.php/USERPRIVATEACCESSKEY/....' Next, you can do a CURL REST in the console, call simulating a WS client: You need to replace the wstoken for the token created for the admin user in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7. curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url= YOURURLH5PFILETOKENPLUGINFILE &frame=0&export=0&copyright=0&embed=0&wstoken=WSTOKEN' | python -m "json.tool" Expected result: Check that the responses's values have this kind of structure: { "files": [ { "filename": "arithmetic-quiz.h5p", "filepath": "/", "filesize": 752717, "fileurl": "http://YOURMOODLESITE/tokenpluginfile.php/USERPRIVATEACCESSKEY/1/core_h5p/export/arithmetic-quiz-14-14.h5p", "mimetype": "application/zip", "timemodified": 1580289548 } ], "warnings": [] } Confirm that : the fileurl value in the response from the CURL call you should get the file using a new tab on the browser and the fileurl has in the path 'http://YOURMOODLESITE/tokenpluginfile.php/USERPRIVATEACCESSKEY/...'.  
    • Affected Branches:
      MOODLE_38_STABLE, MOODLE_39_STABLE
    • Fixed Branches:
      MOODLE_39_STABLE
    • Pull Master Branch:
      MDL-67131-master

      Description

      Right now the player only accepts /pluginfile.php URLs to find the h5p files. It would be nice if it also accepted webservice/pluginfile.php and tokenpluginfile.php URLs, since they're also valid URLs to retrieve the file.

      E.g. this URL works fine:

      http://localhost/stable_master/pluginfile.php/2342/mod_page/content/10/h5p-column-34794.h5p

      But this one gives an error: H5P file not found (invalid contextid)

      http://localhost/stable_master/webservice/pluginfile.php/2342/mod_page/content/10/h5p-column-34794.h5p

        Attachments

          Activity

            People

            Assignee:
            cescobedo Carlos Escobedo
            Reporter:
            dpalou Dani Palou
            Peer reviewer:
            Dani Palou
            Integrator:
            Eloy Lafuente (stronk7)
            Tester:
            Anna Carissa Sadia
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              15/Jun/20

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 2 hours, 25 minutes
                1d 2h 25m