mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-29469 Enrolments - fixing the role assignment access elevation issue
This commit is contained in:
parent
79b0fece1f
commit
2c5857186b
@ -59,9 +59,9 @@ class enrol_self_edit_form extends moodleform {
|
||||
$mform->setDefault('customint1', $plugin->get_config('groupkey'));
|
||||
|
||||
if ($instance->id) {
|
||||
$roles = get_default_enrol_roles($context, $instance->roleid);
|
||||
$roles = $this->extend_assignable_roles($context, $instance->roleid);
|
||||
} else {
|
||||
$roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
|
||||
$roles = $this->extend_assignable_roles($context, $plugin->get_config('roleid'));
|
||||
}
|
||||
$mform->addElement('select', 'roleid', get_string('role', 'enrol_self'), $roles);
|
||||
$mform->setDefault('roleid', $plugin->get_config('roleid'));
|
||||
@ -156,4 +156,24 @@ class enrol_self_edit_form extends moodleform {
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of roles that this user can assign for the course as the default for self-enrolment
|
||||
*
|
||||
* @param context $context the context.
|
||||
* @param integer $defaultrole the id of the role that is set as the default for self-enrolement
|
||||
* @return array index is the role id, value is the role name
|
||||
*/
|
||||
function extend_assignable_roles($context, $defaultrole) {
|
||||
global $DB;
|
||||
$roles = get_assignable_roles($context);
|
||||
$sql = "SELECT r.id, r.name
|
||||
FROM {role} r
|
||||
WHERE r.id = $defaultrole";
|
||||
$results = $DB->get_record_sql($sql);
|
||||
if (isset($results->name)) {
|
||||
$roles[$results->id] = $results->name;
|
||||
}
|
||||
return $roles;
|
||||
}
|
||||
}
|
@ -61,7 +61,7 @@ $string['pluginname'] = 'Self enrolment';
|
||||
$string['pluginname_desc'] = 'The self enrolment plugin allows users to choose which courses they want to participate in. The courses may be protected by an enrolment key. Internally the enrolment is done via the manual enrolment plugin which has to be enabled in the same course.';
|
||||
$string['requirepassword'] = 'Require enrolment key';
|
||||
$string['requirepassword_desc'] = 'Require enrolment key in new courses and prevent removing of enrolment key from existing courses.';
|
||||
$string['role'] = 'Assign role';
|
||||
$string['role'] = 'Default assigned role';
|
||||
$string['self:config'] = 'Configure self enrol instances';
|
||||
$string['self:manage'] = 'Manage enrolled users';
|
||||
$string['self:unenrol'] = 'Unenrol users from course';
|
||||
|
Loading…
x
Reference in New Issue
Block a user