Skip to content

Commit

Permalink
merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Laur0r committed May 12, 2023
2 parents 1ef14d5 + 9cdd556 commit 25b6a16
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
------------
Expand Down
6 changes: 5 additions & 1 deletion lang/en/local_bulkenrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
24 changes: 21 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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);
}
}
}
}
2 changes: 1 addition & 1 deletion locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

defined('MOODLE_INTERNAL') || die;

// Require library.
require_once($CFG->dirroot.'/local/bulkenrol/lib.php');

$filtercustombyunique = true;

$usertableoptions = [
Expand Down Expand Up @@ -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',
Expand Down
61 changes: 31 additions & 30 deletions tests/behat/local_bulkenrol_groups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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 |
57 changes: 57 additions & 0 deletions tests/behat/local_bulkenrol_navigation.feature
Original file line number Diff line number Diff line change
@@ -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 | <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 | <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 |
Loading

0 comments on commit 25b6a16

Please sign in to comment.