Details
-
New Feature
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
3.8
-
MOODLE_38_STABLE
-
MOODLE_38_STABLE
-
MDL-67043-master -
Hide
Notice: You need to be able to use CURL in a console and run SQL in a DB.
Setup
- Login as admin.
- Create a course "Course 1".
- Create a teacher t1 user and enrolled in the Course 1.
- Create a student s1 user and enrolled in the Course 1.
- Ensure webservices is enabled (Site Administration > Advanced features), select "Enable Webservices" (enablewebservices).
- Setup a webservices in Moodle (Site Administration ► Plugins ► Webservices > External Service).
- Turn on the Rest protocol (Site Administration ► Plugins ► Webservices ► Manage protocols).
- Enable "Mobile services": Site administration ► Mobile app ► Mobile settings
- Click on Site administration ► Plugins ► Web services ► Manage tokens
- Create two tokens, one for the teacher t1 and other for the student s1 to service (Mobile Service).
Testing Scenario 1: Teacher Call WS to get a valid export H5P and is not deployed in the site.
- 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.
- Copy the URL of the h5p file.
- 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 teacher 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=WSTOKENTEACHER' | python -m "json.tool"
- You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7.
-
- Execute this SQL in the Database:
SELECT id, filename, filepath, filesize, mimetype, timemodified FROM mdl_files WHERE component LIKE 'core_h5p' AND filearea LIKE 'export' AND filename LIKE 'arithmetic-quiz%' ORDER BY timemodified DESC LIMIT 1;
- Execute this SQL in the Database:
- Expected result: Check that the responses' values from the CURL call has the same values like the results from the SQL. The filename, filepath, filesize, mimetype and timemodified should be part of the files record response from CURL call.
- Confirm that: the fileurl value in the response from the CURL call you should get the file using a new tab on the browser.
Testing Scenario 2: Student Call WS to get a valid export H5P and is already deployed in the site.
- 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 find-the-words-7-7.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.
- Copy the URL of the h5p file.
- Paste the next URL and change YOURURLH5PFILE for the url copied in step 7.
http://YOURMOODLESITE/h5p/embed.php?url=YOURURLH5PFILE
- You have to see the H5P file. So, the H5P file has been deployed.
- 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 student 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=YOURMOODLEURLH5P&embed=0&wstoken=STUDENTWSTOKEN' | python -m "json.tool"
- You need to replace the wstoken for the token created for the student in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7.
-
- Execute this SQL in the Database:
SELECT id, filename, filepath, filesize, mimetype, timemodified FROM mdl_files WHERE component LIKE 'core_h5p' AND filearea LIKE 'export' AND filename LIKE 'find-the-words%'
- Execute this SQL in the Database:
- Expected result: Check that the responses' values from the CURL call has the same values like the results from the SQL. The filename, filepath, filesize, mimetype and timemodified should be part of the files record response from CURL call
- Confirm that :the fileurl value in the response from the CURL call you should get the file using a new tab on the browser.
Testing Scenario 3: Call WS with an empty url.
- Do a CURL REST in the console, call simulating a WS client:
- You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance and the URL parameter will be empty.
curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=&frame=0&export=0©right=0&embed=0&wstoken=WSTOKENTEACHER' | python -m "json.tool"
- You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance and the URL parameter will be empty.
- Expected result: You have to get a response like thiis:
{
"files": [],
"warnings": [
{
"item": "",
"message": "Invalid H5P content URL.",
"warningcode": "0"
}
]
}
Testing Scenario 4: Call WS with an h5p file unknown.
- Do a CURL REST in the console, call simulating a WS client:
- You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance. For the URL parameter you could use the step 7 on the testing scenario 1 and change the name of the file for this, h5pfile.h5p.
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=WSTOKENTEACHER' | python -m "json.tool"
- You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance. For the URL parameter you could use the step 7 on the testing scenario 1 and change the name of the file for this, h5pfile.h5p.
- Expected result: You have to get a response like this:
{
"files": [],
"warnings": [
{
"item": "http://localhost/m/h5pmobile_master/pluginfile.php/43/mod_page/content/2/h5pfile.h5p",
"message": "H5P file not found",
"warningcode": null
}
]
}
The item value has to be the same like your YOURURLH5PFILE.
Testing Scenario 5: Call WS with an invalid 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 invalid.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.
- Copy the URL of the h5p file.
- 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 teacher 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=YOURMOODLEURLH5P&embed=0&wstoken=STUDENTWSTOKEN' | python -m "json.tool"
- You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance and the URL parameter for the URL copied in step 7.
- Expected result: You have to get a response like this:
{
"files": [],
"warnings": [
{
"item": "http://localhost/m/stable_master/pluginfile.php/649/mod_page/content/1/invalid.h5p",
"message": "File \"content/phet.html\" not allowed. Only files with the following extensions are allowed: json png jpg jpeg gif bmp tif tiff svg eot ttf woff woff2 otf webm mp4 ogg mp3 m4a wav txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile vtt webvtt.",
"warningcode": "notinwhitelist"
}
]
}
ShowNotice: You need to be able to use CURL in a console and run SQL in a DB. Setup Login as admin. Create a course "Course 1". Create a teacher t1 user and enrolled in the Course 1. Create a student s1 user and enrolled in the Course 1. Ensure webservices is enabled (Site Administration > Advanced features), select "Enable Webservices" ( enablewebservices ). Setup a webservices in Moodle (Site Administration ► Plugins ► Webservices > External Service). Turn on the Rest protocol (Site Administration ► Plugins ► Webservices ► Manage protocols). Enable "Mobile services": Site administration ► Mobile app ► Mobile settings Click on Site administration ► Plugins ► Web services ► Manage tokens Create two tokens, one for the teacher t1 and other for the student s1 to service (Mobile Service). Testing Scenario 1: Teacher Call WS to get a valid export H5P and is not deployed in the site. 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. Copy the URL of the h5p file. 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 teacher 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=WSTOKENTEACHER' | python -m "json.tool" Execute this SQL in the Database: SELECT id, filename, filepath, filesize, mimetype, timemodified FROM mdl_files WHERE component LIKE 'core_h5p' AND filearea LIKE 'export' AND filename LIKE 'arithmetic-quiz%' ORDER BY timemodified DESC LIMIT 1; Expected result: Check that the responses' values from the CURL call has the same values like the results from the SQL. The filename, filepath, filesize, mimetype and timemodified should be part of the files record response from CURL call. Confirm that : the fileurl value in the response from the CURL call you should get the file using a new tab on the browser. Testing Scenario 2: Student Call WS to get a valid export H5P and is already deployed in the site. 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 find-the-words-7-7.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. Copy the URL of the h5p file. Paste the next URL and change YOURURLH5PFILE for the url copied in step 7. http://YOURMOODLESITE/h5p/embed.php?url=YOURURLH5PFILE You have to see the H5P file. So, the H5P file has been deployed. 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 student 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=YOURMOODLEURLH5P&embed=0&wstoken=STUDENTWSTOKEN' | python -m "json.tool" Execute this SQL in the Database: SELECT id, filename, filepath, filesize, mimetype, timemodified FROM mdl_files WHERE component LIKE 'core_h5p' AND filearea LIKE 'export' AND filename LIKE 'find-the-words%' Expected result: Check that the responses' values from the CURL call has the same values like the results from the SQL. The filename, filepath, filesize, mimetype and timemodified should be part of the files record response from CURL call Confirm that :the fileurl value in the response from the CURL call you should get the file using a new tab on the browser. Testing Scenario 3: Call WS with an empty url. Do a CURL REST in the console, call simulating a WS client: You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance and the URL parameter will be empty. curl 'http://YOURMOODLESITE/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_h5p_get_trusted_h5p_file&url=&frame=0&export=0©right=0&embed=0&wstoken=WSTOKENTEACHER' | python -m "json.tool" Expected result: You have to get a response like thiis: { "files": [], "warnings": [ { "item": "", "message": "Invalid H5P content URL.", "warningcode": "0" } ] } Testing Scenario 4: Call WS with an h5p file unknown. Do a CURL REST in the console, call simulating a WS client: You need to replace the wstoken for the token created for the teacher in the setup and the URL of your moodle instance. For the URL parameter you could use the step 7 on the testing scenario 1 and change the name of the file for this, h5pfile.h5p. 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=WSTOKENTEACHER' | python -m "json.tool" Expected result: You have to get a response like this: { "files": [], "warnings": [ { "item": "http://localhost/m/h5pmobile_master/pluginfile.php/43/mod_page/content/2/h5pfile.h5p", "message": "H5P file not found", "warningcode": null } ] } The item value has to be the same like your YOURURLH5PFILE. Testing Scenario 5: Call WS with an invalid 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 invalid.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. Copy the URL of the h5p file. 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 teacher 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=YOURMOODLEURLH5P&embed=0&wstoken=STUDENTWSTOKEN' | python -m "json.tool" Expected result: You have to get a response like this: { "files": [], "warnings": [ { "item": "http://localhost/m/stable_master/pluginfile.php/649/mod_page/content/1/invalid.h5p", "message": "File \"content/phet.html\" not allowed. Only files with the following extensions are allowed: json png jpg jpeg gif bmp tif tiff svg eot ttf woff woff2 otf webm mp4 ogg mp3 m4a wav txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile vtt webvtt.", "warningcode": "notinwhitelist" } ] }
-
H5P Sprint Relase 3.8
Description
We are going to need a WebService that does the following:
- It will receive the URL of an H5P package.
- The WS should check if that package can be played (check the trusted capability and so). It's the same check that the embed.php will do in Moodle, that way the app will know if the package can be downloaded for offline usage or not. If it cannot be played, the WS should return a warning or a flag that indicates this case. We could use a moodle exception too if you think it's better.
- If the package can be played and hasn't been deployed before, the WS should deploy it now.
- Once deployed, the WS should build a new H5P file with the trusted content_type libraries (downloaded from h5p hub). The app cannot use the original h5p file because it contains content_type libraries that aren't trusted.
- The WS should return the new h5p file's URL, size and timemodified/hash. You can check the class external_files to see the data that's usually returned for files in WebServices. The app needs to be able to know if the h5p file needs to be re-downloaded or not, so we need a hash or a timemodified that tells it. A file needs to be re-downloaded if the user uploaded a new h5p file or if any of the content_type libraries has been updated.
Attachments
- arithmetic-quiz.h5p
- 731 kB
- find-the-words-7-7.h5p
- 617 kB
- invalid.h5p
- 426 kB
- Screenshot_1.png
- 353 kB
- Screenshot_2.png
- 442 kB
Issue Links
- blocks
-
MOBILE-2235 Initial H5P support
-
- Closed
-
- has a non-specific relationship to
-
MDL-67173 core_h5p_get_trusted_h5p_file returns a code error if URL is not local
-
- Closed
-