Error if user has no role in course

Created on 8 May 2025, 2 months ago

Problem/Motivation

If a user is enrolled in a course, but has no role in that course, an error is thrown by the getCourseCompletionPercentage function:

Drupal\moodle_rest\Services\MoodleRestException: User is not enrolled in this course in Drupal\moodle_rest\Services\MoodleRest->requestFunction() (line 159 of /app/web/modules/contrib/moodle_rest/src/Services/MoodleRest.ph

Steps to reproduce

  1. Enrol a user in a course using whatever method.
  2. Via the Moodle Site Administration, remove all course roles from that user, eg remove Student.
  3. Execute the getCourseCompletionPercentage REST function.

I'm fairly sure this'll be an edge case, since for me the Moodle user in question is one we've been testing new courses and Drupal/Moodle integration with. But from some old discussion it does appear to be a supported state, even in current versions (tested with v4.5.2).

Proposed resolution

Add usernotenroled as a possible error code that will trigger a NULL return.

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024