From 50c64005e8fa65d6a6be0d84e993bb2998e5cede Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 1 Aug 2024 12:15:03 +0100 Subject: [PATCH] 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. --- user/action_redir.php | 2 +- user/tests/behat/bulk_editenrolment.feature | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/user/action_redir.php b/user/action_redir.php index c7c70739b97..84163775018 100644 --- a/user/action_redir.php +++ b/user/action_redir.php @@ -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]); } diff --git a/user/tests/behat/bulk_editenrolment.feature b/user/tests/behat/bulk_editenrolment.feature index 373fa352c56..bc414b3ca9d 100644 --- a/user/tests/behat/bulk_editenrolment.feature +++ b/user/tests/behat/bulk_editenrolment.feature @@ -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"