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

Web service for completion doesn't work correctly with restrictions

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.3.10, 4.4.6, 4.5.2, 5.0
    • Course completion
    • MOODLE_403_STABLE, MOODLE_404_STABLE, MOODLE_405_STABLE, MOODLE_500_STABLE
    • mdl-85036_405
    • mdl-85036_500
    • mdl-85036_main
    • Hide
      1. Create a course set to Custom section format, and take note of the course ID.
      2. Add a student, and take note of the student ID.
      3. Create a Page activity with completion set to View the activity.
      4. Hide the Page activity.
      5. Site Administration > Advanced features > Enable web services.
      6. Site Administration > Webs services Overview.
      7. Enable rest protocol if not done.
      8. Create token for the admin user (or other user with the permissions to see the hidden Page activity), and take note of the token.
      9. Run:

        curl  $SITEURL/webservice/rest/server.php -d "wstoken=$TOKEN" -d "wsfunction=core_completion_get_activities_completion_status" -d 'moodlewsrestformat=json' -d "courseid=$COURSEID" -d "userid=$STUDENTUSERID" -k

      10. Verify uservisible is returned as false. (Fails before the patch.)
      Show
      Create a course set to Custom section format, and take note of the course ID. Add a student, and take note of the student ID. Create a Page activity with completion set to View the activity. Hide the Page activity. Site Administration > Advanced features > Enable web services. Site Administration > Webs services Overview. Enable rest protocol if not done. Create token for the admin user (or other user with the permissions to see the hidden Page activity), and take note of the token. Run: curl  $SITEURL /webservice/rest/server .php -d "wstoken=$TOKEN" -d "wsfunction=core_completion_get_activities_completion_status" -d 'moodlewsrestformat=json' -d "courseid=$COURSEID" -d "userid=$STUDENTUSERID" -k Verify uservisible is returned as false. (Fails before the patch.)
    • Hide

      Code verified against automated checks.

      Checked MDL-85036 using repository: https://github.com/james-cnz/moodle.git

      More information about this report

      Built on: Sat Apr 26 10:38:23 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-85036 using repository: https://github.com/james-cnz/moodle.git MOODLE_405_STABLE (0 errors / 0 warnings) [branch: mdl-85036_405 | CI Job ] MOODLE_500_STABLE (0 errors / 0 warnings) [branch: mdl-85036_500 | CI Job ] main (0 errors / 0 warnings) [branch: mdl-85036_main | CI Job ] More information about this report Built on: Sat Apr 26 10:38:23 UTC 2025

      The class completion_info_exporter doesn't correctly fetch information for the specified user, returning information for the logged in user instead.

      Original ticket's description

      Hi everyone,

      I’m reporting you an issue about the completion related to the webservice "core_completion_get_activities_completion_status". Maybe I misunderstood how it works, but for me the activity restrictions, by group especially, are not processed to calculate a student completion. My Moodle is on version 4.3.10 (Build: 20250210)

      • Create a course and set it on Custom section format.
      • Add 2 students
      • Create 3 sections
      • Create 3 pages activities with completion set to with  completion set to View the activity
      • Create two groups, assign one student to each group
      • Go to More > Course completion > Condition: Activity completion and select the 3 activities  (ALL selected activities to be completed)
      • Add the Course Completion status block to the page
      • Put restrictions by group on the second and third sections so Group 1 can view section 2 and Group 2 can see section 3
      • Login as a student s1

      When we use the web service "core_completion_get_activities_completion_status" it returns you all activities. The web service put the "uservisible" parameter on true even on the activity that the student can't access and can't see.

      Concerning the web service if we change the line 56 in the constructor of "completion_info_exporter" by this ↓:

      $this->cminfo = \cm_info::create((object)['id' => $cm->id, 'course' => $cm->course], $userid);

      It put the "uservisible" parameter on false for the activity that the student can't achieve.

      I test on the version 4.5.2 (Build: 20250210), the issue is still here

       

      Thank you for your time and your attention.

      Best regards

       

      [EDIT: at the beginning the ticket reported a problem conerning different component of Moodle. So, we focused this ticket only at the web service. But other issues have been reported.

      We can see with the block completion_status that the student can’t complete the course because he can’t even access to it. In addition, on the page « My courses » the completion of the course show 50%.

      Other related issues have been linked to this ticket.]

        1. admin_view.png
          99 kB
          David Mangez
        2. student_view.png
          79 kB
          David Mangez
        3. completion_student_course_page.png
          103 kB
          David Mangez
        4. course_report_completion.png
          32 kB
          David Mangez
        5. web_service_data_returned.png
          251 kB
          David Mangez

            james-cnz James E. Calder
            david_cnam David Mangez
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

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