Skip to content

Commit

Permalink
MDL-30969 add support for suspending in uploaduser admin tool
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jan 8, 2012
1 parent 0e84b16 commit 08157bf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
38 changes: 37 additions & 1 deletion admin/tool/uploaduser/index.php
Expand Up @@ -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');

Expand All @@ -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
);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -593,13 +618,24 @@
}
}

if ($dologout) {
session_kill_user($existinguser->id);
}

} else {
// save the new user to the database
$user->confirmed = 1;
$user->timemodified = time();
$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';
}
Expand Down
1 change: 1 addition & 0 deletions admin/tool/uploaduser/lang/en/tool_uploaduser.php
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion admin/tool/uploaduser/locallib.php
Expand Up @@ -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.
Expand All @@ -76,6 +76,7 @@ public function start() {
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('password').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('authentication').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('enrolments', 'enrol').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('suspended', 'auth').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('delete').'</th>';
echo '</tr>';
$this->_row = null;
Expand Down
5 changes: 5 additions & 0 deletions admin/tool/uploaduser/user_form.php
Expand Up @@ -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);

Expand Down

0 comments on commit 08157bf

Please sign in to comment.