MDL-72356 core_course: auto enrol admins when adding a new course

This commit is contained in:
Amaia Anabitarte
2021-09-20 13:09:29 +02:00
parent 5ea3545115
commit 7958fa72e1
6 changed files with 47 additions and 2 deletions
+9 -1
View File
@@ -164,7 +164,15 @@ if ($editform->is_cancelled()) {
// Get the context of the newly created course.
$context = context_course::instance($course->id, MUST_EXIST);
if (!empty($CFG->creatornewroleid) and !is_viewing($context, NULL, 'moodle/role:assign') and !is_enrolled($context, NULL, 'moodle/role:assign')) {
// Admins have all capabilities, so is_viewing is returning true for admins.
// We are checking 'enroladminnewcourse' setting to decide to enrol them or not.
if (is_siteadmin($USER->id)) {
$enroluser = $CFG->enroladminnewcourse;
} else {
$enroluser = !is_viewing($context, null, 'moodle/role:assign');
}
if (!empty($CFG->creatornewroleid) and $enroluser and !is_enrolled($context, null, 'moodle/role:assign')) {
// Deal with course creators - enrol them internally with default role.
// Note: This does not respect capabilities, the creator will be assigned the default role.
// This is an expected behaviour. See MDL-66683 for further details.