From 08157bfe767b944d43c6075d8419da5f38840880 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 3 Jan 2012 16:40:09 +0100 Subject: [PATCH] MDL-30969 add support for suspending in uploaduser admin tool --- admin/tool/uploaduser/index.php | 38 ++++++++++++++++++- .../uploaduser/lang/en/tool_uploaduser.php | 1 + admin/tool/uploaduser/locallib.php | 3 +- admin/tool/uploaduser/user_form.php | 5 +++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/admin/tool/uploaduser/index.php b/admin/tool/uploaduser/index.php index 44a0fe88463bc..a0a69b08134ec 100644 --- a/admin/tool/uploaduser/index.php +++ b/admin/tool/uploaduser/index.php @@ -73,6 +73,10 @@ $strinvalidpasswordpolicy = get_string('invalidpasswordpolicy', 'error'); $errorstr = get_string('error'); +$stryes = get_string('yes'); +$strno = get_string('no'); +$stryesnooptions = array(0=>$strno, 1=>$stryes); + $returnurl = new moodle_url('/admin/tool/uploaduser/index.php'); $bulknurl = new moodle_url('/admin/user/user_bulk.php'); @@ -88,6 +92,7 @@ 'url', 'description', 'descriptionformat', 'password', 'auth', // watch out when changing auth type or using external auth plugins! 'oldusername', // use when renaming users - this is the original username + 'suspended', // 1 means suspend user account, 0 means activate user account, nothing means keep as is for existing users 'deleted', // 1 means delete user ); @@ -154,6 +159,7 @@ $updatepasswords = (!empty($formdata->uupasswordold) and $optype != UU_USER_ADDNEW and $optype != UU_USER_ADDINC and ($updatetype == UU_UPDATE_FILEOVERRIDE or $updatetype == UU_UPDATE_ALLOVERRIDE)); $allowrenames = (!empty($formdata->uuallowrenames) and $optype != UU_USER_ADDNEW and $optype != UU_USER_ADDINC); $allowdeletes = (!empty($formdata->uuallowdeletes) and $optype != UU_USER_ADDNEW and $optype != UU_USER_ADDINC); + $allowsuspends = (!empty($formdata->uuallowsuspends)); $bulk = $formdata->uubulk; $noemailduplicates = $formdata->uunoemailduplicates; $standardusernames = $formdata->uustandardusernames; @@ -446,6 +452,7 @@ $user->id = $existinguser->id; $upt->track('username', html_writer::link(new moodle_url('/user/profile.php', array('id'=>$existinguser->id)), s($existinguser->username)), 'normal', false); + $upt->track('suspended', $stryesnooptions[$existinguser->suspended] , 'normal', false); if (is_siteadmin($user->id)) { $upt->track('status', $strusernotupdatedadmin, 'error'); @@ -462,6 +469,7 @@ $upt->track('auth', $existinguser->auth, 'normal', false); $doupdate = false; + $dologout = false; if ($updatetype != UU_UPDATE_NOCHANGES) { if (!empty($user->auth) and $user->auth !== $existinguser->auth) { @@ -471,10 +479,13 @@ $upt->track('auth', $struserauthunsupported, 'warning'); } $doupdate = true; + if ($existinguser->auth === 'nologin') { + $dologout = true; + } } $allcolumns = array_merge($STD_FIELDS, $PRF_FIELDS); foreach ($allcolumns as $column) { - if ($column === 'username' or $column === 'password' or $column === 'auth') { + if ($column === 'username' or $column === 'password' or $column === 'auth' or $column === 'suspended') { // these can not be changed here continue; } @@ -531,6 +542,20 @@ } $isinternalauth = $auth->is_internal(); + // deal with suspending and activating of accounts + if ($allowsuspends and isset($user->suspended) and $user->suspended !== '') { + $user->suspended = $user->suspended ? 1 : 0; + if ($existinguser->suspended != $user->suspended) { + $upt->track('suspended', '', 'normal', false); + $upt->track('suspended', $stryesnooptions[$existinguser->suspended].'-->'.$stryesnooptions[$user->suspended], 'info', false); + $existinguser->suspended = $user->suspended; + $doupdate = true; + if ($existinguser->suspended) { + $dologout = true; + } + } + } + // changing of passwords is a special case // do not force password changes for external auth plugins! $oldpw = $existinguser->password; @@ -593,6 +618,10 @@ } } + if ($dologout) { + session_kill_user($existinguser->id); + } + } else { // save the new user to the database $user->confirmed = 1; @@ -600,6 +629,13 @@ $user->timecreated = time(); $user->mnethostid = $CFG->mnet_localhost_id; // we support ONLY local accounts here, sorry + if (!isset($user->suspended) or $user->suspended === '') { + $user->suspended = 0; + } else { + $user->suspended = $user->suspended ? 1 : 0; + } + $upt->track('suspended', $stryesnooptions[$user->suspended], 'normal', false); + if (empty($user->auth)) { $user->auth = 'manual'; } diff --git a/admin/tool/uploaduser/lang/en/tool_uploaduser.php b/admin/tool/uploaduser/lang/en/tool_uploaduser.php index 90713c24603d6..74bb55ee81499 100644 --- a/admin/tool/uploaduser/lang/en/tool_uploaduser.php +++ b/admin/tool/uploaduser/lang/en/tool_uploaduser.php @@ -25,6 +25,7 @@ $string['allowdeletes'] = 'Allow deletes'; $string['allowrenames'] = 'Allow renames'; +$string['allowsuspends'] = 'Allow suspending and activating of accounts'; $string['csvdelimiter'] = 'CSV delimiter'; $string['defaultvalues'] = 'Default values'; $string['deleteerrors'] = 'Delete errors'; diff --git a/admin/tool/uploaduser/locallib.php b/admin/tool/uploaduser/locallib.php index 0917c2ecde5d3..83b648c9b32f8 100644 --- a/admin/tool/uploaduser/locallib.php +++ b/admin/tool/uploaduser/locallib.php @@ -56,7 +56,7 @@ */ class uu_progress_tracker { private $_row; - public $columns = array('status', 'line', 'id', 'username', 'firstname', 'lastname', 'email', 'password', 'auth', 'enrolments', 'deleted'); + public $columns = array('status', 'line', 'id', 'username', 'firstname', 'lastname', 'email', 'password', 'auth', 'enrolments', 'suspended', 'deleted'); /** * Print table header. @@ -76,6 +76,7 @@ public function start() { echo ''.get_string('password').''; echo ''.get_string('authentication').''; echo ''.get_string('enrolments', 'enrol').''; + echo ''.get_string('suspended', 'auth').''; echo ''.get_string('delete').''; echo ''; $this->_row = null; diff --git a/admin/tool/uploaduser/user_form.php b/admin/tool/uploaduser/user_form.php index 6faa4ddda7007..33b11193508a9 100644 --- a/admin/tool/uploaduser/user_form.php +++ b/admin/tool/uploaduser/user_form.php @@ -134,6 +134,11 @@ function definition () { $mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_USER_ADDNEW); $mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_USER_ADDINC); + $mform->addElement('selectyesno', 'uuallowsuspends', get_string('allowsuspends', 'tool_uploaduser')); + $mform->setDefault('uuallowsuspends', 1); + $mform->disabledIf('uuallowsuspends', 'uutype', 'eq', UU_USER_ADDNEW); + $mform->disabledIf('uuallowsuspends', 'uutype', 'eq', UU_USER_ADDINC); + $mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'tool_uploaduser')); $mform->setDefault('uunoemailduplicates', 1);