forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow multiple roles to be allocated by identity provider * Allow existing enrolment plugins to manage mnet enrolments Author: Peter Bulmer <[email protected]>
- Loading branch information
peterbulmer
committed
Aug 3, 2009
1 parent
ab97dbe
commit 1b509b3
Showing
30 changed files
with
1,920 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); | ||
require_once('mnet_rolemapping_form.php'); | ||
require_once($CFG->dirroot .'/mnet/lib.php'); | ||
|
||
$mnethostid = required_param('hostid', PARAM_INT); | ||
$mnetpeer = mnet_get_peer_host($mnethostid); | ||
$PAGE->set_generaltype('form'); | ||
$PAGE->set_url('admin/mnet/mnet_rolemapping.php', array('hostid' => $mnethostid)); | ||
|
||
$pagetitle = get_string('mnetmaproles'); | ||
$extranavlinks = array( | ||
array('name' => 'Administration', 'link' => '', 'type'=> 'title'), | ||
array('name' => 'Networking', 'link' => '', 'type' => 'title'), | ||
array('name' => 'Peers', 'link' => $CFG->wwwroot . '/admin/mnet/peers.php', 'type' => 'title'), | ||
array('name' => $mnetpeer->name, 'link' => $CFG->wwwroot . '/admin/mnet/peers.php?hostid='.$mnethostid, 'type' => 'title'), | ||
array('name' => $pagetitle, 'link' => '', 'type' => 'title'), | ||
); | ||
$navigation = build_navigation($extranavlinks); | ||
print_header_simple($pagetitle, $pagetitle, $navigation, '', '', false); | ||
|
||
$mform = new rolemapping_form(); | ||
$rolessql = | ||
'SELECT r.id, r.shortname, r.name, rm.remoterole, rm.id as mapid ' . | ||
'FROM {role} r ' . | ||
' LEFT JOIN {mnet_role_mapping} rm ON rm.localrole = r.id AND rm.mnethost = ? '; | ||
$rolesparams = array($mnethostid); | ||
if ($mform->is_cancelled()){ | ||
redirect($CFG->wwwroot . '/admin/mnet/peers.php?hostid=' . $mnethostid, get_string('changescancelled'), 1); | ||
} else if ($fromform=$mform->get_data()) { | ||
$roles = $DB->get_records_sql($rolessql, $rolesparams); | ||
$usersinqueue = 0; | ||
|
||
if (!empty($roles)) { | ||
foreach ($roles as $role) { | ||
if (isset($fromform->{'rolemapping-' . $role->id})) { | ||
$newchoice = $fromform->{'rolemapping-' . $role->id}; | ||
} else { | ||
// User has somehow supplied the form without saying what to do with this role - assume they mean no role mapping: | ||
$newchoice = -1; | ||
} | ||
$toform['rolemapping-' . $role->id] = $newchoice; | ||
// Don't actually store non-mappings in db: | ||
if ($newchoice == -1) { | ||
$newchoice = NULL; | ||
} | ||
if ($newchoice === $role->remoterole) { | ||
// No change in this role mapping, nothing to do | ||
continue; | ||
} | ||
// Role mapping has changed - get everyone with this local role in queue to get their remote role updated. | ||
$usersinqueue += manage_role_mapping($mnethostid, $role->id); | ||
|
||
$rolemappingobj = new stdclass; | ||
$rolemappingobj->mnethost = $mnethostid; | ||
$rolemappingobj->localrole = $role->id; | ||
$rolemappingobj->remoterole = $newchoice; | ||
if (isset($role->remoterole)) { | ||
if ($newchoice === NULL) { | ||
$DB->delete_records('mnet_role_mapping', array('id' => $role->mapid)); | ||
} else { | ||
$rolemappingobj->id = $role->mapid; | ||
$DB->update_record('mnet_role_mapping', $rolemappingobj); | ||
} | ||
} else { | ||
$DB->insert_record('mnet_role_mapping', $rolemappingobj); | ||
} | ||
} | ||
} | ||
print_string('settingssaved'); | ||
echo '<br />'; | ||
if ($usersinqueue) { | ||
print_string('mnetusersinqueue', 'moodle', $usersinqueue); | ||
} | ||
|
||
$toform['hostid'] = $mnethostid; | ||
$mform->set_data($toform); | ||
$mform->display(); | ||
print_footer(); | ||
|
||
} else { | ||
$toform = array(); | ||
$roles = $DB->get_records_sql($rolessql, $rolesparams); | ||
if (!empty($roles)) { | ||
foreach ($roles as $role) { | ||
if (isset($role->remoterole)) { | ||
$toform['rolemapping-' . $role->id] = $role->remoterole; | ||
} else { | ||
$toform['rolemapping-' . $role->id] = -1; | ||
} | ||
} | ||
} | ||
$toform['hostid'] = $mnethostid; | ||
|
||
$mform->set_data($toform); | ||
$mform->display(); | ||
print_footer(); | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
require_once ('../../config.php'); | ||
require_once ($CFG->libdir . '/formslib.php'); | ||
|
||
class rolemapping_form extends moodleform { | ||
|
||
function definition() { | ||
|
||
global $CFG; | ||
$mform =& $this->_form; | ||
$mform->addElement('header', 'mapping', get_string('mnetrolemapping')); | ||
$mform->addElement('static', 'instructions', '',get_string('mnetrolemappinginstructions'), ' '); | ||
$mform->addElement('hidden', 'hostid', 'yes'); | ||
$this->add_action_buttons(); | ||
|
||
} | ||
|
||
function definition_after_data() { | ||
global $CFG, $DB; | ||
require_once($CFG->dirroot . '/mnet/lib.php'); | ||
$mform =& $this->_form; | ||
$mnethostid = $mform->getElementValue('hostid'); | ||
$mnethost = $DB->get_record('mnet_host', array('id' => $mnethostid)); | ||
$remoteroleoptions = array(); | ||
|
||
$rolessql = 'SELECT r.id, r.shortname, r.name, rm.remoterole, rm.id as mapid ' . | ||
'FROM {role} r ' . | ||
' LEFT JOIN {mnet_role_mapping} rm ON rm.localrole = r.id and rm.mnethost = ? ' . | ||
'ORDER BY r.id'; | ||
$rolesparams = array($mnethostid); | ||
$roles = $DB->get_records_sql($rolessql, $rolesparams); | ||
|
||
// Determine if we already have a role mapped to a remote role (mappings to default role don't count) | ||
$actualremoterole = false; | ||
foreach ($roles as $role) { | ||
if (!empty($role->remoterole)) { | ||
$actualremoterole = true; | ||
break; | ||
} | ||
} | ||
|
||
$remotedefaultrole = false; | ||
if (!$actualremoterole) { | ||
// Remote peer may be old & unable to tell us what roles it shares | ||
// See if the mnet peer has upgraded to new mnet code since we last checked | ||
// If it knows how to tell us it's default role, it also knows how to tell us what roles it shares w/ us | ||
$remotedefaultrole = mnet_get_default_role($mnethostid); | ||
if (!empty($remotedefaultrole)) { | ||
$DB->set_field('mnet_role_mapping', 'remoterole', $remotedefaultrole->id, | ||
array('remoterole' => 0, 'mnethost' => $mnethostid)); | ||
$actualremoterole = true; | ||
} | ||
} | ||
if ($actualremoterole) { | ||
$remoteroles = mnet_get_allocatable_roles($mnethostid); | ||
foreach ($remoteroles as $remoterole) { | ||
$remoteroleoptions[$remoterole->id] = $mnethost->name . ' - ' . $remoterole->shortname; | ||
} | ||
} else { | ||
//Still talking to an mnet peer that does't publish more than one role, | ||
// and doesn't know how to tell us what that role is: | ||
$remoteroleoptions[0] = $mnethost->name . ' - Default Role'; | ||
} | ||
|
||
$remoteroleoptions[-1] = 'No Role'; | ||
foreach ($roles as $role) { | ||
$mform->addElement('select', 'rolemapping-' . $role->id, | ||
$role->name . ' (' . $role->shortname . ') ', | ||
$remoteroleoptions); | ||
if (!empty($role->remoterole) && !isset($remoteroleoptions[$role->remoterole])) { | ||
//The remote role that this role is currently mapped to isn't shared any more | ||
$DB->delete_records('mnet_role_mapping', array('id' => $role->mapid)); | ||
manage_role_mapping($mnethostid, $role->id); | ||
} | ||
} | ||
$mform->removeElement('buttonar'); | ||
$this->add_action_buttons(); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); | ||
require_once('mnet_rolespermitted_form.php'); | ||
require_once($CFG->dirroot .'/mnet/lib.php'); | ||
|
||
$mnethostid = required_param('hostid', PARAM_INT); | ||
$mnetpeer = mnet_get_peer_host($mnethostid); | ||
$PAGE->set_generaltype('form'); | ||
$PAGE->set_url('admin/mnet/mnet_rolespermitted.php', array('hostid' => $mnethostid)); | ||
|
||
$pagetitle = get_string('mnetauthorisemnetroles'); | ||
$extranavlinks = array( | ||
array('name' => 'Administration', 'link' => '', 'type' => 'title'), | ||
array('name' => 'Networking', 'link' => '', 'type' => 'title'), | ||
array('name' => 'Peers', 'link' => $CFG->wwwroot . '/admin/mnet/peers.php', 'type' => 'title'), | ||
array('name' => $mnetpeer->name, 'link' => $CFG->wwwroot . '/admin/mnet/peers.php?hostid='.$mnethostid, 'type' => 'title'), | ||
array('name' => $pagetitle, 'link' => '', 'type' => 'title'), | ||
); | ||
$navigation = build_navigation($extranavlinks); | ||
print_header_simple($pagetitle, $pagetitle, $navigation, '', '', false); | ||
$rolessql = | ||
'SELECT ' . | ||
' r.id, r.shortname, r.name, rp.localrole as prepublished ' . | ||
'FROM {role} r ' . | ||
' LEFT JOIN {mnet_role_published} rp ON rp.localrole = r.id and rp.mnethost = ? '; | ||
$rolesparams = array($mnethostid); | ||
|
||
$mform = new rolespermitted_form(); | ||
if ($mform->is_cancelled()){ | ||
redirect($CFG->wwwroot . '/admin/mnet/peers.php?hostid=' . $mnethostid, get_string('changescancelled'), 1); | ||
} else if ($fromform=$mform->get_data()) { | ||
$roles = $DB->get_records_sql($rolessql, $rolesparams); | ||
$rolepublication = new stdclass(); | ||
$rolepublication->mnethost = $mnethostid; | ||
foreach ($roles as $role) { | ||
$rolepublication->localrole = $role->id; | ||
if(isset($fromform->{$role->shortname})) { | ||
// Role checkbox was ticked - add publication entry if not already present. | ||
if (empty($role->prepublished)) { | ||
$DB->insert_record('mnet_role_published', $rolepublication); | ||
$toform[$role->shortname] = 1; | ||
} | ||
} else { | ||
// Role checkbox was not ticked - delete its publication entry (if present) | ||
if (!empty($role->prepublished)) { | ||
$DB->delete_records('mnet_role_published', | ||
array('mnethost' => $rolepublication->mnethost, | ||
'localrole' => $rolepublication->localrole)); | ||
unassign_role_peer($rolepublication->localrole, $rolepublication->mnethost); | ||
} | ||
} | ||
} | ||
print_string('settingssaved'); | ||
$toform['hostid'] = $mnethostid; | ||
$mform->set_data($toform); | ||
$mform->display(); | ||
print_footer(); | ||
|
||
} else { | ||
$toform = array(); | ||
|
||
$roles = $DB->get_records_sql($rolessql, $rolesparams); | ||
foreach ($roles as $role) { | ||
if (!empty($role->prepublished)) { | ||
$toform[$role->shortname] = 1; | ||
} | ||
} | ||
$toform['hostid'] = $mnethostid; | ||
|
||
$mform->set_data($toform); | ||
$mform->display(); | ||
print_footer(); | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
require_once ('../../config.php'); | ||
require_once ($CFG->libdir . '/formslib.php'); | ||
|
||
class rolespermitted_form extends moodleform { | ||
|
||
function definition() { | ||
|
||
global $DB; | ||
$mform =& $this->_form; | ||
$mform->addElement('header', 'permitted', get_string('mnetpermittedroles')); | ||
$mform->addElement('static', 'instructions', '',get_string('mnetpermittedrolesinstructions'), ' '); | ||
$mform->addElement('hidden', 'hostid', 'yes'); | ||
$roles = $DB->get_records('role', array(), 'id'); | ||
foreach ($roles as $role) { | ||
$mform->addElement('checkbox', $role->shortname, $role->name,'('.$role->shortname.')'); | ||
} | ||
|
||
|
||
// buttons | ||
$this->add_action_buttons(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.