Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-30969 add support for suspending in uploaduser admin tool

  • Loading branch information...
commit 77536bd387aff90324d0a68fdb93ea1ede4409b2 1 parent a1d2463
Petr Skoda skodak authored
38 admin/tool/uploaduser/index.php
@@ -73,6 +73,10 @@
73 73 $strinvalidpasswordpolicy = get_string('invalidpasswordpolicy', 'error');
74 74 $errorstr = get_string('error');
75 75
  76 +$stryes = get_string('yes');
  77 +$strno = get_string('no');
  78 +$stryesnooptions = array(0=>$strno, 1=>$stryes);
  79 +
76 80 $returnurl = new moodle_url('/admin/tool/uploaduser/index.php');
77 81 $bulknurl = new moodle_url('/admin/user/user_bulk.php');
78 82
@@ -88,6 +92,7 @@
88 92 'url', 'description', 'descriptionformat', 'password',
89 93 'auth', // watch out when changing auth type or using external auth plugins!
90 94 'oldusername', // use when renaming users - this is the original username
  95 + 'suspended', // 1 means suspend user account, 0 means activate user account, nothing means keep as is for existing users
91 96 'deleted', // 1 means delete user
92 97 );
93 98
@@ -154,6 +159,7 @@
154 159 $updatepasswords = (!empty($formdata->uupasswordold) and $optype != UU_USER_ADDNEW and $optype != UU_USER_ADDINC and ($updatetype == UU_UPDATE_FILEOVERRIDE or $updatetype == UU_UPDATE_ALLOVERRIDE));
155 160 $allowrenames = (!empty($formdata->uuallowrenames) and $optype != UU_USER_ADDNEW and $optype != UU_USER_ADDINC);
156 161 $allowdeletes = (!empty($formdata->uuallowdeletes) and $optype != UU_USER_ADDNEW and $optype != UU_USER_ADDINC);
  162 + $allowsuspends = (!empty($formdata->uuallowsuspends));
157 163 $bulk = $formdata->uubulk;
158 164 $noemailduplicates = $formdata->uunoemailduplicates;
159 165 $standardusernames = $formdata->uustandardusernames;
@@ -446,6 +452,7 @@
446 452 $user->id = $existinguser->id;
447 453
448 454 $upt->track('username', html_writer::link(new moodle_url('/user/profile.php', array('id'=>$existinguser->id)), s($existinguser->username)), 'normal', false);
  455 + $upt->track('suspended', $stryesnooptions[$existinguser->suspended] , 'normal', false);
449 456
450 457 if (is_siteadmin($user->id)) {
451 458 $upt->track('status', $strusernotupdatedadmin, 'error');
@@ -462,6 +469,7 @@
462 469 $upt->track('auth', $existinguser->auth, 'normal', false);
463 470
464 471 $doupdate = false;
  472 + $dologout = false;
465 473
466 474 if ($updatetype != UU_UPDATE_NOCHANGES) {
467 475 if (!empty($user->auth) and $user->auth !== $existinguser->auth) {
@@ -471,10 +479,13 @@
471 479 $upt->track('auth', $struserauthunsupported, 'warning');
472 480 }
473 481 $doupdate = true;
  482 + if ($existinguser->auth === 'nologin') {
  483 + $dologout = true;
  484 + }
474 485 }
475 486 $allcolumns = array_merge($STD_FIELDS, $PRF_FIELDS);
476 487 foreach ($allcolumns as $column) {
477   - if ($column === 'username' or $column === 'password' or $column === 'auth') {
  488 + if ($column === 'username' or $column === 'password' or $column === 'auth' or $column === 'suspended') {
478 489 // these can not be changed here
479 490 continue;
480 491 }
@@ -531,6 +542,20 @@
531 542 }
532 543 $isinternalauth = $auth->is_internal();
533 544
  545 + // deal with suspending and activating of accounts
  546 + if ($allowsuspends and isset($user->suspended) and $user->suspended !== '') {
  547 + $user->suspended = $user->suspended ? 1 : 0;
  548 + if ($existinguser->suspended != $user->suspended) {
  549 + $upt->track('suspended', '', 'normal', false);
  550 + $upt->track('suspended', $stryesnooptions[$existinguser->suspended].'-->'.$stryesnooptions[$user->suspended], 'info', false);
  551 + $existinguser->suspended = $user->suspended;
  552 + $doupdate = true;
  553 + if ($existinguser->suspended) {
  554 + $dologout = true;
  555 + }
  556 + }
  557 + }
  558 +
534 559 // changing of passwords is a special case
535 560 // do not force password changes for external auth plugins!
536 561 $oldpw = $existinguser->password;
@@ -593,6 +618,10 @@
593 618 }
594 619 }
595 620
  621 + if ($dologout) {
  622 + session_kill_user($existinguser->id);
  623 + }
  624 +
