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:
Paul Holden
2024-08-27 16:55:20 +01:00
parent f714dbee87
commit 8caac3da44
2 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -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]);
}
+2 -1
View File
@@ -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"