Moodle

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

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 1.8.3, 1.9
  • Fix Version/s: None
  • Component/s: Roles / Access
  • Labels:
    None
  • Affected Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE

Description

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?

Issue Links

Activity

Hide
Yu Zhang added a comment -

Hi Gisela, could you please explain how to do 2a? Is this done in the assign role interface?

Cheers,

Yu

Show
Yu Zhang added a comment - Hi Gisela, could you please explain how to do 2a? Is this done in the assign role interface? Cheers, Yu
Hide
Gisela Hillenbrand added a comment -

Hi Yu,

case 2a:

I'm a student in the course
Within the course I access my user profile (clicking on my name in the participants list or clicking on my name in the "You are loggend in as..." link on the course page. In the profile I find the buttons "Change password", "Unenrol me from XXX" and "Messages". So here I click on the "Unenrol me"" button and then get the error message.

I know that this is not the intended way to unenrol myself from a course. It is rather expected to use case1. However one of my collegues tried to do it the way described and found that bug.

Gisela

Show
Gisela Hillenbrand added a comment - Hi Yu, case 2a: I'm a student in the course Within the course I access my user profile (clicking on my name in the participants list or clicking on my name in the "You are loggend in as..." link on the course page. In the profile I find the buttons "Change password", "Unenrol me from XXX" and "Messages". So here I click on the "Unenrol me"" button and then get the error message. I know that this is not the intended way to unenrol myself from a course. It is rather expected to use case1. However one of my collegues tried to do it the way described and found that bug. Gisela
Hide
Dan Poltawski added a comment -

Hi, I fixed this issue recently in MDL-10241

Show
Dan Poltawski added a comment - Hi, I fixed this issue recently in MDL-10241

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: