mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
MDL-27233 allow adding of default role to restorers
This commit is contained in:
parent
d53e3298c0
commit
73d000f389
@ -89,6 +89,9 @@ if ($hassiteconfig
|
||||
$defaultuserid = 0;
|
||||
}
|
||||
|
||||
$restorersnewrole = $creatornewroles;
|
||||
$restorersnewrole[0] = get_string('none');
|
||||
|
||||
$temp->add(new admin_setting_configselect('notloggedinroleid', get_string('notloggedinroleid', 'admin'),
|
||||
get_string('confignotloggedinroleid', 'admin'), $defaultguestid, ($guestroles + $otherroles)));
|
||||
$temp->add(new admin_setting_configselect('guestroleid', get_string('guestroleid', 'admin'),
|
||||
@ -97,12 +100,15 @@ if ($hassiteconfig
|
||||
get_string('configdefaultuserroleid', 'admin'), $defaultuserid, ($userroles + $otherroles)));
|
||||
$temp->add(new admin_setting_configselect('creatornewroleid', get_string('creatornewroleid', 'admin'),
|
||||
get_string('creatornewroleid_help', 'admin'), $defaultteacherid, $creatornewroles));
|
||||
$temp->add(new admin_setting_configselect('restorernewroleid', get_string('restorernewroleid', 'admin'),
|
||||
get_string('restorernewroleid_help', 'admin'), $defaultteacherid, $restorersnewrole));
|
||||
|
||||
// release memory
|
||||
unset($otherroles);
|
||||
unset($guestroles);
|
||||
unset($userroles);
|
||||
unset($creatornewroles);
|
||||
unset($restorersnewrole);
|
||||
}
|
||||
|
||||
$temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0));
|
||||
|
@ -74,6 +74,9 @@ class restore_course_task extends restore_task {
|
||||
$this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
|
||||
}
|
||||
|
||||
// Now make sure the user that is running the restore can actually access the course
|
||||
$this->add_step(new restore_fix_restorer_access_step('fix_restorer_access'));
|
||||
|
||||
// Restore course filters (conditionally)
|
||||
if ($this->get_setting_value('filters')) {
|
||||
$this->add_step(new restore_filters_structure_step('course_filters', 'filters.xml'));
|
||||
|
@ -1434,6 +1434,57 @@ class restore_enrolments_structure_step extends restore_structure_step {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make sure the user restoring the course can actually access it.
|
||||
*/
|
||||
class restore_fix_restorer_access_step extends restore_execution_step {
|
||||
protected function define_execution() {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (!$userid = $this->task->get_userid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($CFG->restorernewroleid)) {
|
||||
// Bad luck, no fallback role for restorers specified
|
||||
return;
|
||||
}
|
||||
|
||||
$courseid = $this->get_courseid();
|
||||
$context = context_course::instance($courseid);
|
||||
|
||||
if (is_enrolled($context, $userid, 'moodle/course:update', true) or is_viewing($context, $userid, 'moodle/course:update')) {
|
||||
// Current user may access the course (admin, category manager or restored teacher enrolment usually)
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to add role only - we do not need enrolment if user has moodle/course:view or is already enrolled
|
||||
role_assign($CFG->restorernewroleid, $userid, $context);
|
||||
|
||||
if (is_enrolled($context, $userid, 'moodle/course:update', true) or is_viewing($context, $userid, 'moodle/course:update')) {
|
||||
// Extra role is enough, yay!
|
||||
return;
|
||||
}
|
||||
|
||||
// The last chance is to create manual enrol if it does not exist and and try to enrol the current user,
|
||||
// hopefully admin selected suitable $CFG->restorernewroleid ...
|
||||
if (!enrol_is_enabled('manual')) {
|
||||
return;
|
||||
}
|
||||
if (!$enrol = enrol_get_plugin('manual')) {
|
||||
return;
|
||||
}
|
||||
if (!$DB->record_exists('enrol', array('enrol'=>'manual', 'courseid'=>$courseid))) {
|
||||
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
|
||||
$fields = array('status'=>ENROL_INSTANCE_ENABLED, 'enrolperiod'=>$enrol->get_config('enrolperiod', 0), 'roleid'=>$enrol->get_config('roleid', 0));
|
||||
$enrol->add_instance($course, $fields);
|
||||
}
|
||||
|
||||
enrol_try_internal_enrol($courseid, $userid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This structure steps restores the filters and their configs
|
||||
*/
|
||||
|
@ -842,6 +842,8 @@ $string['requires'] = 'Requires';
|
||||
$string['purgecaches']= 'Purge all caches';
|
||||
$string['purgecachesconfirm']= 'Moodle can cache themes, javascript, language strings, filtered text, rss feeds and many other pieces of calculated data. Purging these caches will delete that data from the server and force browsers to refetch data, so that you can be sure you are seeing the most up-to-date values produced by the current code. There is no danger in purging caches, but your site may appear slower for a while until the server and clients calculate new information and cache it.';
|
||||
$string['purgecachesfinished']= 'All caches were purged.';
|
||||
$string['restorernewroleid'] = 'Restorers\' role in courses';
|
||||
$string['restorernewroleid_help'] = 'If the user does not already have the permission to manage the newly restored course, the user is automatically assigned this role and enrolled if necessary. Select "None" if you do not want restorers to be able to manage every restored course.';
|
||||
$string['restrictbydefault'] = 'Restrict modules by default';
|
||||
$string['restrictmodulesfor'] = 'Restrict modules for';
|
||||
$string['reverseproxy'] = 'Reverse proxy';
|
||||
|
Loading…
x
Reference in New Issue
Block a user