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

WS core_course_update_courses returning "requireloginerror"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.9.3, 3.10
    • Fix Version/s: None
    • Component/s: Course, Web Services
    • Labels:
    • Affected Branches:
      MOODLE_310_STABLE, MOODLE_39_STABLE

      Description

      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:
      {
      "warnings": [
      {
      "item": "course",
      "itemid": 2,
      "warningcode": "requireloginerror",
      "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
      • moodle/course:update
      • moodle/course:changecategory
      • moodle/course:changefullname
      • moodle/course:changeshortname
      • moodle/course:changeidnumber
      • moodle/course:changesummary
      • moodle/course:visibility
      • webservice/rest:use

      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[0][id]="2"'
      --form
      'courses[0][fullname]="new course fullname"'
      --form
      'courses[0][shortname]="shortname"'
      --form
      'courses[0][categoryid]="1"'
      --form
      'courses[0][startdate]="1609470000"'
      --form
      'courses[0][enddate]="1640919600"'
       
      (If I've not forget any step, this is sufficient to reproduce)
       
      You will get the error.
      Thanks for the help!

      Jeferson

       

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            jeferod83 Jeferson Rodrigues
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona), Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: