MDL-72972 tool_uploaduser: observe capability to delete users.

This commit is contained in:
Paul Holden
2022-03-08 10:04:21 +01:00
committed by Jenkins
parent 15c282d1e5
commit c653a49fe3
2 changed files with 8 additions and 1 deletions
+3 -1
View File
@@ -26,6 +26,7 @@ namespace tool_uploaduser;
defined('MOODLE_INTERNAL') || die();
use context_system;
use tool_uploaduser\local\field_value_validators;
require_once($CFG->dirroot.'/user/profile/lib.php');
@@ -550,7 +551,8 @@ class process {
// Delete user.
if (!empty($user->deleted)) {
if (!$this->get_allow_deletes() or $remoteuser) {
if (!$this->get_allow_deletes() or $remoteuser or
!has_capability('moodle/user:delete', context_system::instance())) {
$this->usersskipped++;
$this->upt->track('status', get_string('usernotdeletedoff', 'error'), 'warning');
return;
+5
View File
@@ -147,6 +147,11 @@ class admin_uploaduser_form2 extends moodleform {
$mform->addElement('selectyesno', 'uuallowdeletes', get_string('allowdeletes', 'tool_uploaduser'));
$mform->setDefault('uuallowdeletes', 0);
// Ensure user is able to perform user deletion.
if (!has_capability('moodle/user:delete', context_system::instance())) {
$mform->hardFreeze('uuallowdeletes');
$mform->setConstant('uuallowdeletes', 0);
}
$mform->hideIf('uuallowdeletes', 'uutype', 'eq', UU_USER_ADDNEW);
$mform->hideIf('uuallowdeletes', 'uutype', 'eq', UU_USER_ADDINC);