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

New Web Services for updating a forum post (or a discussion topic post)

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.8
    • 3.6, 3.8
    • Forum
    • MOODLE_36_STABLE, MOODLE_38_STABLE
    • MOODLE_38_STABLE
    • MDL-64254-master
    • Hide
      Test for regressions in the web site
      1. Create or use a course with one user enrolled as teacher (t1) and a couple of users enrolled as students (s1 and s2)
      2. Create a forum in that course. Configure it so discussion subscriptions are optional.
      3. As admin, ensure that the maxeditingtime for posts global setting (Site security settings) is set to 30 minutes
      4. Now, log in as teacher t1 and create a new discussion in that forum (using the advance mode) marking as selected the "Pinned" option and also the "Discussion subscription one"
      5. Confirm that:
        • After saving the message is "pinned" in the main discussions view and it says that you are subscribed.
      6. Access to the forum discussion and edit the post, this time uncheck the "Pinned" and "Discussion subscription option"
      7. Confirm that:
        • After saving the message, in the main discussion view, you don't see any more the post "Pinned" and the message that says that you are subscribed
      8. Now, as s1, access to the forum
      9. Reply to the discussion created by t1 using the "Advance mode" changing the Subject and writting some text in the Message field
      10. Confirm that:
        • The post with the reply is created properly
      11. Now, still as s1 click "Edit" at the bottom of the post you just created
      12. Edit the post changing the "Subject" and the "Message" and uncheck the "Discussion subscription option"
      13. Save the changes and confirm that:
        • The post was updated correctly and it displays the new subject and message
      14. Edit again the message this time adding attachments and some images in the message text
      15. Save the changes and confirm that:
        • The post was updated correctly and you can see the image in the text and the attachments
      16. As admin, now change the "maxeditingtime" global setting (in Site security settings) and set it to 1 minute
      17. Wait for a minute and log-in as s1 again
      18. Check that within the forum discussion, you don't see the "edit" option anymore in the s1 created posts
      Test for web services
      1. As admin, enable "Mobile services": Site administration ► Mobile app ► Mobile settings
      2. Create a Token in the mobile app service for t1, s1 and s2
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      3. Create a NEW forum in that course
      4. As admin, ensure that the maxeditingtime for posts global setting (Site security settings) is set to 30 minutes
      5. Now, log in as teacher t1 and create a new discussion in the forum used in the previout set of tests.
      6. Open the console an execute this new curl request, replacing wstoken with the t1 token, the postid with the first post id of the discussion created a couple of steps ago. (You can get the post id just from the "Edit" link)

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_forum_get_discussion_post&wstoken=3af67232a7596ceb658df4db329e5ad6&postid=53' | python -m "json.tool"

      7. Confirm you receive the complete post information. Including a "capabilities->edit" field set to true
      8. Now, log-in as s1 in the web site and reply to the discussion. Do not include any attachment or images in the message body
      9. Open the console an execute this new curl request, replacing wstoken with the s1 token, the postid with the one you just created and the site url with yours.

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_forum_prepare_draft_area_for_post&wstoken=3af67232a7596ceb658df4db329e5ad6&postid=54&area=attachment' | python -m "json.tool"

      10. Confirm that as part of the response you receive a "draftitemid". Please, copy this value somewhere (you'll need it later)
      11. Now, copy in your computer home or document folder an existing pdf document (any), renaming it to "document.pdf"
      12. Open the console an execute this new curl request, replacing token with the s1 token, the itemid parameter with the draftitemid value your copied before and the path of your "document.pdf" document with your local path

        curl -i -F name=document.pdf -F filedata=@/Users/juanleyvadelgado/Documents/document.pdf "http://localhost/m/stable_master/webservice/upload.php?token=3af67232a7596ceb658df4db329e5ad6&itemid=421435137"

      13. Confirm you receive as response a JSON structure with some data including the file name
      14. Open the console an execute this new curl request, replacing wstoken with the s1 token, the postid with the one you used in the previous request, and the value of the "options[4][value]" parameter with the "draftitemid" you used in the previous request the site url with yours.

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_forum_update_discussion_post&wstoken=3af67232a7596ceb658df4db329e5ad6&postid=53&subject=SubjectTestUpdated&message=MessageTestUpdated&messageformat=1&options[0][name]=inlineattachmentsid&options[0][value]=-1&options[1][name]=attachmentsid&options[1][value]=-1' | python -m "json.tool"

      15. Confirm that you receive a response with status set to true
      16. Log-in into the web site as s1, open the updated post and check that now in the subject you see "SubjectTestUpdated", in the message body you see "MessageTestUpdated" and you see the document.pdf as an attachment
      Show
      Test for regressions in the web site Create or use a course with one user enrolled as teacher (t1) and a couple of users enrolled as students (s1 and s2) Create a forum in that course. Configure it so discussion subscriptions are optional. As admin, ensure that the maxeditingtime for posts global setting (Site security settings) is set to 30 minutes Now, log in as teacher t1 and create a new discussion in that forum (using the advance mode) marking as selected the "Pinned" option and also the "Discussion subscription one" Confirm that: After saving the message is "pinned" in the main discussions view and it says that you are subscribed. Access to the forum discussion and edit the post, this time uncheck the "Pinned" and "Discussion subscription option" Confirm that: After saving the message, in the main discussion view, you don't see any more the post "Pinned" and the message that says that you are subscribed Now, as s1, access to the forum Reply to the discussion created by t1 using the "Advance mode" changing the Subject and writting some text in the Message field Confirm that: The post with the reply is created properly Now, still as s1 click "Edit" at the bottom of the post you just created Edit the post changing the "Subject" and the "Message" and uncheck the "Discussion subscription option" Save the changes and confirm that: The post was updated correctly and it displays the new subject and message Edit again the message this time adding attachments and some images in the message text Save the changes and confirm that: The post was updated correctly and you can see the image in the text and the attachments As admin, now change the "maxeditingtime" global setting (in Site security settings) and set it to 1 minute Wait for a minute and log-in as s1 again Check that within the forum discussion, you don't see the "edit" option anymore in the s1 created posts Test for web services As admin, enable "Mobile services": Site administration ► Mobile app ► Mobile settings Create a Token in the mobile app service for t1, s1 and s2 Click on Site administration ► Plugins ► Web services ► Manage tokens Create a NEW forum in that course As admin, ensure that the maxeditingtime for posts global setting (Site security settings) is set to 30 minutes Now, log in as teacher t1 and create a new discussion in the forum used in the previout set of tests. Open the console an execute this new curl request, replacing wstoken with the t1 token, the postid with the first post id of the discussion created a couple of steps ago. (You can get the post id just from the "Edit" link) curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_forum_get_discussion_post&wstoken=3af67232a7596ceb658df4db329e5ad6&postid=53' | python -m "json.tool" Confirm you receive the complete post information. Including a "capabilities->edit" field set to true Now, log-in as s1 in the web site and reply to the discussion. Do not include any attachment or images in the message body Open the console an execute this new curl request, replacing wstoken with the s1 token, the postid with the one you just created and the site url with yours. curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_forum_prepare_draft_area_for_post&wstoken=3af67232a7596ceb658df4db329e5ad6&postid=54&area=attachment' | python -m "json.tool" Confirm that as part of the response you receive a "draftitemid". Please, copy this value somewhere (you'll need it later) Now, copy in your computer home or document folder an existing pdf document (any), renaming it to "document.pdf" Open the console an execute this new curl request, replacing token with the s1 token, the itemid parameter with the draftitemid value your copied before and the path of your "document.pdf" document with your local path curl -i -F name=document.pdf -F filedata=@/Users/juanleyvadelgado/Documents/document.pdf "http://localhost/m/stable_master/webservice/upload.php?token=3af67232a7596ceb658df4db329e5ad6&itemid=421435137" Confirm you receive as response a JSON structure with some data including the file name Open the console an execute this new curl request, replacing wstoken with the s1 token, the postid with the one you used in the previous request, and the value of the "options [4] [value] " parameter with the "draftitemid" you used in the previous request the site url with yours. curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=mod_forum_update_discussion_post&wstoken=3af67232a7596ceb658df4db329e5ad6&postid=53&subject=SubjectTestUpdated&message=MessageTestUpdated&messageformat=1&options [0] [name] =inlineattachmentsid&options [0] [value] =-1&options [1] [name] =attachmentsid&options [1] [value] =-1' | python -m "json.tool" Confirm that you receive a response with status set to true Log-in into the web site as s1, open the updated post and check that now in the subject you see "SubjectTestUpdated", in the message body you see "MessageTestUpdated" and you see the document.pdf as an attachment

      Create a new set of functions for being able to update discussion posts.

      It will require some additional helper WS function to set/prepare the draft attachment and editors.

      Web services to be created are:
      mod_forum_get_discussion_post - To obtain particular information about a post and specifically if the user is able to update ir or not
      mod_forum_prepare_draft_area_for_post - To prepare the draft areas for a post that it is going to be updated including the files to be kept in the draft area when editing a post
      mod_forum_update_discussion_post - To update a post

            jleyva Juan Leyva
            jleyva Juan Leyva
            Pau Ferrer Pau Ferrer
            Jake Dallimore Jake Dallimore
            Gladys Basiana Gladys Basiana
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 days, 6 hours, 16 minutes
                3d 6h 16m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.