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

This commit is contained in:
Amaia Anabitarte 2021-08-23 18:04:18 +02:00
parent 5ea3545115
commit 7958fa72e1
6 changed files with 47 additions and 2 deletions

View File

@ -186,6 +186,9 @@ if ($hassiteconfig
unset($restorersnewrole);
}
$temp->add(new admin_setting_configcheckbox('enroladminnewcourse', new lang_string('enroladminnewcourse', 'admin'),
new lang_string('enroladminnewcourse_help', 'admin'), 1));
$temp->add(new admin_setting_configcheckbox('autologinguests', new lang_string('autologinguests', 'admin'), new lang_string('configautologinguests', 'admin'), 0));
$temp->add(new admin_setting_configmultiselect('hiddenuserfields', new lang_string('hiddenuserfields', 'admin'),

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.

View File

@ -114,3 +114,27 @@ Feature: Managers can create courses
And I press "Save and display"
And I click on "Participants" "link"
Then I should see "Non-editing teacher" in the "Kevin the" "table_row"
@javascript
Scenario: Create a course as admin
Given I log in as "admin"
And the following config values are set as admin:
| enroladminnewcourse | 0 |
And I navigate to "Courses > Add a new course" in site administration
And I set the following fields to these values:
| Course full name | My first course |
| Course short name | myfirstcourse |
And I press "Save and display"
And I navigate to course participants
Then I should not see "Teacher"
And I should see "Nothing to display"
And the following config values are set as admin:
| enroladminnewcourse | 1 |
And I navigate to "Courses > Add a new course" in site administration
And I set the following fields to these values:
| Course full name | My second course |
| Course short name | mysecondcourse |
And I press "Save and display"
And I navigate to course participants
And I should see "Teacher"
And I should not see "Nothing to display"

View File

@ -576,6 +576,8 @@ $string['enablewebservices'] = 'Enable web services';
$string['enablewsdocumentation'] = 'Web services documentation';
$string['encryptedpassword_set'] = '(Set and encrypted)';
$string['encryptedpassword_edit'] = 'Enter new value';
$string['enroladminnewcourse'] = 'Auto-enrol admin in new courses';
$string['enroladminnewcourse_help'] = 'When an admin adds a new course, should they be automatically enrolled and assigned the creators\' role in new courses?';
$string['enrolinstancedefaults'] = 'Enrolment instance defaults';
$string['enrolinstancedefaults_desc'] = 'Default enrolment settings in new courses.';
$string['enrolmultipleusers'] = 'Enrol the users';

View File

@ -2778,5 +2778,13 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021091100.02);
}
if ($oldversion < 2021091700.01) {
// Default 'off' for existing sites as this is the behaviour they had earlier.
set_config('enroladminnewcourse', false);
// Main savepoint reached.
upgrade_main_savepoint(true, 2021091700.01);
}
return true;
}

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2021091700.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021091700.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20210917)'; // Human-friendly version name