mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
mnet MDL-20660 allow admins to configure fields to be sent over mnet
This commit is contained in:
parent
4e780305e7
commit
61506902f3
@ -47,18 +47,17 @@ if ($data = $form->get_data()) {
|
||||
if (!isset($data->exportdefault)) {
|
||||
$data->exportdefault = 0;
|
||||
}
|
||||
if (!isset($data->importfields)) {
|
||||
$data->importfields = array();
|
||||
}
|
||||
if (!isset($data->exportfields)) {
|
||||
$data->exportfields = array();
|
||||
}
|
||||
set_config('host' . $hostid . 'importdefault', $data->importdefault, 'mnet');
|
||||
if (!$data->importdefault) {
|
||||
set_config('host' . $hostid . 'importfields', implode(',', $data->importfields), 'mnet');
|
||||
} else {
|
||||
unset_config('host' . $hostid . 'importfields', 'mnet');
|
||||
}
|
||||
set_config('host' . $hostid . 'importfields', implode(',', $data->importfields), 'mnet');
|
||||
set_config('host' . $hostid . 'exportdefault', $data->exportdefault, 'mnet');
|
||||
if (!$data->exportdefault) {
|
||||
set_config('host' . $hostid . 'exportfields', implode(',', $data->exportfields), 'mnet');
|
||||
} else {
|
||||
unset_config('host' . $hostid . 'exportfields', 'mnet');
|
||||
}
|
||||
set_config('host' . $hostid . 'exportfields', implode(',', $data->exportfields), 'mnet');
|
||||
|
||||
redirect('/admin/mnet/peers.php', get_string('changessaved'));
|
||||
} elseif ($form->is_cancelled()) {
|
||||
redirect('/admin/mnet/peers.php?hostid=' . $hostid);
|
||||
|
@ -72,27 +72,14 @@ class auth_plugin_mnet extends auth_plugin_base {
|
||||
throw new mnet_server_exception(3, get_string('authfail_usermismatch', 'mnet'));
|
||||
}
|
||||
|
||||
$userdata = array();
|
||||
$userdata['username'] = $user->username;
|
||||
$userdata['email'] = $user->email;
|
||||
$userdata = mnet_strip_user((array)$user, mnet_fields_to_send($remoteclient));
|
||||
|
||||
// extra special ones
|
||||
$userdata['auth'] = 'mnet';
|
||||
$userdata['confirmed'] = $user->confirmed;
|
||||
$userdata['deleted'] = $user->deleted;
|
||||
$userdata['firstname'] = $user->firstname;
|
||||
$userdata['lastname'] = $user->lastname;
|
||||
$userdata['city'] = $user->city;
|
||||
$userdata['country'] = $user->country;
|
||||
$userdata['lang'] = $user->lang;
|
||||
$userdata['timezone'] = $user->timezone;
|
||||
$userdata['description'] = $user->description;
|
||||
$userdata['mailformat'] = $user->mailformat;
|
||||
$userdata['maildigest'] = $user->maildigest;
|
||||
$userdata['maildisplay'] = $user->maildisplay;
|
||||
$userdata['htmleditor'] = $user->htmleditor;
|
||||
$userdata['wwwroot'] = $this->mnet->wwwroot;
|
||||
$userdata['session.gc_maxlifetime'] = ini_get('session.gc_maxlifetime');
|
||||
$userdata['picture'] = $user->picture;
|
||||
if (!empty($user->picture)) {
|
||||
|
||||
if (array_key_exists('picture', $userdata) && !empty($user->picture)) {
|
||||
$imagefile = make_user_directory($user->id, true) . "/f1.jpg";
|
||||
if (file_exists($imagefile)) {
|
||||
$userdata['imagehash'] = sha1(file_get_contents($imagefile));
|
||||
@ -262,6 +249,11 @@ class auth_plugin_mnet extends auth_plugin_base {
|
||||
exit;
|
||||
}
|
||||
|
||||
$remoteuser = mnet_strip_user($remoteuser, mnet_fields_to_import($remotepeer));
|
||||
|
||||
$remoteuser->auth = 'mnet';
|
||||
$remoteuser->wwwroot = $remotepeer->wwwroot;
|
||||
|
||||
$firsttime = false;
|
||||
|
||||
// get the local record for the remote user
|
||||
|
@ -299,14 +299,10 @@ class enrolment_plugin_mnet {
|
||||
$userrecord = $DB->get_record('user',array('username'=>$user['username'], 'mnethostid'=>$remoteclient->id));
|
||||
|
||||
if ($userrecord == false) {
|
||||
// We should at least be checking that we allow the remote
|
||||
// site to create users
|
||||
// TODO: more rigour here thanks!
|
||||
$userrecord = new stdClass();
|
||||
$userrecord->username = $user['username'];
|
||||
$userrecord->email = $user['email'];
|
||||
$userrecord->firstname = $user['firstname'];
|
||||
$userrecord->lastname = $user['lastname'];
|
||||
$userrecord = mnet_strip_user((object)$user, mnet_fields_to_import($remoteclient));
|
||||
// TODO maybe check a setting here to see whether
|
||||
// we allow the remote site to create users
|
||||
// see MDL-21327
|
||||
$userrecord->mnethostid = $remoteclient->id;
|
||||
|
||||
//TODO - username required to use PARAM_USERNAME before inserting into user table (MDL-16919)
|
||||
@ -505,9 +501,9 @@ class enrolment_plugin_mnet {
|
||||
global $CFG, $USER, $DB;
|
||||
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
|
||||
|
||||
// Prepare a basic user record
|
||||
// Prepare a user record
|
||||
// in case the remote host doesn't have it
|
||||
$user = $DB->get_record('user', array('id'=>$userid), 'username, email, firstname, lastname');
|
||||
$user = $DB->get_record('user', array('id'=>$userid));
|
||||
$user = (array)$user;
|
||||
|
||||
$course = $DB->get_record('mnet_enrol_course', array('id'=>$courseid));
|
||||
@ -519,7 +515,7 @@ class enrolment_plugin_mnet {
|
||||
// set up the RPC request
|
||||
$mnetrequest = new mnet_xmlrpc_client();
|
||||
$mnetrequest->set_method('enrol/mnet/enrol.php/enrol_user');
|
||||
$mnetrequest->add_param($user);
|
||||
$mnetrequest->add_param(mnet_strip_user($user, mnet_fields_to_send($mnet_sp)));
|
||||
$mnetrequest->add_param($course->remoteid);
|
||||
|
||||
// Thunderbirds are go! Do RPC call and store response
|
||||
|
79
mnet/lib.php
79
mnet/lib.php
@ -579,11 +579,15 @@ function mnet_profile_field_options() {
|
||||
);
|
||||
|
||||
// these are the ones that user_not_fully_set_up will complain about
|
||||
// and also special case ones
|
||||
$forced = array(
|
||||
'username',
|
||||
'email',
|
||||
'firstname',
|
||||
'lastname',
|
||||
'auth',
|
||||
'wwwroot',
|
||||
'session.gc_lifetime',
|
||||
);
|
||||
|
||||
// these are the ones we used to send/receive (pre 2.0)
|
||||
@ -804,3 +808,78 @@ function mnet_get_service_info(mnet_peer $mnet_peer, $fulldata=true) {
|
||||
|
||||
return $cache[$mnet_peer->id][$requestkey];
|
||||
}
|
||||
|
||||
/**
|
||||
* return an array of the profile fields to send
|
||||
* with user information to the given mnet host.
|
||||
*
|
||||
* @param mnet_peer $peer the peer to send the information to
|
||||
*
|
||||
* @return array (like 'username', 'firstname', etc)
|
||||
*/
|
||||
function mnet_fields_to_send(mnet_peer $peer) {
|
||||
return _mnet_field_helper($peer, 'export');
|
||||
}
|
||||
|
||||
/**
|
||||
* return an array of the profile fields to import
|
||||
* from the given host, when creating/updating user accounts
|
||||
*
|
||||
* @param mnet_peer $peer the peer we're getting the information from
|
||||
*
|
||||
* @return array (like 'username', 'firstname', etc)
|
||||
*/
|
||||
function mnet_fields_to_import(mnet_peer $peer) {
|
||||
return _mnet_field_helper($peer, 'import');
|
||||
}
|
||||
|
||||
/**
|
||||
* helper for {@see mnet_fields_to_import} and {@mnet_fields_to_send}
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @param mnet_peer $peer the peer object
|
||||
* @param string $key 'import' or 'export'
|
||||
*
|
||||
* @return array (like 'username', 'firstname', etc)
|
||||
*/
|
||||
function _mnet_field_helper(mnet_peer $peer, $key) {
|
||||
$tmp = mnet_profile_field_options();
|
||||
$defaults = explode(',', get_config('mnetprofile' . $key . 'fields'));
|
||||
if (1 === get_config('mnet', 'host' . $peer->id . $key . 'default')) {
|
||||
return array_merge($tmp['forced'], $defaults);
|
||||
}
|
||||
$hostsettings = get_config('mnet', 'host' . $peer->id . $key . 'fields');
|
||||
if (false === $hostsettings) {
|
||||
return array_merge($tmp['forced'], $defaults);
|
||||
}
|
||||
return array_merge($tmp['forced'], explode(',', $hostsettings));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* given a user object (or array) and a list of allowed fields,
|
||||
* strip out all the fields that should not be included.
|
||||
* This can be used both for outgoing data and incoming data.
|
||||
*
|
||||
* @param mixed $user array or object representing a database record
|
||||
* @param array $fields an array of allowed fields (usually from mnet_fields_to_{send,import}
|
||||
*
|
||||
* @return mixed array or object, depending what type of $user object was passed (datatype is respected)
|
||||
*/
|
||||
function mnet_strip_user($user, $fields) {
|
||||
if (is_object($user)) {
|
||||
$user = (array)$user;
|
||||
$wasobject = true; // so we can cast back before we return
|
||||
}
|
||||
|
||||
foreach ($user as $key => $value) {
|
||||
if (!in_array($key, $fields)) {
|
||||
unset($user[$key]);
|
||||
}
|
||||
}
|
||||
if (!empty($wasobject)) {
|
||||
$user = (object)$user;
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user