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

Unenrol from a course using a users profile: does not work for unenroling myself

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • None
    • 1.8.3, 1.9
    • Roles / Access
    • None
    • MOODLE_18_STABLE, MOODLE_19_STABLE

      Roles and capability settings are as in standrad Moodle. Additionally for the student role the capability moodle/role:unassignself is set to allowed (so that a student can unenrol himself from a course).

      There are two ways to unenrol from a course:

      Case 1. Unenroling myself (in the role of a student) via Administration block on the course page (see blocks/admin/block_admin.php - here NO userid parameter is passed to course/unenrol.php)

      Case 2. Using the Unenrol button in the user profile.
      Case 2a: unenrol myself (in the role of a student)
      Case 2b. unenrol any user of the course (if I am in the role of an editing teacher)

      Case 2a does not work - the following error messages appears:
      "Sorry, but you do not currently have permissions to do that (Assign roles to users)"

      Looking at the code in user/view.php we see that when clicking the unenrol button (Case2) the userid parameter is set and passed to course/unenrol.php.

      Now looking at course/unenrol.php we find the code lines 31ff:

      if ($userid)

      { // Unenrolling someone else require_capability('moodle/role:assign', $context, NULL, false); }

      else

      { // Unenrol yourself require_capability('moodle/role:unassignself', $context, NULL, false); }

      However this works only for case1 and case 2b.

      In order to work for case 2a the code should be modified as follows:

      if ($userid AND $userid != $USER->id)

      { require_capability('moodle/role:assign', $context, NULL, false); // case 2a and 2b }

      else

      { // Unenrol yourself require_capability('moodle/role:unassignself', $context, NULL, false); // case 1 }

      Can anyone check this please?

            poltawski Dan Poltawski
            ghillenb Gisela Hillenbrand
            Nobody Nobody (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

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