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

New Web Service mod_forum_can_add_discussion

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0
    • Fix Version/s: 3.1
    • 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_can_add_discussion&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool"

      12. Check that in the response you see status = True (that means that you can create discussions)
      13. 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_can_add_discussion&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&groupid=4' | python -m "json.tool"

      14. Verify that in the response you see status = True
      15. Run the same request but with groupid=-1, verify that in the response you see status = true
      16. Run the same curl request but using the forumid of the forum using visible groups (and using a valid groupid again)
        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=19&wsfunction=mod_forum_can_add_discussion&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&groupid=4' | python -m "json.tool"
      17. Verify that in the response you see status = True
      18. Run the same command but replacing the user token and the groupid of the other user
      19. Verify that in the response you see status = True
      20. Now, try to use and invalid groupid. You should receive a status = false
      21. Repeat the last steps but for the forum with separate groups
      22. Now, enroll a teacher in the course and create a WS token for that user.
      23. Check if you can create a discussion in 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_can_add_discussion&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' | python -m "json.tool"

      24. Check that the teacher has the capability "site:accessallgroups" enabled and run the query for a normal forumid using groups adding the groupid=-1 parameter to the query. Verify that you get a status=true
      25. Run the same request but using a student token, you should get an status = false
      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_can_add_discussion&wstoken=ffbe3a3002f235bf9d01fd9369e10b66' | python -m "json.tool" Check that in the response you see status = True (that means that you can create discussions) 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_can_add_discussion&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&groupid=4' | python -m "json.tool" Verify that in the response you see status = True Run the same request but with groupid=-1, verify that in the response you see status = true Run the same curl request but using the forumid of the forum using visible groups (and using a valid groupid again) curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'forumid=19&wsfunction=mod_forum_can_add_discussion&wstoken=ffbe3a3002f235bf9d01fd9369e10b66&groupid=4' | python -m "json.tool" Verify that in the response you see status = True Run the same command but replacing the user token and the groupid of the other user Verify that in the response you see status = True Now, try to use and invalid groupid. You should receive a status = false Repeat the last steps but for the forum with separate groups Now, enroll a teacher in the course and create a WS token for that user. Check if you can create a discussion in 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_can_add_discussion&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' | python -m "json.tool" Check that the teacher has the capability "site:accessallgroups" enabled and run the query for a normal forumid using groups adding the groupid=-1 parameter to the query. Verify that you get a status=true Run the same request but using a student token, you should get an status = false
    • Affected Branches:
      MOODLE_30_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-52165-master

      Description

      Check if the user can add discussions in the given forum (and optionally group).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jleyva Juan Leyva
              Reporter:
              jleyva Juan Leyva
              Peer reviewer:
              Dani Palou
              Integrator:
              Dan Poltawski
              Tester:
              Mark Nelson
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                23/May/16