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

Add ability for "get enrolled users" web service to be filtered by suspended users

XMLWordPrintable

    • MOODLE_38_STABLE
    • MOODLE_311_STABLE
    • MDL-69869-master
    • Hide
      1. Create a course
        1. Note the ID of the course
      2. Enrol two users as students in the course
      3. Suspend enrolment for one of the students
      4. Enrol another user as a Teacher
      5. Enable the Mobile App from Site admin -> Mobile app -> Mobile settings
      6. Navigate to Site admin -> Plugins -> Web services -> Manage tokens
      7. Create a token for the teacher and note the token
      8. Make a webservice call to retrieve all users. You can do so with a curl request like:

        curl "{ADDRESS_HERE}/webservice/rest/server.php?wstoken={TOKEN_HERE}&wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json&courseid={COURSEID}" | json_pp -
        

        1. Confirm that all three users were retrieved
      9. Make a webservice call to retrieve only active users 

        curl "[ADDRESS_HERE]/webservice/rest/server.php?wstoken=[TOKEN_HERE]&wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json&courseid=[COURSEID]&options[1][name]=onlyactive&options[1][value]=true" | json_pp -
        

        1. Confirm that only the two active users were retrieved
      10. Make a webservice call to retrieve only suspended users 

        curl "[ADDRESS_HERE]/webservice/rest/server.php?wstoken=[TOKEN_HERE]&wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json&courseid=[COURSEID]&options[0][name]=onlysuspended&options[0][value]=true" | json_pp -
        

        1. Confirm that only the one suspended user was retrieved
      11. Make a webservice call that tries to get only active and only suspended at the same time (so two parameters are passed) 

        curl "[ADDRESS_HERE]/webservice/rest/server.php?wstoken=[TOKEN_HERE]&wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json&courseid=[COURSEID]&options[0][name]=onlysuspended&options[0][value]=true&options[1][name]=onlyactive&options[1][value]=true" | json_pp -
        

        1. Confirm that an exception was thrown 

          Both onlyactive and onlysuspended are set, this is probably not what you want!
          

       

      Show
      Create a course Note the ID of the course Enrol two users as students in the course Suspend enrolment for one of the students Enrol another user as a Teacher Enable the Mobile App from Site admin -> Mobile app -> Mobile settings Navigate to Site admin -> Plugins -> Web services -> Manage tokens Create a token for the teacher and note the token Make a webservice call to retrieve all users. You can do so with a curl request like: curl "{ADDRESS_HERE}/webservice/rest/server.php?wstoken={TOKEN_HERE}&wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json&courseid={COURSEID}" | json_pp - Confirm that all three users were retrieved Make a webservice call to retrieve only active users  curl "[ADDRESS_HERE]/webservice/rest/server.php?wstoken=[TOKEN_HERE]&wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json&courseid=[COURSEID]&options[1][name]=onlyactive&options[1][value]=true" | json_pp - Confirm that only the two active users were retrieved Make a webservice call to retrieve only suspended users  curl "[ADDRESS_HERE]/webservice/rest/server.php?wstoken=[TOKEN_HERE]&wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json&courseid=[COURSEID]&options[0][name]=onlysuspended&options[0][value]=true" | json_pp - Confirm that only the one suspended user was retrieved Make a webservice call that tries to get only active and only suspended at the same time (so two parameters are passed)  curl "[ADDRESS_HERE]/webservice/rest/server.php?wstoken=[TOKEN_HERE]&wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json&courseid=[COURSEID]&options[0][name]=onlysuspended&options[0][value]=true&options[1][name]=onlyactive&options[1][value]=true" | json_pp - Confirm that an exception was thrown   Both onlyactive and onlysuspended are set, this is probably not what you want!  
    • Moppies Kanban

      I need to retrieve all Moodle suspended users enrolled in a course (participants) via REST web service functions (Moodle 3.8.4).

      Normally, I use the API function core_enrol_get_enrolled_users. Unfortunately, it does not expose the participants suspended field in the response.

      I searched the available web services for a course/participant API function that contains the suspended filed. And indeed, core_enrol_search_users seems to fit the bill (the web service call was added in 3.8, it looks like) however, the suspended property field is marked as an optional response. And here comes the problem: When I call the API function the optional suspended field is not returned (nor any other optional data).
      My first thought was: A permission issue. According to the Site Admin settings->Web Services->Funtions this API call asks for the permission moodle/course:viewparticipants.

      I tried to add it but to no avail. I cannot see how I can add these permissions to my user or role since the API user has already sys admin privileges. This should cover it already, and I can see suspensions in the UI if I browser a course using this user. So, what needs to be done to retrieve the suspended info via web services?

        1. Screenshot_3.jpg
          Screenshot_3.jpg
          70 kB
        2. Screenshot_2.jpg
          Screenshot_2.jpg
          50 kB
        3. Screenshot_1.jpg
          Screenshot_1.jpg
          62 kB

            ilyatregubov Ilya Tregubov
            floriangrimps Florian Grimps
            Amaia Anabitarte Amaia Anabitarte
            Andrew Lyons Andrew Lyons
            Janelle Barcega Janelle Barcega
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 43 minutes
                1d 43m

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