596 625 } else {
597 626 // save the new user to the database
598 627 $user->confirmed = 1;
@@ -600,6 +629,13 @@
600 629 $user->timecreated = time();
601 630 $user->mnethostid = $CFG->mnet_localhost_id; // we support ONLY local accounts here, sorry
602 631
  632 + if (!isset($user->suspended) or $user->suspended === '') {
  633 + $user->suspended = 0;
  634 + } else {
  635 + $user->suspended = $user->suspended ? 1 : 0;
  636 + }
  637 + $upt->track('suspended', $stryesnooptions[$user->suspended], 'normal', false);
  638 +
603 639 if (empty($user->auth)) {
604 640 $user->auth = 'manual';
605 641 }
1  admin/tool/uploaduser/lang/en/tool_uploaduser.php
@@ -25,6 +25,7 @@
25 25
26 26 $string['allowdeletes'] = 'Allow deletes';
27 27 $string['allowrenames'] = 'Allow renames';
  28 +$string['allowsuspends'] = 'Allow suspending and activating of accounts';
28 29 $string['csvdelimiter'] = 'CSV delimiter';
29 30 $string['defaultvalues'] = 'Default values';
30 31 $string['deleteerrors'] = 'Delete errors';
3  admin/tool/uploaduser/locallib.php
@@ -56,7 +56,7 @@
56 56 */
57 57 class uu_progress_tracker {
58 58 private $_row;
59   - public $columns = array('status', 'line', 'id', 'username', 'firstname', 'lastname', 'email', 'password', 'auth', 'enrolments', 'deleted');
  59 + public $columns = array('status', 'line', 'id', 'username', 'firstname', 'lastname', 'email', 'password', 'auth', 'enrolments', 'suspended', 'deleted');
60 60
61 61 /**
62 62 * Print table header.
@@ -76,6 +76,7 @@ public function start() {
76 76 echo '<th class="header c'.$ci++.'" scope="col">'.get_string('password').'</th>';
77 77 echo '<th class="header c'.$ci++.'" scope="col">'.get_string('authentication').'</th>';
78 78 echo '<th class="header c'.$ci++.'" scope="col">'.get_string('enrolments', 'enrol').'</th>';
  79 + echo '<th class="header c'.$ci++.'" scope="col">'.get_string('suspended', 'auth').'</th>';
79 80 echo '<th class="header c'.$ci++.'" scope="col">'.get_string('delete').'</th>';
80 81 echo '</tr>';
81 82 $this->_row = null;
5 admin/tool/uploaduser/user_form.php
@@ -134,6 +134,11 @@ function definition () {
134 134 $mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_USER_ADDNEW);
135 135 $mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_USER_ADDINC);
136 136
  137 + $mform->addElement('selectyesno', 'uuallowsuspends', get_string('allowsuspends', 'tool_uploaduser'));
  138 + $mform->setDefault('uuallowsuspends', 1);
  139 + $mform->disabledIf('uuallowsuspends', 'uutype', 'eq', UU_USER_ADDNEW);
  140 + $mform->disabledIf('uuallowsuspends', 'uutype', 'eq', UU_USER_ADDINC);
  141 +
137 142 $mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'tool_uploaduser'));
138 143 $mform->setDefault('uunoemailduplicates', 1);
139 144

0 comments on commit 77536bd

Please sign in to comment.
Something went wrong with that request. Please try again.