Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
3.8, 3.9
-
MOODLE_38_STABLE, MOODLE_39_STABLE
-
MOODLE_39_STABLE
-
MDL-67131-master -
Hide
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©right=0&embed=0&wstoken=WSTOKEN' | python -m "json.tool"
- 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.
- 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©right=0&embed=0&wstoken=WSTOKEN' | python -m "json.tool"
- 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.
- 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©right=0&embed=0&wstoken=WSTOKEN' | python -m "json.tool"
- 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.
- 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/...'.
ShowNotice: 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©right=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©right=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©right=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/...'.
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)
Attachments
- MDL-67131.jpg
- 79 kB
- MDL-67131 (2).jpg
- 42 kB