diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml index d5f65c3..02ea439 100644 --- a/.github/workflows/moodle-plugin-ci.yml +++ b/.github/workflows/moodle-plugin-ci.yml @@ -30,8 +30,8 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.3', '7.4', '8.0'] - moodle-branch: ['MOODLE_400_STABLE'] + php: ['7.4', '8.0'] + moodle-branch: ['MOODLE_401_STABLE'] database: [pgsql, mariadb] steps: diff --git a/CHANGES.md b/CHANGES.md index a0d6a44..752e82e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,8 +4,16 @@ moodle-local_bulkenrol Changes ------- -### Unreleased +### v4.1-r1 +* 2023-01-21 - Prepare compatibility for Moodle 4.1. + +### v4.0-r3 + +* 2023-04-26 - Allow teachers to configure the navigation node placement. +* 2023-04-26 - Add a missing setting to README.md +* 2023-03-12 - Tests: Fix a Behat test which broke after Moodle core upstream changes +* 2023-03-11 - Make codechecker happy again * 2022-11-28 - Updated Moodle Plugin CI to latest upstream recommendations ### v4.0-r2 diff --git a/README.md b/README.md index 45a9657..b771d51 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Moodle plugin which provides the possibility to bulk enrol a list of users who a Requirements ------------ -This plugin requires Moodle 4.0+ +This plugin requires Moodle 4.1+ Motivation for this plugin @@ -41,11 +41,17 @@ After installing the plugin, it does not do anything to Moodle yet. To configure the plugin and its behaviour, please visit: Site administration -> Plugins -> Enrolments -> User bulk enrolment -There, you find only one setting: +There, you find two settings: ### 1. Enrolment plugin The enrolment method to be used to bulk enrol the users. If the configured enrolment method is not active / added in the course when the users are bulk-enrolled, it is automatically added / activated. +### 2. Role +The role to be used to bulk enrol the users. + +### 3. Navigation node placement +The location where the navigation node for this functionality will be added within a course. + Capabilities ------------ diff --git a/lang/en/local_bulkenrol.php b/lang/en/local_bulkenrol.php index 97472e0..2fadb5f 100644 --- a/lang/en/local_bulkenrol.php +++ b/lang/en/local_bulkenrol.php @@ -84,4 +84,8 @@ $string['parameter_empty'] = 'Parameter empty'; $string['type_enrol'] = 'Enrolment method'; $string['identifying_data'] = 'Data'; - +$string['navigation'] = 'Navigation node placement'; +$string['navigation_desc'] = 'The location where the navigation node for user bulk enrolment will be added within a course.'; +$string['nav_course'] = 'Navigation node in course navigation'; +$string['nav_participants'] = 'Navigation node in participants page jump menu'; +$string['nav_both'] = 'Navigation node both in participants page jump menu and in course navigation'; diff --git a/lib.php b/lib.php index de2bc8e..63c1c02 100644 --- a/lib.php +++ b/lib.php @@ -22,6 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +define('LOCALBULKENROL_NAV_COURSE', 'navcourse'); +define('LOCALBULKENROL_NAV_PARTICIPANTS', 'navpart'); +define('LOCALBULKENROL_NAV_BOTH', 'navboth'); + /** * This function extends the course navigation with the bulkenrol item * @@ -31,13 +35,27 @@ */ function local_bulkenrol_extend_navigation_course($navigation, $course, $context) { if (has_capability('local/bulkenrol:enrolusers', $context)) { + // Create the navigation node. $url = new moodle_url('/local/bulkenrol/index.php', array('id' => $course->id)); $bulkenrolnode = navigation_node::create(get_string('pluginname', 'local_bulkenrol'), $url, navigation_node::TYPE_SETTING, null, 'local_bulkenrol', new pix_icon('i/users', '')); - $usersnode = $navigation->get('users'); - if (isset($bulkenrolnode) && !empty($usersnode)) { - $usersnode->add_node($bulkenrolnode); + // Get the navigation node placement setting. + $navigationplacement = get_config('local_bulkenrol', 'navigation'); + + // If the admin wanted to add the navigation node to the participants page jump menu. + if ($navigationplacement == LOCALBULKENROL_NAV_PARTICIPANTS || $navigationplacement == LOCALBULKENROL_NAV_BOTH) { + $usersnode = $navigation->get('users'); + if (isset($bulkenrolnode) && !empty($usersnode)) { + $usersnode->add_node($bulkenrolnode); + } + } + + // If the admin wanted to add the navigation node to the course navigation. + if ($navigationplacement == LOCALBULKENROL_NAV_COURSE || $navigationplacement == LOCALBULKENROL_NAV_BOTH) { + if (isset($bulkenrolnode)) { + $navigation->add_node($bulkenrolnode); + } } } } diff --git a/locallib.php b/locallib.php index d12a714..65d8ac2 100644 --- a/locallib.php +++ b/locallib.php @@ -372,7 +372,7 @@ function local_bulkenrol_users($localbulkenrolkey) { $id = $plugin->add_instance($course, $fields); $enrolinstance = $DB->get_record('enrol', array('id' => $id)); - $enrolinstance->expirynotify = $plugin->get_config('expirynotify'); + $enrolinstance->expirynotify = $plugin->get_config('expirynotify'); $enrolinstance->expirythreshold = $plugin->get_config('expirythreshold'); $enrolinstance->roleid = $plugin->get_config('roleid'); $enrolinstance->timemodified = time(); diff --git a/settings.php b/settings.php index 49ec950..dd25082 100644 --- a/settings.php +++ b/settings.php @@ -24,6 +24,9 @@ defined('MOODLE_INTERNAL') || die; +// Require library. +require_once($CFG->dirroot.'/local/bulkenrol/lib.php'); + $filtercustombyunique = true; $usertableoptions = [ @@ -88,6 +91,20 @@ ); unset($roleoptions); + // Create navigation node placement widget. + $navigationoptions = array(LOCALBULKENROL_NAV_COURSE => get_string('nav_course', 'local_bulkenrol'), + LOCALBULKENROL_NAV_PARTICIPANTS => get_string('nav_participants', 'local_bulkenrol'), + LOCALBULKENROL_NAV_BOTH => get_string('nav_both', 'local_bulkenrol')); + $settings->add( + new admin_setting_configselect( + 'local_bulkenrol/navigation', + get_string('navigation', 'local_bulkenrol'), + get_string('navigation_desc', 'local_bulkenrol'), + LOCALBULKENROL_NAV_PARTICIPANTS, + $navigationoptions) + ); + unset($navigationoptions); + $settings->add( new admin_setting_configcheckbox( 'local_bulkenrol/create_on_the_fly', diff --git a/tests/behat/local_bulkenrol_groups.feature b/tests/behat/local_bulkenrol_groups.feature index 3e0122e..759c54d 100644 --- a/tests/behat/local_bulkenrol_groups.feature +++ b/tests/behat/local_bulkenrol_groups.feature @@ -9,17 +9,18 @@ Feature: Using the local_bulkenrol plugin for group management | fullname | shortname | format | | Course 1 | C1 | topics | And the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - | student1 | Student | 1 | student1@example.com | - | student2 | Student | 2 | student2@example.com | - | student3 | Student | 3 | student3@example.com | + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | student3 | Student | 3 | student3@example.com | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | And the following config values are set as admin: - | config | value | plugin | - | enrolplugin | manual | local_bulkenrol | + | config | value | plugin | + | enrolplugin | manual | local_bulkenrol | + | navigation | navpart | local_bulkenrol | Given I log in as "admin" And I navigate to "Plugins > Enrolments > User bulk enrolment" in site administration And I set the following fields to these values: @@ -55,16 +56,16 @@ Feature: Using the local_bulkenrol plugin for group management | Group 2 | Group already exists | | Group 3 | Group already exists | And the following should exist in the "localbulkenrol_enrolusers" table: - | Email address | First name | Surname | User enrolment | Group membership | Group membership | - | student1@example.com | Student | 1 | User will be enrolled | Group 1 | User will be added to group | - | student2@example.com | Student | 2 | User will be enrolled | Group 2 | User will be added to group | - | student3@example.com | Student | 3 | User will be enrolled | Group 3 | User will be added to group | + | Email address | First name | Last name | User enrolment | Group membership | Group membership | + | student1@example.com | Student | 1 | User will be enrolled | Group 1 | User will be added to group | + | student2@example.com | Student | 2 | User will be enrolled | Group 2 | User will be added to group | + | student3@example.com | Student | 3 | User will be enrolled | Group 3 | User will be added to group | And I click on "Enrol users" "button" Then the following should exist in the "participants" table: - | Email address | First name | Surname | Roles | Groups | - | student1@example.com | Student | 1 | Student | Group 1 | - | student2@example.com | Student | 2 | Student | Group 2 | - | student3@example.com | Student | 3 | Student | Group 3 | + | Email address | First name | Last name | Roles | Groups | + | student1@example.com | Student | 1 | Student | Group 1 | + | student2@example.com | Student | 2 | Student | Group 2 | + | student3@example.com | Student | 3 | Student | Group 3 | Scenario: Bulk enrol students into the course with students already enrolled and who only have to be added to (existing) groups Given the following "course enrolments" exist: @@ -91,14 +92,14 @@ Feature: Using the local_bulkenrol plugin for group management | Group 1 | Group already exists | | Group 2 | Group already exists | And the following should exist in the "localbulkenrol_enrolusers" table: - | Email address | First name | Surname | User enrolment | Group membership | Group membership | - | student1@example.com | Student | 1 | User is already enrolled | Group 1 | User will be added to group | - | student2@example.com | Student | 2 | User is already enrolled | Group 2 | User will be added to group | + | Email address | First name | Last name | User enrolment | Group membership | Group membership | + | student1@example.com | Student | 1 | User is already enrolled | Group 1 | User will be added to group | + | student2@example.com | Student | 2 | User is already enrolled | Group 2 | User will be added to group | And I click on "Enrol users" "button" Then the following should exist in the "participants" table: - | Email address | First name | Surname | Roles | Groups | - | student1@example.com | Student | 1 | Student | Group 1 | - | student2@example.com | Student | 2 | Student | Group 2 | + | Email address | First name | Last name | Roles | Groups | + | student1@example.com | Student | 1 | Student | Group 1 | + | student2@example.com | Student | 2 | Student | Group 2 | Scenario: Bulk enrol students into the course with students already enrolled and who are also a member of the given (existing) groups And the following "course enrolments" exist: @@ -129,14 +130,14 @@ Feature: Using the local_bulkenrol plugin for group management | Group 1 | Group already exists | | Group 2 | Group already exists | And the following should exist in the "localbulkenrol_enrolusers" table: - | Email address | First name | Surname | User enrolment | Group membership | Group membership | - | student1@example.com | Student | 1 | User is already enrolled | Group 1 | User is already group member | - | student2@example.com | Student | 2 | User is already enrolled | Group 2 | User is already group member | + | Email address | First name | Last name | User enrolment | Group membership | Group membership | + | student1@example.com | Student | 1 | User is already enrolled | Group 1 | User is already group member | + | student2@example.com | Student | 2 | User is already enrolled | Group 2 | User is already group member | And I click on "Enrol users" "button" Then the following should exist in the "participants" table: - | Email address | First name | Surname | Roles | Groups | - | student1@example.com | Student | 1 | Student | Group 1 | - | student2@example.com | Student | 2 | Student | Group 2 | + | Email address | First name | Last name | Roles | Groups | + | student1@example.com | Student | 1 | Student | Group 1 | + | student2@example.com | Student | 2 | Student | Group 2 | Scenario: Bulk enrol students into the course and create groups if needed Given the following "groups" exist: @@ -159,6 +160,6 @@ Feature: Using the local_bulkenrol plugin for group management | Group 2 | Group will be created | And I click on "Enrol users" "button" Then the following should exist in the "participants" table: - | Email address | First name | Surname | Roles | Groups | - | student1@example.com | Student | 1 | Student | Group 1 | - | student2@example.com | Student | 2 | Student | Group 2 | + | Email address | First name | Last name | Roles | Groups | + | student1@example.com | Student | 1 | Student | Group 1 | + | student2@example.com | Student | 2 | Student | Group 2 | diff --git a/tests/behat/local_bulkenrol_navigation.feature b/tests/behat/local_bulkenrol_navigation.feature new file mode 100644 index 0000000..bb0a38c --- /dev/null +++ b/tests/behat/local_bulkenrol_navigation.feature @@ -0,0 +1,57 @@ +@local @local_bulkenrol @local_bulkenrol_navigation @javascript +Feature: Using the local_bulkenrol plugin + In order to bulk enrol users into the course + As user with the appropriate rights + I need to have a proper navigation + + Background: + Given the following "courses" exist: + | fullname | shortname | format | + | Course 1 | C1 | topics | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following config values are set as admin: + | config | value | plugin | + | enrolplugin | manual | local_bulkenrol | + Given I log in as "admin" + And I navigate to "Plugins > Enrolments > User bulk enrolment" in site administration + And I set the following fields to these values: + | Role | Student | + And I press "Save changes" + And I set the following system permissions of "Teacher" role: + | capability | permission | + | local/bulkenrol:enrolusers | Allow | + And I log out + + Scenario Outline: Access the bulk enrolment page via the participants page jump menu + Given the following config values are set as admin: + | config | value | plugin | + | navigation | | local_bulkenrol | + When I log in as "teacher1" + And I am on "Course 1" course homepage + And I select "Participants" from secondary navigation + And I select "User bulk enrolment" from the "jump" singleselect + Then I should see "User bulk enrolment" in the "#region-main h2" "css_element" + + Examples: + | navigation | + | navpart | + | navboth | + + Scenario Outline: Access the bulk enrolment page via the participants page jump menu + Given the following config values are set as admin: + | config | value | plugin | + | navigation | | local_bulkenrol | + When I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "User bulk enrolment" in current page administration + Then I should see "User bulk enrolment" in the "#region-main h2" "css_element" + + Examples: + | navigation | + | navcourse | + | navboth | diff --git a/tests/behat/local_bulkenrol_users.feature b/tests/behat/local_bulkenrol_users.feature index f505e16..a2cc3c5 100644 --- a/tests/behat/local_bulkenrol_users.feature +++ b/tests/behat/local_bulkenrol_users.feature @@ -9,17 +9,18 @@ Feature: Using the local_bulkenrol plugin for user enrolments | fullname | shortname | format | | Course 1 | C1 | topics | And the following "users" exist: - | username | firstname | lastname | email | idnumber | - | teacher1 | Teacher | 1 | teacher1@example.com | 1 | - | student1 | Student | 1 | student1@example.com | 2 | - | student2 | Student | 2 | student2@example.com | 3 | - | student3 | Student | 3 | student3@example.com | 4 | + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | student3 | Student | 3 | student3@example.com | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | And the following config values are set as admin: - | config | value | plugin | - | enrolplugin | manual | local_bulkenrol | + | config | value | plugin | + | enrolplugin | manual | local_bulkenrol | + | navigation | navpart | local_bulkenrol | Given I log in as "admin" And I navigate to "Plugins > Enrolments > User bulk enrolment" in site administration And I set the following fields to these values: @@ -45,19 +46,19 @@ Feature: Using the local_bulkenrol plugin for user enrolments """ And I click on "Enrol users" "button" Then the following should exist in the "localbulkenrol_enrolusers" table: - | Email address | First name | Surname | User enrolment | - | student1@example.com | Student | 1 | User will be enrolled | - | student2@example.com | Student | 2 | User will be enrolled | - | student3@example.com | Student | 3 | User will be enrolled | + | Email address | First name | Last name | User enrolment | + | student1@example.com | Student | 1 | User will be enrolled | + | student2@example.com | Student | 2 | User will be enrolled | + | student3@example.com | Student | 3 | User will be enrolled | And the following should exist in the "localbulkenrol_enrolinfo" table: - | Enrolment method | Assigned role | - | Self enrolment | Student | + | Enrolment method | Assigned role | + | Self enrolment | Student | And I click on "Enrol users" "button" Then the following should exist in the "participants" table: - | Email address | First name | Surname | Roles | - | student1@example.com | Student | 1 | Student | - | student2@example.com | Student | 2 | Student | - | student3@example.com | Student | 3 | Student | + | Email address | First name | Last name | Roles | + | student1@example.com | Student | 1 | Student | + | student2@example.com | Student | 2 | Student | + | student3@example.com | Student | 3 | Student | And "div[data-fullname='Student 1'][data-enrolinstancename='Self enrolment (Student)'][data-status='Active']" "css_element" should exist Scenario: Bulk enrol students into the course who are not enrolled yet with authentication method manual @@ -72,19 +73,19 @@ Feature: Using the local_bulkenrol plugin for user enrolments """ And I click on "Enrol users" "button" Then the following should exist in the "localbulkenrol_enrolusers" table: - | Email address | First name | Surname | User enrolment | - | student1@example.com | Student | 1 | User will be enrolled | - | student2@example.com | Student | 2 | User will be enrolled | - | student3@example.com | Student | 3 | User will be enrolled | + | Email address | First name | Last name | User enrolment | + | student1@example.com | Student | 1 | User will be enrolled | + | student2@example.com | Student | 2 | User will be enrolled | + | student3@example.com | Student | 3 | User will be enrolled | And the following should exist in the "localbulkenrol_enrolinfo" table: | Enrolment method | Assigned role | | Manual enrolments | Student | And I click on "Enrol users" "button" Then the following should exist in the "participants" table: - | Email address | First name | Surname | Roles | - | student1@example.com | Student | 1 | Student | - | student2@example.com | Student | 2 | Student | - | student3@example.com | Student | 3 | Student | + | Email address | First name | Last name | Roles | + | student1@example.com | Student | 1 | Student | + | student2@example.com | Student | 2 | Student | + | student3@example.com | Student | 3 | Student | And "div[data-fullname='Student 1'][data-enrolinstancename='Manual enrolments'][data-status='Active']" "css_element" should exist Scenario: Bulk enrol users into the course who are not enrolled yet with role teacher @@ -105,19 +106,19 @@ Feature: Using the local_bulkenrol plugin for user enrolments """ And I click on "Enrol users" "button" Then the following should exist in the "localbulkenrol_enrolusers" table: - | Email address | First name | Surname | User enrolment | - | student1@example.com | Student | 1 | User will be enrolled | - | student2@example.com | Student | 2 | User will be enrolled | - | student3@example.com | Student | 3 | User will be enrolled | + | Email address | First name | Last name | User enrolment | + | student1@example.com | Student | 1 | User will be enrolled | + | student2@example.com | Student | 2 | User will be enrolled | + | student3@example.com | Student | 3 | User will be enrolled | And the following should exist in the "localbulkenrol_enrolinfo" table: | Enrolment method | Assigned role | | Manual enrolments | Teacher | And I click on "Enrol users" "button" Then the following should exist in the "participants" table: - | Email address | First name | Surname | Roles | - | student1@example.com | Student | 1 | Teacher | - | student2@example.com | Student | 2 | Teacher | - | student3@example.com | Student | 3 | Teacher | + | Email address | First name | Last name | Roles | + | student1@example.com | Student | 1 | Teacher | + | student2@example.com | Student | 2 | Teacher | + | student3@example.com | Student | 3 | Teacher | And "div[data-fullname='Student 1'][data-enrolinstancename='Manual enrolments'][data-status='Active']" "css_element" should exist Scenario: Bulk enrol users into the course by their ID @@ -172,16 +173,16 @@ Feature: Using the local_bulkenrol plugin for user enrolments """ And I click on "Enrol users" "button" Then the following should exist in the "localbulkenrol_enrolusers" table: - | Email address | First name | Surname | User enrolment | - | student1@example.com | Student | 1 | User is already enrolled | - | student2@example.com | Student | 2 | User will be enrolled | - | student3@example.com | Student | 3 | User will be enrolled | + | Email address | First name | Last name | User enrolment | + | student1@example.com | Student | 1 | User is already enrolled | + | student2@example.com | Student | 2 | User will be enrolled | + | student3@example.com | Student | 3 | User will be enrolled | And I click on "Enrol users" "button" Then the following should exist in the "participants" table: - | Email address | First name | Surname | Roles | - | student1@example.com | Student | 1 | Student | - | student2@example.com | Student | 2 | Student | - | student3@example.com | Student | 3 | Student | + | Email address | First name | Last name | Roles | + | student1@example.com | Student | 1 | Student | + | student2@example.com | Student | 2 | Student | + | student3@example.com | Student | 3 | Student | Scenario: Respect existing self enrolments during bulk enrol Given I log in as "admin" @@ -204,12 +205,12 @@ Feature: Using the local_bulkenrol plugin for user enrolments """ And I click on "Enrol users" "button" And the following should exist in the "localbulkenrol_enrolusers" table: - | Email address | First name | Surname | User enrolment | - | student1@example.com | Student | 1 | User is already enrolled | + | Email address | First name | Last name | User enrolment | + | student1@example.com | Student | 1 | User is already enrolled | And I click on "Enrol users" "button" And the following should exist in the "participants" table: - | Email address | First name | Surname | Roles | - | student1@example.com | Student | 1 | Student | + | Email address | First name | Last name | Roles | + | student1@example.com | Student | 1 | Student | Then "div[data-fullname='Student 1'][data-enrolinstancename='Manual enrolments'] a[data-action=showdetails]" "css_element" should not exist And "div[data-fullname='Student 1'][data-enrolinstancename='Self enrolment'] a[data-action=showdetails]" "css_element" should exist diff --git a/version.php b/version.php index 555d5d7..efc815e 100644 --- a/version.php +++ b/version.php @@ -26,8 +26,8 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'local_bulkenrol'; -$plugin->version = 2022071201; -$plugin->release = 'v4.0-r2'; -$plugin->requires = 2022041900; -$plugin->supported = [400, 400]; +$plugin->version = 2023010500; +$plugin->release = 'v4.1-r1'; +$plugin->requires = 2022112800; +$plugin->supported = [401, 401]; $plugin->maturity = MATURITY_STABLE;