mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merged branch 'w52_MDL-30548_m23_suspenduser' of git://github.com/skodak/moodle.git with conflict resolution
This commit is contained in:
commit
44d5c138a2
11 changed files with 150 additions and 54 deletions
|
@ -127,7 +127,9 @@ if ($hassiteconfig
|
|||
'firstaccess' => new lang_string('firstaccess'),
|
||||
'lastaccess' => new lang_string('lastaccess'),
|
||||
'mycourses' => new lang_string('mycourses'),
|
||||
'groups' => new lang_string('groups'))));
|
||||
'groups' => new lang_string('groups'),
|
||||
'suspended' => new lang_string('suspended', 'auth'),
|
||||
)));
|
||||
|
||||
// Select fields to display as part of user identity (only to those
|
||||
// with moodle/site:viewuseridentity).
|
||||
|
|
150
admin/user.php
150
admin/user.php
|
@ -14,7 +14,8 @@
|
|||
$ru = optional_param('ru', '2', PARAM_INT); // show remote users
|
||||
$lu = optional_param('lu', '2', PARAM_INT); // show local users
|
||||
$acl = optional_param('acl', '0', PARAM_INT); // id of user to tweak mnet ACL (requires $access)
|
||||
|
||||
$suspend = optional_param('suspend', 0, PARAM_INT);
|
||||
$unsuspend = optional_param('unsuspend', 0, PARAM_INT);
|
||||
|
||||
admin_externalpage_setup('editusers');
|
||||
|
||||
|
@ -29,6 +30,9 @@
|
|||
$strdelete = get_string('delete');
|
||||
$strdeletecheck = get_string('deletecheck');
|
||||
$strshowallusers = get_string('showallusers');
|
||||
$strsuspend = get_string('suspenduser', 'admin');
|
||||
$strunsuspend = get_string('unsuspenduser', 'admin');
|
||||
$strconfirm = get_string('confirm');
|
||||
|
||||
if (empty($CFG->loginhttps)) {
|
||||
$securewwwroot = $CFG->wwwroot;
|
||||
|
@ -36,10 +40,11 @@
|
|||
$securewwwroot = str_replace('http:','https:',$CFG->wwwroot);
|
||||
}
|
||||
|
||||
$returnurl = "$CFG->wwwroot/$CFG->admin/user.php";
|
||||
$returnurl = new moodle_url('/admin/user.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage, 'page'=>$page));
|
||||
|
||||
if ($confirmuser and confirm_sesskey()) {
|
||||
if (!$user = $DB->get_record('user', array('id'=>$confirmuser))) {
|
||||
require_capability('moodle/user:update', $sitecontext);
|
||||
if (!$user = $DB->get_record('user', array('id'=>$confirmuser, 'mnethostid'=>$CFG->mnet_localhost_id))) {
|
||||
print_error('nousers');
|
||||
}
|
||||
|
||||
|
@ -55,10 +60,9 @@
|
|||
}
|
||||
|
||||
} else if ($delete and confirm_sesskey()) { // Delete a selected user, after confirmation
|
||||
|
||||
require_capability('moodle/user:delete', $sitecontext);
|
||||
|
||||
$user = $DB->get_record('user', array('id'=>$delete), '*', MUST_EXIST);
|
||||
$user = $DB->get_record('user', array('id'=>$delete, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);
|
||||
|
||||
if (is_siteadmin($user->id)) {
|
||||
print_error('useradminodelete', 'error');
|
||||
|
@ -69,7 +73,7 @@
|
|||
$fullname = fullname($user, true);
|
||||
echo $OUTPUT->heading(get_string('deleteuser', 'admin'));
|
||||
$optionsyes = array('delete'=>$delete, 'confirm'=>md5($delete), 'sesskey'=>sesskey());
|
||||
echo $OUTPUT->confirm(get_string('deletecheckfull', '', "'$fullname'"), new moodle_url('user.php', $optionsyes), 'user.php');
|
||||
echo $OUTPUT->confirm(get_string('deletecheckfull', '', "'$fullname'"), new moodle_url($returnurl, $optionsyes), $returnurl);
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
} else if (data_submitted() and !$user->deleted) {
|
||||
|
@ -83,8 +87,7 @@
|
|||
}
|
||||
}
|
||||
} else if ($acl and confirm_sesskey()) {
|
||||
if (!has_capability('moodle/user:delete', $sitecontext)) {
|
||||
// TODO: this should be under a separate capability
|
||||
if (!has_capability('moodle/user:update', $sitecontext)) {
|
||||
print_error('nopermissions', 'error', '', 'modify the NMET access control list');
|
||||
}
|
||||
if (!$user = $DB->get_record('user', array('id'=>$acl))) {
|
||||
|
@ -110,6 +113,36 @@
|
|||
}
|
||||
$mnethosts = $DB->get_records('mnet_host', null, 'id', 'id,wwwroot,name');
|
||||
redirect($returnurl);
|
||||
|
||||
} else if ($suspend and confirm_sesskey()) {
|
||||
require_capability('moodle/user:update', $sitecontext);
|
||||
|
||||
if ($user = $DB->get_record('user', array('id'=>$suspend, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0))) {
|
||||
if (!is_siteadmin($user) and $USER->id != $user->id and $user->suspended != 1) {
|
||||
$user->suspended = 1;
|
||||
$user->timemodified = time();
|
||||
$DB->set_field('user', 'suspended', $user->suspended, array('id'=>$user->id));
|
||||
$DB->set_field('user', 'timemodified', $user->timemodified, array('id'=>$user->id));
|
||||
// force logout
|
||||
session_kill_user($user->id);
|
||||
events_trigger('user_updated', $user);
|
||||
}
|
||||
}
|
||||
redirect($returnurl);
|
||||
|
||||
} else if ($unsuspend and confirm_sesskey()) {
|
||||
require_capability('moodle/user:update', $sitecontext);
|
||||
|
||||
if ($user = $DB->get_record('user', array('id'=>$unsuspend, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0))) {
|
||||
if ($user->suspended != 0) {
|
||||
$user->suspended = 0;
|
||||
$user->timemodified = time();
|
||||
$DB->set_field('user', 'suspended', $user->suspended, array('id'=>$user->id));
|
||||
$DB->set_field('user', 'timemodified', $user->timemodified, array('id'=>$user->id));
|
||||
events_trigger('user_updated', $user);
|
||||
}
|
||||
}
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
// create the user filter form
|
||||
|
@ -163,7 +196,7 @@
|
|||
|
||||
$strall = get_string('all');
|
||||
|
||||
$baseurl = new moodle_url('user.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage));
|
||||
$baseurl = new moodle_url('/admin/user.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage));
|
||||
echo $OUTPUT->paging_bar($usercount, $page, $perpage, $baseurl);
|
||||
|
||||
flush();
|
||||
|
@ -225,9 +258,7 @@
|
|||
$table->align[] = 'left';
|
||||
$table->head[] = $lastaccess;
|
||||
$table->align[] = 'left';
|
||||
$table->head[] = "";
|
||||
$table->align[] = 'center';
|
||||
$table->head[] = "";
|
||||
$table->head[] = get_string('edit');
|
||||
$table->align[] = 'center';
|
||||
$table->head[] = "";
|
||||
$table->align[] = 'center';
|
||||
|
@ -238,52 +269,65 @@
|
|||
continue; // do not display guest here
|
||||
}
|
||||
|
||||
if ($user->id == $USER->id or is_siteadmin($user)) {
|
||||
$deletebutton = "";
|
||||
} else {
|
||||
if (has_capability('moodle/user:delete', $sitecontext)) {
|
||||
$deletebutton = "<a href=\"user.php?delete=$user->id&sesskey=".sesskey()."\">$strdelete</a>";
|
||||
$buttons = array();
|
||||
$lastcolumn = '';
|
||||
|
||||
// delete button
|
||||
if (has_capability('moodle/user:delete', $sitecontext)) {
|
||||
if (is_mnet_remote_user($user) or $user->id == $USER->id or is_siteadmin($user)) {
|
||||
// no deleting of self, mnet accounts or admins allowed
|
||||
} else {
|
||||
$deletebutton ="";
|
||||
$buttons[] = html_writer::link(new moodle_url($returnurl, array('delete'=>$user->id, 'sesskey'=>sesskey())), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>$strdelete, 'class'=>'iconsmall')), array('title'=>$strdelete));
|
||||
}
|
||||
}
|
||||
|
||||
if (has_capability('moodle/user:update', $sitecontext) and (is_siteadmin($USER) or !is_siteadmin($user)) and !is_mnet_remote_user($user)) {
|
||||
$editbutton = "<a href=\"$securewwwroot/user/editadvanced.php?id=$user->id&course=$site->id\">$stredit</a>";
|
||||
if ($user->confirmed == 0) {
|
||||
$confirmbutton = "<a href=\"user.php?confirmuser=$user->id&sesskey=".sesskey()."\">" . get_string('confirm') . "</a>";
|
||||
// suspend button
|
||||
if (has_capability('moodle/user:update', $sitecontext)) {
|
||||
if (is_mnet_remote_user($user)) {
|
||||
// mnet users have special access control, they can not be deleted the standard way or suspended
|
||||
$accessctrl = 'allow';
|
||||
if ($acl = $DB->get_record('mnet_sso_access_control', array('username'=>$user->username, 'mnet_host_id'=>$user->mnethostid))) {
|
||||
$accessctrl = $acl->accessctrl;
|
||||
}
|
||||
$changeaccessto = ($accessctrl == 'deny' ? 'allow' : 'deny');
|
||||
$buttons[] = " (<a href=\"?acl={$user->id}&accessctrl=$changeaccessto&sesskey=".sesskey()."\">".get_string($changeaccessto, 'mnet') . " access</a>)";
|
||||
|
||||
} else {
|
||||
$confirmbutton = "";
|
||||
}
|
||||
} else {
|
||||
$editbutton ="";
|
||||
if ($user->confirmed == 0) {
|
||||
$confirmbutton = "<span class=\"dimmed_text\">".get_string('confirm')."</span>";
|
||||
} else {
|
||||
$confirmbutton = "";
|
||||
if ($user->suspended) {
|
||||
$buttons[] = html_writer::link(new moodle_url($returnurl, array('unsuspend'=>$user->id, 'sesskey'=>sesskey())), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/show'), 'alt'=>$strunsuspend, 'class'=>'iconsmall')), array('title'=>$strunsuspend));
|
||||
} else {
|
||||
if ($user->id == $USER->id or is_siteadmin($user)) {
|
||||
// no suspending of admins or self!
|
||||
} else {
|
||||
$buttons[] = html_writer::link(new moodle_url($returnurl, array('suspend'=>$user->id, 'sesskey'=>sesskey())), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/hide'), 'alt'=>$strsuspend, 'class'=>'iconsmall')), array('title'=>$strsuspend));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// for remote users, shuffle columns around and display MNET stuff
|
||||
// edit button
|
||||
if (has_capability('moodle/user:update', $sitecontext)) {
|
||||
// prevent editing of admins by non-admins
|
||||
if (is_siteadmin($USER) or !is_siteadmin($user)) {
|
||||
$buttons[] = html_writer::link(new moodle_url($securewwwroot.'/user/editadvanced.php', array('id'=>$user->id, 'course'=>$site->id)), html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/edit'), 'alt'=>$stredit, 'class'=>'iconsmall')), array('title'=>$stredit));
|
||||
}
|
||||
}
|
||||
|
||||
// the last column - confirm or mnet info
|
||||
if (is_mnet_remote_user($user)) {
|
||||
$accessctrl = 'allow';
|
||||
if ($acl = $DB->get_record('mnet_sso_access_control', array('username'=>$user->username, 'mnet_host_id'=>$user->mnethostid))) {
|
||||
$accessctrl = $acl->accessctrl;
|
||||
}
|
||||
$changeaccessto = ($accessctrl == 'deny' ? 'allow' : 'deny');
|
||||
// delete button in confirm column - remote users should already be confirmed
|
||||
// TODO: no delete for remote users, for now. new userid, delete flag, unique on username/host...
|
||||
$confirmbutton = "";
|
||||
// ACL in delete column
|
||||
$deletebutton = get_string($accessctrl, 'mnet');
|
||||
if (has_capability('moodle/user:delete', $sitecontext)) {
|
||||
// TODO: this should be under a separate capability
|
||||
$deletebutton .= " (<a href=\"?acl={$user->id}&accessctrl=$changeaccessto&sesskey=".sesskey()."\">"
|
||||
. get_string($changeaccessto, 'mnet') . " access</a>)";
|
||||
}
|
||||
// mnet info in edit column
|
||||
// all mnet users are confirmed, let's print just the name of the host there
|
||||
if (isset($mnethosts[$user->mnethostid])) {
|
||||
$editbutton = $mnethosts[$user->mnethostid]->name;
|
||||
$lastcolumn = get_string($accessctrl, 'mnet').': '.$mnethosts[$user->mnethostid]->name;
|
||||
} else {
|
||||
$lastcolumn = get_string($accessctrl, 'mnet');
|
||||
}
|
||||
|
||||
} else if ($user->confirmed == 0) {
|
||||
if (has_capability('moodle/user:update', $sitecontext)) {
|
||||
$lastcolumn = html_writer::link(new moodle_url($returnurl, array('confirmuser'=>$user->id, 'sesskey'=>sesskey())), $strconfirm);
|
||||
} else {
|
||||
$lastcolumn = "<span class=\"dimmed_text\">".get_string('confirm')."</span>";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,9 +346,13 @@
|
|||
$row[] = $user->city;
|
||||
$row[] = $user->country;
|
||||
$row[] = $strlastaccess;
|
||||
$row[] = $editbutton;
|
||||
$row[] = $deletebutton;
|
||||
$row[] = $confirmbutton;
|
||||
if ($user->suspended) {
|
||||
foreach ($row as $k=>$v) {
|
||||
$row[$k] = html_writer::tag('span', $v, array('class'=>'usersuspended'));
|
||||
}
|
||||
}
|
||||
$row[] = implode(' ', $buttons);
|
||||
$row[] = $lastcolumn;
|
||||
$table->data[] = $row;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue