MDL-82663 user: fix check for current user removing own enrolment.
We only need to remove the current user from selection if they were ever part of the selection originally.
This commit is contained in:
@@ -231,7 +231,7 @@ if ($formaction == 'bulkchange.php') {
|
||||
$filteredusers = array_filter($users, $matchesplugin);
|
||||
|
||||
// If the bulk operation is deleting enrolments, we exclude in any case the current user as it was probably a mistake.
|
||||
if ($operationname === 'deleteselectedusers' && (!in_array($USER->id, $removed))) {
|
||||
if ($operationname === 'deleteselectedusers' && array_key_exists($USER->id, $filteredusers)) {
|
||||
\core\notification::warning(get_string('userremovedfromselectiona', 'enrol', fullname($USER)));
|
||||
unset($filteredusers[$USER->id]);
|
||||
}
|
||||
|
||||
@@ -53,8 +53,10 @@ Feature: Bulk enrolments
|
||||
When I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to course participants
|
||||
# Select all three users (the teacher themselves and both students).
|
||||
And I click on "Select all" "checkbox"
|
||||
And I set the field "With selected users..." to "Delete selected user enrolments"
|
||||
# Teacher is informed that they've been removed from current selection.
|
||||
Then I should see "User \"Teacher 1\" was removed from the selection."
|
||||
And the following should exist in the "generaltable" table:
|
||||
| Name | Status |
|
||||
@@ -63,7 +65,6 @@ Feature: Bulk enrolments
|
||||
And I should not see "Teacher 1" in the "generaltable" "table"
|
||||
And I press "Unenrol users"
|
||||
And I should see "2 unenrolled users"
|
||||
And I should see "User \"Teacher 1\" was removed from the selection."
|
||||
And I should see "Teacher 1" in the "participants" "table"
|
||||
And I should not see "Student 1" in the "participants" "table"
|
||||
And I should not see "Student 2" in the "participants" "table"
|
||||
|
||||
Reference in New Issue
Block a user