From aac6bfdf7ab56f88cd0d8fa22b1a1305e48d8398 Mon Sep 17 00:00:00 2001 From: Paola Maneggia Date: Tue, 20 Sep 2022 11:52:30 +0200 Subject: [PATCH 1/2] MDL-75802 user: Exclude current user from bulk unenrol operation --- user/action_redir.php | 6 ++++++ user/tests/behat/bulk_editenrolment.feature | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/user/action_redir.php b/user/action_redir.php index e17c4d0582e..c7c70739b97 100644 --- a/user/action_redir.php +++ b/user/action_redir.php @@ -230,6 +230,12 @@ 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))) { + \core\notification::warning(get_string('userremovedfromselectiona', 'enrol', fullname($USER))); + unset($filteredusers[$USER->id]); + } + if (empty($filteredusers)) { redirect($returnurl, get_string('noselectedusers', 'bulkusers')); } diff --git a/user/tests/behat/bulk_editenrolment.feature b/user/tests/behat/bulk_editenrolment.feature index a81510a8fb4..c617a35660b 100644 --- a/user/tests/behat/bulk_editenrolment.feature +++ b/user/tests/behat/bulk_editenrolment.feature @@ -48,6 +48,25 @@ Feature: Bulk enrolments And I should not see "Teacher 1" And I should see "3 unenrolled users" + @javascript + Scenario: Bulk delete enrolments when user is themselves enrolled + When I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to course participants + And I click on "Select all" "checkbox" + And I set the field "With selected users..." to "Delete selected user enrolments" + Then I should see "User \"Teacher 1\" was removed from the selection." + And the following should exist in the "Delete selected user enrolments" table: + | Student 1 | student1@example.com | + | Student 2 | student2@example.com | + And I press "Unenrol users" + Then I should see "2 unenrolled users" + And I should see "User \"Teacher 1\" was removed from the selection." + And the following should exist in the "Enrolled users" table: + | Teacher 1 | teacher1@example.com | + And I should not see "Student 1" + And I should not see "Student 2" + @javascript Scenario: Bulk edit enrolment for deleted user When I log in as "admin" From 347810b07fd219eea4b47e192293c129c059ea2f Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 24 Aug 2023 10:15:32 +0100 Subject: [PATCH 2/2] MDL-75802 course: fix Behat scenario for bulk unenrolment. --- user/tests/behat/bulk_editenrolment.feature | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/user/tests/behat/bulk_editenrolment.feature b/user/tests/behat/bulk_editenrolment.feature index c617a35660b..ac2490e63ae 100644 --- a/user/tests/behat/bulk_editenrolment.feature +++ b/user/tests/behat/bulk_editenrolment.feature @@ -56,16 +56,17 @@ Feature: Bulk enrolments And I click on "Select all" "checkbox" And I set the field "With selected users..." to "Delete selected user enrolments" Then I should see "User \"Teacher 1\" was removed from the selection." - And the following should exist in the "Delete selected user enrolments" table: - | Student 1 | student1@example.com | - | Student 2 | student2@example.com | + And the following should exist in the "generaltable" table: + | Name | Status | + | Student 1 | Active | + | Student 2 | Active | + And I should not see "Teacher 1" in the "generaltable" "table" And I press "Unenrol users" - Then I should see "2 unenrolled users" + And I should see "2 unenrolled users" And I should see "User \"Teacher 1\" was removed from the selection." - And the following should exist in the "Enrolled users" table: - | Teacher 1 | teacher1@example.com | - And I should not see "Student 1" - And I should not see "Student 2" + 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" @javascript Scenario: Bulk edit enrolment for deleted user