Hi! I'm trying to use Moodle (3.10+ build 2020110900.02) webservices from another program, but when I tried to make the ws function "core_course_update_courses" works, it fails with this error:
"message": "Course or activity not accessible. (Not enrolled)"
Debugging the Moodle code, this error raises on line 3011 from the file "moodlelib.php", and it's conditions to arrive there is "the user cannot access the course, because it not enrolled".
The question is: to run this function properly, the webservice user must enrolled on the course(s) who want to update?
In my humble opinion, I believe it's a problem that the algorithm is not prepared to allow a webservice user for making course updates.
Steps to reproduce:
1) Enable webservices
2) Enable REST protocol
3) Create a user who will work on webservices
4) Create a role specific for work on webservices with this permissions:
- Context types where this role may be assigned: System
5) On the system roles assignment, put the webservice user on the webservice role
7) Create a custom service, check "authorized users only" to allow the webservice user only and add the function "core_course_update_courses"
8) Add the webservice user to this custom service
9) Create a token for the webservice user
10) Run on curl or on your preferred client the call to make a update on a course, like this example on curl format:
curl --location --request POST 'http://localhost/moodle310/webservice/rest/server.php?wsfunction=core_course_update_courses&moodlewsrestformat=json&wstoken=<webservice user token>'
--form 'courses[fullname]="new course fullname"'
(If I've not forget any step, this is sufficient to reproduce)
You will get the error.
Thanks for the help!