MDL-64031 enrol_manual: Fix hard-coded list of user fields.
authorVinhLe <Vinh.LeThe@Nashtechglobal.com>
Wed, 21 Nov 2018 06:35:42 +0000 (13:35 +0700)
committerVinhLe <Vinh.LeThe@Nashtechglobal.com>
Fri, 11 Jan 2019 04:24:15 +0000 (11:24 +0700)
Respect get_extra_user_fields() in PHP code

enrol/manual/amd/build/form-potential-user-selector.min.js
enrol/manual/amd/src/form-potential-user-selector.js
enrol/manual/classes/enrol_users_form.php
enrol/manual/tests/behat/quickenrolment.feature

index 2ced5d6..bf66147 100644 (file)
Binary files a/enrol/manual/amd/build/form-potential-user-selector.min.js and b/enrol/manual/amd/build/form-potential-user-selector.min.js differ
index 066f59d..7fac602 100644 (file)
@@ -49,6 +49,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], function($, Ajax,
         transport: function(selector, query, success, failure) {
             var promise;
             var courseid = $(selector).attr('courseid');
+            var userfields = $(selector).attr('userfields').split(',');
             if (typeof courseid === "undefined") {
                 courseid = '1';
             }
@@ -78,7 +79,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], function($, Ajax,
                     $.each(results, function(index, user) {
                         var ctx = user,
                             identity = [];
-                        $.each(['idnumber', 'email', 'phone1', 'phone2', 'department', 'institution'], function(i, k) {
+                        $.each(userfields, function(i, k) {
                             if (typeof user[k] !== 'undefined' && user[k] !== '') {
                                 ctx.hasidentity = true;
                                 identity.push(user[k]);
index da4cd68..165a6e9 100644 (file)
@@ -98,7 +98,8 @@ class enrol_manual_enrol_users_form extends moodleform {
             'ajax' => 'enrol_manual/form-potential-user-selector',
             'multiple' => true,
             'courseid' => $course->id,
-            'enrolid' => $instance->id
+            'enrolid' => $instance->id,
+            'userfields' => implode(',', get_extra_user_fields($context))
         );
         $mform->addElement('autocomplete', 'userlist', get_string('selectusers', 'enrol_manual'), array(), $options);
 
index c5e3549..2afa506 100644 (file)
@@ -153,3 +153,28 @@ Feature: Teacher can search and enrol users one by one into the course
     When I set the field "Select users" to "example.com"
     And I click on ".form-autocomplete-downarrow" "css_element" in the "Select users" "form_row"
     Then I should see "Too many users (>100) to show"
+
+  @javascript
+  Scenario: Change the Show user identity setting affects the enrolment pop-up.
+    Given I log out
+    When I log in as "admin"
+    Then the following "users" exist:
+      | username    | firstname | lastname | email                   | phone1     | phone2     | department | institution | city    | country  |
+      | student100  | Student   | 100      | student100@example.com  | 1234567892 | 1234567893 | ABC1       | ABC2        | CITY1   | UK       |
+    And the following config values are set as admin:
+      | showuseridentity | idnumber,email,city,country,phone1,phone2,department,institution |
+    When I am on "Course 001" course homepage
+    Then I navigate to course participants
+    And I press "Enrol users"
+    When I set the field "Select users" to "student100@example.com"
+    And I click on ".form-autocomplete-downarrow" "css_element" in the "Select users" "form_row"
+    Then I should see "student100@example.com, CITY1, UK, 1234567892, 1234567893, ABC1, ABC2"
+    # Remove identity field in setting User policies
+    And the following config values are set as admin:
+      | showuseridentity | idnumber,email,phone1,phone2,department,institution |
+    When I am on "Course 001" course homepage
+    And I navigate to course participants
+    And I press "Enrol users"
+    When I set the field "Select users" to "student100@example.com"
+    And I click on ".form-autocomplete-downarrow" "css_element" in the "Select users" "form_row"
+    Then I should see "student100@example.com, 1234567892, 1234567893, ABC1, ABC2"