Skip to content

Commit

Permalink
Merge branch 'MDL-80328' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Jan 22, 2024
2 parents 9e4366a + a32397f commit 2893dc7
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
28 changes: 26 additions & 2 deletions admin/classes/reportbuilder/local/systemreports/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use core_reportbuilder\local\report\filter;
use core_reportbuilder\system_report;
use core_role\reportbuilder\local\entities\role;
use core_user\fields;
use lang_string;
use moodle_url;
use pix_icon;
Expand Down Expand Up @@ -62,8 +63,9 @@ protected function initialise(): void {
$this->add_entity($entityuser);

// Any columns required by actions should be defined here to ensure they're always available.
$fullnamefields = array_map(fn($field) => "{$entityuseralias}.{$field}", fields::get_name_fields());
$this->add_base_fields("{$entityuseralias}.id, {$entityuseralias}.confirmed, {$entityuseralias}.mnethostid,
{$entityuseralias}.suspended, {$entityuseralias}.username");
{$entityuseralias}.suspended, {$entityuseralias}.username, " . implode(', ', $fullnamefields));

$paramguest = database::generate_param_name();
$this->add_base_condition_sql("{$entityuseralias}.deleted <> 1 AND {$entityuseralias}.id <> :{$paramguest}",
Expand Down Expand Up @@ -332,10 +334,32 @@ protected function add_actions(): void {
$this->add_action((new action(
new moodle_url('/admin/user.php', ['delete' => ':id', 'sesskey' => sesskey()]),
new pix_icon('t/delete', ''),
['class' => 'text-danger'],
[
'class' => 'text-danger',
'data-modal' => 'confirmation',
'data-modal-title-str' => json_encode(['deleteuser', 'admin']),
'data-modal-content-str' => ':deletestr',
'data-modal-yes-button-str' => json_encode(['delete', 'core']),
'data-modal-destination' => ':deleteurl',

],
false,
new lang_string('delete', 'moodle'),
))->add_callback(static function(\stdclass $row) use ($USER, $contextsystem): bool {

// Populate deletion modal attributes.
$row->deletestr = json_encode([
'deletecheckfull',
'moodle',
fullname($row, true),
]);

$row->deleteurl = (new moodle_url('/admin/user.php', [
'delete' => $row->id,
'confirm' => md5($row->id),
'sesskey' => sesskey(),
]))->out(false);

return has_capability('moodle/user:delete', $contextsystem) &&
!is_mnet_remote_user($row) && $row->id != $USER->id && !is_siteadmin($row);
}));
Expand Down
7 changes: 4 additions & 3 deletions admin/tests/behat/browse_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ Feature: An administrator can browse user accounts
Scenario: Delete a user account
Given I navigate to "Users > Accounts > Browse list of users" in site administration
And I press "Delete" action in the "User One" report row
And I should see "Are you absolutely sure you want to completely delete the user 'User One'"
And I press "Delete"
Then I should not see "User One" in the "reportbuilder-table" "table"
And I should see "Are you absolutely sure you want to completely delete the user User One" in the "Delete user" "dialogue"
And I click on "Delete" "button" in the "Delete user" "dialogue"
Then I should see "Deleted user User One"
And I should not see "User One" in the "reportbuilder-table" "table"

@javascript
Scenario: Resend email and confirm a user account
Expand Down
4 changes: 2 additions & 2 deletions admin/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
echo $OUTPUT->confirm(get_string('deletecheckfull', '', "'$fullname'"), $deletebutton, $returnurl);
echo $OUTPUT->footer();
die;
} else if (data_submitted()) {
} else {
if (delete_user($user)) {
\core\session\manager::gc(); // Remove stale sessions.
redirect($returnurl);
redirect($returnurl, get_string('deleteduserx', 'admin', fullname($user, true)));
} else {
\core\session\manager::gc(); // Remove stale sessions.
echo $OUTPUT->header();
Expand Down
8 changes: 1 addition & 7 deletions grade/tests/behat/grade_average.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,8 @@ Feature: Average grades are displayed in the gradebook
| student2 | C1 | student | suspended |
And I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on "Filters" "button"
And I set the following fields in the "Username" "core_reportbuilder > Filter" to these values:
| Username operator | Is equal to |
| Username value | student5 |
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
And I click on "Filters" "button"
And I press "Delete" action in the "Student 5" report row
And I press "Delete"
And I click on "Delete" "button" in the "Delete user" "dialogue"
# Enable averages
And I am on the "Course 1" "grades > course grade settings" page
And I set the following fields to these values:
Expand Down
1 change: 1 addition & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@
$string['deleteincompleteusers'] = 'Delete incomplete users after';
$string['deleteunconfirmed'] = 'Delete not fully setup users after';
$string['deleteuser'] = 'Delete user';
$string['deleteduserx'] = 'Deleted user {$a}';
$string['density'] = 'Density';
$string['denyemailaddresses'] = 'Denied email domains';
$string['devlibdirpresent'] = 'Directories with development libraries, especially <em>/vendor</em> and <em>/node_modules</em>, should not be present on public sites. See the <a href="{$a->moreinfourl}">security overview report</a> for more details.';
Expand Down
8 changes: 1 addition & 7 deletions user/tests/behat/bulk_editenrolment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,8 @@ Feature: Bulk enrolments
And I set the field "Available" to "Student 2"
And I press "Add to selection"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on "Filters" "button"
And I set the following fields in the "Username" "core_reportbuilder > Filter" to these values:
| Username operator | Is equal to |
| Username value | student1 |
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
And I click on "Filters" "button"
And I press "Delete" action in the "Student 1" report row
And I press "Delete"
And I click on "Delete" "button" in the "Delete user" "dialogue"
And I navigate to "Users > Accounts > Bulk user actions" in site administration
And I set the field "id_action" to "Add to cohort"
And I press "Go"
Expand Down
8 changes: 1 addition & 7 deletions user/tests/behat/delete_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ Feature: Deleting users
And I press "Add to selection"
Then I should see "User One"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I click on "Filters" "button"
And I set the following fields in the "Username" "core_reportbuilder > Filter" to these values:
| Username operator | Is equal to |
| Username value | user1 |
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
And I click on "Filters" "button"
And I press "Delete" action in the "User One" report row
And I press "Delete"
And I click on "Delete" "button" in the "Delete user" "dialogue"
And I navigate to "Users > Accounts > Bulk user actions" in site administration
Then I should not see "User One"

0 comments on commit 2893dc7

Please sign in to comment.