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

New Web Service mod_forum_add_discussion

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.9
    • Fix Version/s: 3.0
    • Component/s: Forum, Web Services
    • Labels:
    • Testing Instructions:
      Hide
      1. Create a course with visible groups enabled (do not force groups)
      2. Create 3 different forums in that course
      3. Forum 1: Without groups
      4. Forum 2: With visible groups enabled
      5. Forum 3: With separate groups enabled
      6. Create two groups in the course
      7. Enrol two users as student in the course
      8. Add the users to different groups
      9. As admin, enable "Mobile services": Plugins ► Web Services ► Mobile
      10. Create tokens for the two users:
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      11. Next, you can do a CURL REST call simulating a WS client with one of the users.
        • You need to replace the wstoken, formumid (the forum instance value of the forum not using groups) and the URL of your moodle instance

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=18&wsfunction=mod_forum_add_discussion&subject=Hi&message=hello&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool"

      12. Check that the message was created in the Moodle web interface
      13. Check in the activity logs that there are new entries with origin WS: Discussion subscription created and Discussion created and Some content has been posted.
      14. Repeat the curl call but using the other user token, and addition this optional parameter: &options%5B0%5D%5Bname%5D=discussionsubscribe&options%5B0%5D%5Bvalue%5D=false
      15. verify that the message is also created, but in the logs you shouldn’t see a Discussion subscription created entry for the new post (since we specify to not subscribe to this discussion)
      16. Now, execute the following request (replace again your url tokens etc..). Replace the groupid value “4” with the user group id (retrieve id from the database or web interface)

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=18&wsfunction=mod_forum_add_discussion&subject=Hi&message=hello&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&groupid=4' | python -m "json.tool"

      17. Verify the discussion is created and that in the database (table discussions) the groupid value for this discussion is -1
      18. Run the same curl request but using the forumid of the forum using visible groups
        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=19&wsfunction=mod_forum_add_discussion&subject=Hi&message=hello&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&groupid=4' | python -m "json.tool"
      19. Verify the discussion is created (remember to choose the Visible groups in the select field). In the database (table discussions) the groupid value for this discussion is the one you specified in the curl request
      20. Run the same command but replacing the user token and the groupid of the other user
      21. Verify the discussion is created
      22. Now, try to use and invalid groupid. You should receive a cannotcreatediscussion error
      23. Now, run the same curl command but removing all the options parameters from the curl request, verify that the discussion is created in the correct user group.
      24. Repeat the last six steps but for the forum with separate groups
      25. Now, enroll a teacher in the course and create a WS token for that user.
      26. Try to create a discussion for the default news forum in the course:

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=17&wsfunction=mod_forum_add_discussion&subject=Hi&message=hello&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' | python -m "json.tool"

      27. Run the same request but using a student token, you should get an error cannotcreatediscussion
      Show
      Create a course with visible groups enabled (do not force groups) Create 3 different forums in that course Forum 1: Without groups Forum 2: With visible groups enabled Forum 3: With separate groups enabled Create two groups in the course Enrol two users as student in the course Add the users to different groups As admin, enable "Mobile services": Plugins ► Web Services ► Mobile Create tokens for the two users: Click on Site administration ► Plugins ► Web services ► Manage tokens Next, you can do a CURL REST call simulating a WS client with one of the users. You need to replace the wstoken, formumid (the forum instance value of the forum not using groups) and the URL of your moodle instance curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=18&wsfunction=mod_forum_add_discussion&subject=Hi&message=hello&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool" Check that the message was created in the Moodle web interface Check in the activity logs that there are new entries with origin WS: Discussion subscription created and Discussion created and Some content has been posted. Repeat the curl call but using the other user token, and addition this optional parameter: &options%5B0%5D%5Bname%5D=discussionsubscribe&options%5B0%5D%5Bvalue%5D=false verify that the message is also created, but in the logs you shouldn’t see a Discussion subscription created entry for the new post (since we specify to not subscribe to this discussion) Now, execute the following request (replace again your url tokens etc..). Replace the groupid value “4” with the user group id (retrieve id from the database or web interface) curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=18&wsfunction=mod_forum_add_discussion&subject=Hi&message=hello&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&groupid=4' | python -m "json.tool" Verify the discussion is created and that in the database (table discussions) the groupid value for this discussion is -1 Run the same curl request but using the forumid of the forum using visible groups curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=19&wsfunction=mod_forum_add_discussion&subject=Hi&message=hello&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&groupid=4' | python -m "json.tool" Verify the discussion is created (remember to choose the Visible groups in the select field). In the database (table discussions) the groupid value for this discussion is the one you specified in the curl request Run the same command but replacing the user token and the groupid of the other user Verify the discussion is created Now, try to use and invalid groupid. You should receive a cannotcreatediscussion error Now, run the same curl command but removing all the options parameters from the curl request, verify that the discussion is created in the correct user group. Repeat the last six steps but for the forum with separate groups Now, enroll a teacher in the course and create a WS token for that user. Try to create a discussion for the default news forum in the course: curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=17&wsfunction=mod_forum_add_discussion&subject=Hi&message=hello&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' | python -m "json.tool" Run the same request but using a student token, you should get an error cannotcreatediscussion
    • Affected Branches:
      MOODLE_29_STABLE
    • Fixed Branches:
      MOODLE_30_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-50994-master

      Description

      This function will be used for creating new discussions into an existing forum.

      Parameters:
      forumid, subject, message, options

      Response:
      Same response that get_forum_discussions but only including the discussion created

      Initially, we won't support attachments or advanced features like "Post to all groups", we won't support "Post to all users" either. (The teacher will have to choose which group to post in case groups are used)

      We will used a generic parameter "options" for parameters like groups or future functionalities like the ones mentioned above. This will make very easy to maintain the function without further API changes

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jleyva Juan Leyva
              Reporter:
              jleyva Juan Leyva
              Peer reviewer:
              John Okely
              Integrator:
              Andrew Nicols
              Tester:
              Adrian Greeve
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                16/Nov/15