diff --git a/.upgradenotes/MDL-84142-2025021805225963.yml b/.upgradenotes/MDL-84142-2025021805225963.yml new file mode 100644 index 00000000000..15a40636093 --- /dev/null +++ b/.upgradenotes/MDL-84142-2025021805225963.yml @@ -0,0 +1,7 @@ +issueNumber: MDL-84142 +notes: + enrol_self: + - message: >- + Class enrol_self_enrol_form is deprecated, use + enrol_self\form\enrol_form instead + type: deprecated diff --git a/course/tests/behat/keyholder.feature b/course/tests/behat/keyholder.feature index e7a7e958507..968b6ecd545 100644 --- a/course/tests/behat/keyholder.feature +++ b/course/tests/behat/keyholder.feature @@ -40,6 +40,7 @@ Feature: Keyholder role is listed as course contact And I follow "Course 1" Then I should see "Keyholder 1" + @javascript Scenario: Keyholder assigned to a category Given the following "role assigns" exist: | user | role | contextlevel | reference | @@ -50,4 +51,5 @@ Feature: Keyholder role is listed as course contact When I log in as "student1" And I am on site homepage And I follow "Course 1" + And I press "Enrol me" Then I should see "Keyholder 1" diff --git a/enrol/self/amd/build/enrol_page.min.js b/enrol/self/amd/build/enrol_page.min.js new file mode 100644 index 00000000000..bff131c3ad4 --- /dev/null +++ b/enrol/self/amd/build/enrol_page.min.js @@ -0,0 +1,10 @@ +define("enrol_self/enrol_page",["exports","core_form/modalform","core/str","core/prefetch","core/url"],(function(_exports,_modalform,_str,_prefetch,_url){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} +/** + * Functions for the enrol_self plugin + * + * @module enrol_self/enrol_page + * @copyright Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.initEnrol=function(instanceId){(0,_prefetch.prefetchStrings)("enrol_self",["enrolme"]);const button=document.querySelector('button[type="submit"][data-instance="'+instanceId+'"]');button&&button.addEventListener("click",(e=>{e.preventDefault();const modalForm=new _modalform.default({modalConfig:{title:button.dataset.title,large:!1},formClass:button.dataset.form,args:{id:button.dataset.id,instance:instanceId},saveButtonText:(0,_str.getString)("enrolme","enrol_self"),returnFocus:button});modalForm.addEventListener(modalForm.events.FORM_SUBMITTED,(event=>{window.location.href=event.detail?event.detail:_url.default.relativeUrl("/course/view.php",{id:button.dataset.id})})),modalForm.show()}))},_modalform=_interopRequireDefault(_modalform),_url=_interopRequireDefault(_url)})); + +//# sourceMappingURL=enrol_page.min.js.map \ No newline at end of file diff --git a/enrol/self/amd/build/enrol_page.min.js.map b/enrol/self/amd/build/enrol_page.min.js.map new file mode 100644 index 00000000000..408645325d1 --- /dev/null +++ b/enrol/self/amd/build/enrol_page.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"enrol_page.min.js","sources":["../src/enrol_page.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Functions for the enrol_self plugin\n *\n * @module enrol_self/enrol_page\n * @copyright Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalForm from 'core_form/modalform';\nimport {getString} from 'core/str';\nimport {prefetchStrings} from 'core/prefetch';\nimport Url from 'core/url';\n\n/**\n * Initialise widget on the course enrolment page - clicking on the button should submit the form\n *\n * @param {Number} instanceId\n */\nexport function initEnrol(instanceId) {\n prefetchStrings('enrol_self', [\n 'enrolme',\n ]);\n\n const button = document.querySelector('button[type=\"submit\"][data-instance=\"' + instanceId + '\"]');\n if (button) {\n button.addEventListener('click', (e) => {\n e.preventDefault();\n const modalForm = new ModalForm({\n modalConfig: {\n title: button.dataset.title,\n large: false, // This is a very small form that does not need a large popup.\n },\n formClass: button.dataset.form,\n args: {id: button.dataset.id, instance: instanceId},\n saveButtonText: getString('enrolme', 'enrol_self'),\n returnFocus: button,\n });\n\n // Redirect to the course page when the form is submitted.\n modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {\n window.location.href = event.detail ? event.detail :\n Url.relativeUrl('/course/view.php', {id: button.dataset.id});\n });\n\n modalForm.show();\n });\n }\n}\n"],"names":["instanceId","button","document","querySelector","addEventListener","e","preventDefault","modalForm","ModalForm","modalConfig","title","dataset","large","formClass","form","args","id","instance","saveButtonText","returnFocus","events","FORM_SUBMITTED","event","window","location","href","detail","Url","relativeUrl","show"],"mappings":";;;;;;;yFAiC0BA,0CACN,aAAc,CAC1B,kBAGEC,OAASC,SAASC,cAAc,wCAA0CH,WAAa,MACzFC,QACAA,OAAOG,iBAAiB,SAAUC,IAC9BA,EAAEC,uBACIC,UAAY,IAAIC,mBAAU,CAC5BC,YAAa,CACTC,MAAOT,OAAOU,QAAQD,MACtBE,OAAO,GAEXC,UAAWZ,OAAOU,QAAQG,KAC1BC,KAAM,CAACC,GAAIf,OAAOU,QAAQK,GAAIC,SAAUjB,YACxCkB,gBAAgB,kBAAU,UAAW,cACrCC,YAAalB,SAIjBM,UAAUH,iBAAiBG,UAAUa,OAAOC,gBAAgBC,QACxDC,OAAOC,SAASC,KAAOH,MAAMI,OAASJ,MAAMI,OACxCC,aAAIC,YAAY,mBAAoB,CAACZ,GAAIf,OAAOU,QAAQK,QAGhET,UAAUsB"} \ No newline at end of file diff --git a/enrol/self/amd/src/enrol_page.js b/enrol/self/amd/src/enrol_page.js new file mode 100644 index 00000000000..54b240070a5 --- /dev/null +++ b/enrol/self/amd/src/enrol_page.js @@ -0,0 +1,63 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Functions for the enrol_self plugin + * + * @module enrol_self/enrol_page + * @copyright Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import ModalForm from 'core_form/modalform'; +import {getString} from 'core/str'; +import {prefetchStrings} from 'core/prefetch'; +import Url from 'core/url'; + +/** + * Initialise widget on the course enrolment page - clicking on the button should submit the form + * + * @param {Number} instanceId + */ +export function initEnrol(instanceId) { + prefetchStrings('enrol_self', [ + 'enrolme', + ]); + + const button = document.querySelector('button[type="submit"][data-instance="' + instanceId + '"]'); + if (button) { + button.addEventListener('click', (e) => { + e.preventDefault(); + const modalForm = new ModalForm({ + modalConfig: { + title: button.dataset.title, + large: false, // This is a very small form that does not need a large popup. + }, + formClass: button.dataset.form, + args: {id: button.dataset.id, instance: instanceId}, + saveButtonText: getString('enrolme', 'enrol_self'), + returnFocus: button, + }); + + // Redirect to the course page when the form is submitted. + modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => { + window.location.href = event.detail ? event.detail : + Url.relativeUrl('/course/view.php', {id: button.dataset.id}); + }); + + modalForm.show(); + }); + } +} diff --git a/enrol/self/classes/form/enrol_form.php b/enrol/self/classes/form/enrol_form.php new file mode 100644 index 00000000000..ff605fc608c --- /dev/null +++ b/enrol/self/classes/form/enrol_form.php @@ -0,0 +1,204 @@ +. + +declare(strict_types=1); + +namespace enrol_self\form; + +use core\context\course as context_course; +use core\context\system as context_system; +use core_form\dynamic_form; +use core_text; +use html_writer; +use moodle_url; + +/** + * Form for entering password for self enrolment + * + * @package enrol_self + * @copyright Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class enrol_form extends dynamic_form { + /** @var \stdClass */ + protected $instance; + /** @var \enrol_self_plugin */ + protected $plugin = null; + + /** + * Returns the enrolment method + * + * @return \enrol_self_plugin + */ + protected function get_plugin(): \enrol_self_plugin { + global $CFG; + require_once($CFG->dirroot . '/lib/enrollib.php'); + if ($this->plugin === null) { + $this->plugin = enrol_get_plugin('self'); + } + return $this->plugin; + } + + /** + * Returns the instance of the enrolment method + * + * @return \stdClass + */ + protected function get_instance(): \stdClass { + global $DB, $CFG; + require_once($CFG->dirroot . '/lib/enrollib.php'); + if ($this->instance === null) { + // Method enrol_get_instances() will also validate that the enrolment method and the instance are enabled. + $courseid = $this->optional_param('id', 0, PARAM_INT); + $instanceid = $this->optional_param('instance', 0, PARAM_INT); + $instances = enrol_get_instances($courseid, true); + $this->instance = $instances[$instanceid] ?? null; + if (empty($this->instance) || $this->instance->enrol !== 'self') { + throw new \moodle_exception('invalidenrolinstance', 'enrol'); + } + } + return $this->instance; + } + + #[\Override] + public function definition() { + global $USER, $OUTPUT, $CFG; + + $mform = $this->_form; + + $mform->addElement('password', 'enrolpassword', get_string('password', 'enrol_self')); + + // Display keyholders - list of users who have 'enrol/self:holdkey' capability. + $context = context_course::instance($this->instance->courseid); + $userfieldsapi = \core_user\fields::for_userpic(); + $ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects; + $keyholders = get_users_by_capability($context, 'enrol/self:holdkey', $ufields); + $keyholdercount = 0; + foreach ($keyholders as $keyholder) { + $keyholdercount++; + if ($keyholdercount === 1) { + $mform->addElement('static', 'keyholder', '', get_string('keyholder', 'enrol_self')); + } + if ($USER->id == $keyholder->id + || has_capability('moodle/user:viewdetails', context_system::instance()) + || has_coursecontact_role($keyholder->id)) { + $profileurl = new moodle_url('/user/profile.php', ['id' => $keyholder->id, 'course' => $this->instance->courseid]); + $profilelink = html_writer::link($profileurl, fullname($keyholder)); + } else { + $profilelink = fullname($keyholder); + } + $profilepic = $OUTPUT->user_picture($keyholder, ['size' => 35, 'courseid' => $this->instance->courseid]); + $mform->addElement('static', 'keyholder' . $keyholdercount, '', $profilepic . $profilelink); + } + + $mform->addElement('hidden', 'id'); + $mform->setType('id', PARAM_INT); + + $mform->addElement('hidden', 'instance'); + $mform->setType('instance', PARAM_INT); + } + + #[\Override] + public function validation($data, $files) { + global $DB, $CFG; + require_once($CFG->dirroot.'/enrol/self/locallib.php'); + + $errors = parent::validation($data, $files); + $instance = $this->get_instance(); + if ($data['enrolpassword'] !== $instance->password) { + if ($instance->customint1) { + // Check group enrolment key. + if (!enrol_self_check_group_enrolment_key($instance->courseid, $data['enrolpassword'])) { + // We can not hint because there are probably multiple passwords. + $errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self'); + } + } else { + $plugin = enrol_get_plugin('self'); + if ($plugin->get_config('showhint')) { + $hint = core_text::substr($instance->password, 0, 1); + $errors['enrolpassword'] = get_string('passwordinvalidhint', 'enrol_self', $hint); + } else { + $errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self'); + } + } + } + + return $errors; + } + + #[\Override] + protected function check_access_for_dynamic_submission(): void { + global $USER, $CFG; + $instance = $this->get_instance(); + $courseid = $instance->courseid; + $course = get_course($courseid); + $context = context_course::instance($instance->courseid); + if (!\core_course_category::can_view_course_info($course) && !is_enrolled($context, $USER, '', true)) { + throw new \moodle_exception('coursehidden', '', $CFG->wwwroot . '/'); + } + if (isguestuser()) { + throw new \moodle_exception('noguestaccess', 'enrol'); + } + $canselfenrol = $this->get_plugin()->can_self_enrol($instance); + if ($canselfenrol !== true) { + throw new \moodle_exception($canselfenrol); + } + if (!$instance->password) { + throw new \moodle_exception('nopassword', 'enrol_self'); + } + } + + #[\Override] + protected function get_context_for_dynamic_submission(): \context { + // This form is used for users who are not yet enrolled in the course and do not have access to the course. + // For the purpose of permission checks they must be able to access the course category for this course. + return context_course::instance($this->get_instance()->courseid)->get_parent_context(); + } + + #[\Override] + protected function get_page_url_for_dynamic_submission(): moodle_url { + $instance = $this->get_instance(); + return new moodle_url('/enrol/index.php', ['id' => $instance->courseid, 'instance' => $instance->id]); + } + + /** + * Process the form submission, used if form was submitted via AJAX + * + * Enrols the user in the course and returns the URL to redirect to + * + * @return string + */ + public function process_dynamic_submission() { + global $CFG, $SESSION; + $this->get_plugin()->enrol_self($this->get_instance(), $this->get_data()); + + // Go to the originally requested page. + if (!empty($SESSION->wantsurl)) { + $destination = $SESSION->wantsurl; + unset($SESSION->wantsurl); + } else { + require_once($CFG->dirroot . '/course/lib.php'); + $destination = course_get_url($this->get_instance()->courseid); + } + return $destination; + } + + #[\Override] + public function set_data_for_dynamic_submission(): void { + $instance = $this->get_instance(); + $this->set_data(['id' => $instance->courseid, 'instance' => $instance->id]); + } +} diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php index f681f512266..b77a06ae2cf 100644 --- a/enrol/self/lang/en/enrol_self.php +++ b/enrol/self/lang/en/enrol_self.php @@ -36,6 +36,7 @@ $string['editselectedusers'] = 'Edit selected user enrolments'; $string['enrolenddate'] = 'End date'; $string['enrolenddate_help'] = 'If enabled, users can enrol themselves until this date only.'; $string['enrolenddaterror'] = 'Enrolment end date cannot be earlier than start date'; +$string['enrolkeyrequired'] = 'An enrolment key will be required'; $string['enrolme'] = 'Enrol me'; $string['enrolperiod'] = 'Enrolment duration'; $string['enrolperiod_desc'] = 'Default length of time that the enrolment is valid. If set to zero, the enrolment duration will be unlimited by default.'; diff --git a/enrol/self/lib.php b/enrol/self/lib.php index 30721dcc3ce..d50851ab5b2 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -22,6 +22,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use core\output\single_button; +use core_enrol\output\enrol_page; + /** * Self enrolment plugin implementation. * @author Petr Skoda @@ -164,7 +167,6 @@ class enrol_self_plugin extends enrol_plugin { * * @param stdClass $instance enrolment instance * @param stdClass $data data needed for enrolment. - * @return bool|array true if enroled else eddor code and messege */ public function enrol_self(stdClass $instance, $data = null) { global $DB, $USER, $CFG; @@ -202,46 +204,61 @@ class enrol_self_plugin extends enrol_plugin { } } - /** - * Creates course enrol form, checks if form submitted - * and enrols user if necessary. It can also redirect. - * - * @param stdClass $instance - * @return string html text, usually a form in a text box - */ + #[\Override] public function enrol_page_hook(stdClass $instance) { - global $CFG, $OUTPUT, $USER; + global $CFG, $OUTPUT, $USER, $PAGE; - require_once("$CFG->dirroot/enrol/self/locallib.php"); + $buttonurl = null; + $buttontext = ''; + $buttonattrs = []; + $body = ''; + $title = $this->get_instance_name($instance); $enrolstatus = $this->can_self_enrol($instance); - - if (true === $enrolstatus) { - // This user can self enrol using this instance. - $form = new enrol_self_enrol_form(null, $instance); - $instanceid = optional_param('instance', 0, PARAM_INT); - if ($instance->id == $instanceid) { - if ($data = $form->get_data()) { - $this->enrol_self($instance, $data); + if ($enrolstatus === true) { + if ($instance->password) { + // Self-enrolment with password. Display a button to open a form in a modal. + $body = get_string('enrolkeyrequired', 'enrol_self'); + $buttonurl = $PAGE->url; + $buttonattrs = [ + 'data-id' => $instance->courseid, + 'data-instance' => $instance->id, + 'data-form' => enrol_self\form\enrol_form::class, + 'data-title' => $title, + ]; + $PAGE->requires->js_call_amd('enrol_self/enrol_page', 'initEnrol', [$instance->id]); + } else { + // Self-enrolment without password. Display a button to self enrol. If button is pressed - enrol the user. + if (optional_param('action', null, PARAM_TEXT) === 'enrol' && confirm_sesskey()) { + $this->enrol_self($instance, (object)[]); + return ''; } + $body = get_string('nopassword', 'enrol_self'); + $buttonurl = new moodle_url($PAGE->url, ['action' => 'enrol', 'sesskey' => sesskey()]); } + $buttontext = get_string('enrolme', 'enrol_self'); + } else if (isguestuser()) { + // User is not logged in. Display a button to login. + $buttonurl = new moodle_url(get_login_url()); + $body = get_string('noguestaccess', 'enrol'); + $buttontext = get_string('continue'); + } else if (!$enrolstatus) { + // No reason why user can not use this method, do not display anything. + return ''; } else { - // This user can not self enrol using this instance. Using an empty form to keep - // the UI consistent with other enrolment plugins that returns a form. - $data = new stdClass(); - $data->header = $this->get_instance_name($instance); - $data->info = $enrolstatus; - - // The can_self_enrol call returns a button to the login page if the user is a - // guest, setting the login url to the form if that is the case. - $url = isguestuser() ? get_login_url() : null; - $form = new enrol_self_empty_form($url, $data); + $body = $enrolstatus; } - ob_start(); - $form->display(); - $output = ob_get_clean(); - return $OUTPUT->box($output); + $notification = new \core\output\notification($body, 'info', false); + $notification->set_extra_classes(['mb-0']); + $enrolpage = new enrol_page( + instance: $instance, + header: $title, + body: $OUTPUT->render($notification), + buttons: $buttonurl ? + [new single_button($buttonurl, $buttontext, 'get', single_button::BUTTON_PRIMARY, $buttonattrs)] : + []); + return $OUTPUT->render($enrolpage); } /** @@ -285,7 +302,7 @@ class enrol_self_plugin extends enrol_plugin { * This function doesn't check user capabilities. Use can_self_enrol to check capabilities. * * @param stdClass $instance enrolment instance - * @return bool - true means "Enrol me in this course" link could be available + * @return bool|string - true means "Enrol me in this course" link could be available */ public function is_self_enrol_available(stdClass $instance) { global $CFG, $DB, $USER; diff --git a/enrol/self/locallib.php b/enrol/self/locallib.php index 98f73c84c5a..b0684160b10 100644 --- a/enrol/self/locallib.php +++ b/enrol/self/locallib.php @@ -53,10 +53,33 @@ function enrol_self_check_group_enrolment_key($courseid, $enrolpassword) { return $found; } +/** + * Old class for displaying the self enrolment form + * + * @deprecated since Moodle 5.0 - please use {@see enrol_self\form\enrol_form} + */ +#[\core\attribute\deprecated(replacement: enrol_self\form\enrol_form::class, since: '5.0', reason: 'Now a dynamic form is used')] class enrol_self_enrol_form extends moodleform { protected $instance; protected $toomany = false; + /** + * Constructor + * + * @param mixed $action + * @param mixed $customdata + * @param string $method + * @param string $target + * @param mixed $attributes + * @param bool $editable + * @param array $ajaxformdata + */ + public function __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, + $ajaxformdata=null) { + \core\deprecation::emit_deprecation_if_present([$this, __FUNCTION__]); + parent::__construct($action, $customdata, $method, $target, $attributes, $editable, $ajaxformdata); + } + /** * Overriding this function to get unique form id for multiple self enrolments. * diff --git a/enrol/self/tests/behat/key_holder.feature b/enrol/self/tests/behat/key_holder.feature index e6f110067e5..f761c1496b9 100644 --- a/enrol/self/tests/behat/key_holder.feature +++ b/enrol/self/tests/behat/key_holder.feature @@ -34,11 +34,13 @@ Feature: Users can be defined as key holders in courses where self enrolment is And I log out And I log in as "student1" And I am on "Course 1" course homepage + And I should see "An enrolment key will be required" + And I press "Enrol me" And I should see "You should have received this enrolment key from:" And I should see "Manager 1" And I set the following fields to these values: | Enrolment key | moodle_rules | - And I press "Enrol me" + And I click on "Enrol me" "button" in the "Test student enrolment" "dialogue" Then I should see "New section" And I should not see "Enrolment options" And I should not see "Enrol me in this course" diff --git a/enrol/self/tests/behat/self_enrolment.feature b/enrol/self/tests/behat/self_enrolment.feature index 5813c7c61ed..db0617563fb 100644 --- a/enrol/self/tests/behat/self_enrolment.feature +++ b/enrol/self/tests/behat/self_enrolment.feature @@ -42,6 +42,7 @@ Feature: Users can auto-enrol themself in courses where self enrolment is allowe Then I should see "New section" And I should not see "Enrolment options" + @javascript Scenario: Self-enrolment enabled requiring an enrolment key Given I log in as "teacher1" When I add "Self enrolment" enrolment method in "Course 1" with: @@ -50,9 +51,11 @@ Feature: Users can auto-enrol themself in courses where self enrolment is allowe And I log out And I log in as "student1" And I am on "Course 1" course homepage + And I should see "An enrolment key will be required" + And I press "Enrol me" And I set the following fields to these values: | Enrolment key | moodle_rules | - And I press "Enrol me" + And I click on "Enrol me" "button" in the "Test student enrolment" "dialogue" Then I should see "New section" And I should not see "Enrolment options" And I should not see "Enrol me in this course" @@ -62,6 +65,7 @@ Feature: Users can auto-enrol themself in courses where self enrolment is allowe When I am on "Course 1" course homepage Then I should see "You cannot enrol yourself in this course" + @javascript Scenario: Self-enrolment enabled requiring a group enrolment key Given I log in as "teacher1" When I add "Self enrolment" enrolment method in "Course 1" with: @@ -77,16 +81,18 @@ Feature: Users can auto-enrol themself in courses where self enrolment is allowe And I log out And I log in as "student1" And I am on "Course 1" course homepage + And I press "Enrol me" And I set the following fields to these values: | Enrolment key | Test-groupenrolkey1 | - And I press "Enrol me" + And I click on "Enrol me" "button" in the "Test student enrolment" "dialogue" Then I should see "New section" And I should not see "Enrolment options" And I should not see "Enrol me in this course" And I am on the "Course 1" course page logged in as student2 + And I press "Enrol me" And I set the following fields to these values: | Enrolment key | moodle_rules | - And I press "Enrol me" + And I click on "Enrol me" "button" in the "Test student enrolment" "dialogue" And I am on the "Course 1" course page logged in as teacher1 And I navigate to course participants And the following should exist in the "participants" table: