From efb9654dcb374261f8bb6ef487a701efe69159ef Mon Sep 17 00:00:00 2001 From: sam marshall Date: Thu, 18 Mar 2021 13:00:20 +0000 Subject: [PATCH] MDL-71131 Admin: Users page incorrectly showing all name fields --- admin/tests/behat/browse_users.feature | 50 ++++++++++++++++++++ admin/user.php | 9 ++-- user/tests/behat/filter_participants.feature | 2 +- 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 admin/tests/behat/browse_users.feature diff --git a/admin/tests/behat/browse_users.feature b/admin/tests/behat/browse_users.feature new file mode 100644 index 00000000000..b6d9f412141 --- /dev/null +++ b/admin/tests/behat/browse_users.feature @@ -0,0 +1,50 @@ +@core @core_admin +Feature: An administrator can browse user accounts + In order to find the user accounts I am looking for + As an admin + I can browse users and see their basic information + + Background: + Given the following "custom profile fields" exist: + | datatype | shortname | name | + | text | frog | Favourite frog | + And the following "users" exist: + | username | firstname | lastname | email | department | profile_field_frog | firstnamephonetic | + | user1 | User | One | one@example.com | Attack | Kermit | Yewzer | + | user2 | User | Two | two@example.com | Defence | Tree | Yoozare | + And I log in as "admin" + + Scenario: User accounts display default fields + When I navigate to "Users > Accounts > Browse list of users" in site administration + # Name field always present, email field is default for showidentity. + Then the following should exist in the "users" table: + | First name / Surname | Email address | + | User One | one@example.com | + | User Two | two@example.com | + # Should not see other identity fields or non-default name fields. + And I should not see "Department" in the "table" "css_element" + And I should not see "Attack" + And I should not see "Favourite frog" in the "table" "css_element" + And I should not see "Kermit" + And I should not see "First name - phonetic" in the "table" "css_element" + And I should not see "Yoozare" + + Scenario: User accounts with extra name fields + Given the following config values are set as admin: + | alternativefullnameformat | firstnamephonetic lastname | + When I navigate to "Users > Accounts > Browse list of users" in site administration + Then the following should exist in the "users" table: + | First name - phonetic / Surname | Email address | + | Yewzer One | one@example.com | + | Yoozare Two | two@example.com | + + Scenario: User accounts with specified identity fields + Given the following config values are set as admin: + | showuseridentity | department,profile_field_frog | + When I navigate to "Users > Accounts > Browse list of users" in site administration + Then the following should exist in the "users" table: + | First name / Surname | Favourite frog | Department | + | User One | Kermit | Attack | + | User Two | Tree | Defence | + And I should not see "Email address" in the "table" "css_element" + And I should not see "one@example.com" diff --git a/admin/user.php b/admin/user.php index 4d491aac4e6..59853ca45a8 100644 --- a/admin/user.php +++ b/admin/user.php @@ -183,10 +183,11 @@ // These columns are always shown in the users list. $requiredcolumns = array('city', 'country', 'lastaccess'); // Extra columns containing the extra user fields, excluding the required columns (city and country, to be specific). - $userfields = \core_user\fields::for_identity($context, true)->with_name()->excluding(...$requiredcolumns); + $userfields = \core_user\fields::for_identity($context, true)->excluding(...$requiredcolumns); $extracolumns = $userfields->get_required_fields(); - // Get all user name fields as an array. - $columns = array_merge($extracolumns, $requiredcolumns); + // Get all user name fields as an array, but with firstname and lastname first. + $allusernamefields = \core_user\fields::get_name_fields(true); + $columns = array_merge($allusernamefields, $extracolumns, $requiredcolumns); foreach ($columns as $column) { $string[$column] = \core_user\fields::get_display_name($column); @@ -226,7 +227,7 @@ } // Order in string will ensure that the name columns are in the correct order. - $usernames = order_in_string($extracolumns, $fullnamesetting); + $usernames = order_in_string($allusernamefields, $fullnamesetting); $fullnamedisplay = array(); foreach ($usernames as $name) { // Use the link from $$column for sorting on the user's name. diff --git a/user/tests/behat/filter_participants.feature b/user/tests/behat/filter_participants.feature index 730b58b2d54..f9aa410e27f 100644 --- a/user/tests/behat/filter_participants.feature +++ b/user/tests/behat/filter_participants.feature @@ -1018,7 +1018,7 @@ Feature: Course participants can be filtered And I should not see "Student 3" in the "participants" "table" And I should not see "Patricia Pea" in the "participants" "table" - @javascript @frogfrog + @javascript Scenario: Filtering works correctly with custom profile fields Given the following config values are set as admin: | showuseridentity | email,profile_field_frog |