Skip to content

Commit

Permalink
MDL-66133 user: Add setting to configure user filters
Browse files Browse the repository at this point in the history
  • Loading branch information
abias committed Aug 23, 2019
1 parent 0dca957 commit a292ed5
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 1 deletion.
32 changes: 32 additions & 0 deletions admin/settings/users.php
Expand Up @@ -21,6 +21,38 @@
$ADMIN->add('accounts', new admin_externalpage('userbulk', new lang_string('userbulk','admin'), "$CFG->wwwroot/$CFG->admin/user/user_bulk.php", array('moodle/user:update', 'moodle/user:delete')));
$ADMIN->add('accounts', new admin_externalpage('addnewuser', new lang_string('addnewuser'), "$CFG->wwwroot/user/editadvanced.php?id=-1", 'moodle/user:create'));

// "User management" settingpage.
$temp = new admin_settingpage('usermanagement', new lang_string('usermanagement', 'admin'));
if ($ADMIN->fulltree) {
$choices = array();
$choices['realname'] = new lang_string('fullnameuser');
$choices['lastname'] = new lang_string('lastname');
$choices['firstname'] = new lang_string('firstname');
$choices['username'] = new lang_string('username');
$choices['email'] = new lang_string('email');
$choices['city'] = new lang_string('city');
$choices['country'] = new lang_string('country');
$choices['confirmed'] = new lang_string('confirmed', 'admin');
$choices['suspended'] = new lang_string('suspended', 'auth');
$choices['profile'] = new lang_string('profilefields', 'admin');
$choices['courserole'] = new lang_string('courserole', 'filters');
$choices['anycourses'] = new lang_string('anycourses', 'filters');
$choices['systemrole'] = new lang_string('globalrole', 'role');
$choices['cohort'] = new lang_string('idnumber', 'core_cohort');
$choices['firstaccess'] = new lang_string('firstaccess', 'filters');
$choices['lastaccess'] = new lang_string('lastaccess');
$choices['neveraccessed'] = new lang_string('neveraccessed', 'filters');
$choices['timemodified'] = new lang_string('lastmodified');
$choices['nevermodified'] = new lang_string('nevermodified', 'filters');
$choices['auth'] = new lang_string('authentication');
$choices['idnumber'] = new lang_string('idnumber');
$choices['lastip'] = new lang_string('lastip');
$choices['mnethostid'] = new lang_string('mnetidprovider', 'mnet');
$temp->add(new admin_setting_configmultiselect('userfiltersdefault', new lang_string('userfiltersdefault', 'admin'),
new lang_string('userfiltersdefault_desc', 'admin'), array('realname'), $choices));
}
$ADMIN->add('accounts', $temp);

// "User default preferences" settingpage.
$temp = new admin_settingpage('userdefaultpreferences', new lang_string('userdefaultpreferences', 'admin'));
if ($ADMIN->fulltree) {
Expand Down
150 changes: 150 additions & 0 deletions admin/tests/behat/filter_users_settings.feature
@@ -0,0 +1,150 @@
@core @core_admin @javascript
Feature: An administrator can configure the available user list filters
In order to have all needed user filters instantly at hand
As an admin
I want to configure the filters which are shown as default

Scenario: Do not change the user filter default configuration
When I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
Then I should see "User full name"
And I should not see "Surname" in the "New filter" "fieldset"
And I should not see "Firstname" in the "New filter" "fieldset"
And I should not see "Username" in the "New filter" "fieldset"
And I should not see "Email address" in the "New filter" "fieldset"
And I should not see "City/town" in the "New filter" "fieldset"
And I should not see "Country" in the "New filter" "fieldset"
And I should not see "Confirmed" in the "New filter" "fieldset"
And I should not see "Suspended account" in the "New filter" "fieldset"
And I should not see "User profile fields" in the "New filter" "fieldset"
And I should not see "Course role" in the "New filter" "fieldset"
And I should not see "Enrolled in any course" in the "New filter" "fieldset"
And I should not see "System role" in the "New filter" "fieldset"
And I should not see "Cohort ID" in the "New filter" "fieldset"
And I should not see "First access" in the "New filter" "fieldset"
And I should not see "Last access" in the "New filter" "fieldset"
And I should not see "Last modified" in the "New filter" "fieldset"
And I should not see "Authentication" in the "New filter" "fieldset"
And I should not see "ID number" in the "New filter" "fieldset"
And I should not see "Last IP address" in the "New filter" "fieldset"
And I should not see "MNet ID provider" in the "New filter" "fieldset"
And I navigate to "Users > Accounts > Bulk user actions" in site administration
Then I should see "User full name"
And I should not see "Surname" in the "New filter" "fieldset"
And I should not see "Firstname" in the "New filter" "fieldset"
And I should not see "Username" in the "New filter" "fieldset"
And I should not see "Email address" in the "New filter" "fieldset"
And I should not see "City/town" in the "New filter" "fieldset"
And I should not see "Country" in the "New filter" "fieldset"
And I should not see "Confirmed" in the "New filter" "fieldset"
And I should not see "Suspended account" in the "New filter" "fieldset"
And I should not see "User profile fields" in the "New filter" "fieldset"
And I should not see "Course role" in the "New filter" "fieldset"
And I should not see "Enrolled in any course" in the "New filter" "fieldset"
And I should not see "System role" in the "New filter" "fieldset"
And I should not see "Cohort ID" in the "New filter" "fieldset"
And I should not see "First access" in the "New filter" "fieldset"
And I should not see "Last access" in the "New filter" "fieldset"
And I should not see "Last modified" in the "New filter" "fieldset"
And I should not see "Authentication" in the "New filter" "fieldset"
And I should not see "ID number" in the "New filter" "fieldset"
And I should not see "Last IP address" in the "New filter" "fieldset"
And I should not see "MNet ID provider" in the "New filter" "fieldset"

Scenario: Change the user filter default configuration to something else
Given the following config values are set as admin:
| userfiltersdefault | realname,username,email |
And I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
Then I should see "User full name"
And I should not see "Surname" in the "New filter" "fieldset"
And I should not see "Firstname" in the "New filter" "fieldset"
And I should see "Username" in the "New filter" "fieldset"
And I should see "Email address" in the "New filter" "fieldset"
And I should not see "City/town" in the "New filter" "fieldset"
And I should not see "Country" in the "New filter" "fieldset"
And I should not see "Confirmed" in the "New filter" "fieldset"
And I should not see "Suspended account" in the "New filter" "fieldset"
And I should not see "User profile fields" in the "New filter" "fieldset"
And I should not see "Course role" in the "New filter" "fieldset"
And I should not see "Enrolled in any course" in the "New filter" "fieldset"
And I should not see "System role" in the "New filter" "fieldset"
And I should not see "Cohort ID" in the "New filter" "fieldset"
And I should not see "First access" in the "New filter" "fieldset"
And I should not see "Last access" in the "New filter" "fieldset"
And I should not see "Last modified" in the "New filter" "fieldset"
And I should not see "Authentication" in the "New filter" "fieldset"
And I should not see "ID number" in the "New filter" "fieldset"
And I should not see "Last IP address" in the "New filter" "fieldset"
And I should not see "MNet ID provider" in the "New filter" "fieldset"
And I navigate to "Users > Accounts > Bulk user actions" in site administration
Then I should see "User full name"
And I should not see "Surname" in the "New filter" "fieldset"
And I should not see "Firstname" in the "New filter" "fieldset"
And I should see "Username" in the "New filter" "fieldset"
And I should see "Email address" in the "New filter" "fieldset"
And I should not see "City/town" in the "New filter" "fieldset"
And I should not see "Country" in the "New filter" "fieldset"
And I should not see "Confirmed" in the "New filter" "fieldset"
And I should not see "Suspended account" in the "New filter" "fieldset"
And I should not see "User profile fields" in the "New filter" "fieldset"
And I should not see "Course role" in the "New filter" "fieldset"
And I should not see "Enrolled in any course" in the "New filter" "fieldset"
And I should not see "System role" in the "New filter" "fieldset"
And I should not see "Cohort ID" in the "New filter" "fieldset"
And I should not see "First access" in the "New filter" "fieldset"
And I should not see "Last access" in the "New filter" "fieldset"
And I should not see "Last modified" in the "New filter" "fieldset"
And I should not see "Authentication" in the "New filter" "fieldset"
And I should not see "ID number" in the "New filter" "fieldset"
And I should not see "Last IP address" in the "New filter" "fieldset"
And I should not see "MNet ID provider" in the "New filter" "fieldset"

Scenario: Change the user filter default configuration to no filter at all
Given the following config values are set as admin:
| userfiltersdefault | |
And I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
Then I should see "User full name"
And I should not see "Surname" in the "New filter" "fieldset"
And I should not see "Firstname" in the "New filter" "fieldset"
And I should not see "Username" in the "New filter" "fieldset"
And I should not see "Email address" in the "New filter" "fieldset"
And I should not see "City/town" in the "New filter" "fieldset"
And I should not see "Country" in the "New filter" "fieldset"
And I should not see "Confirmed" in the "New filter" "fieldset"
And I should not see "Suspended account" in the "New filter" "fieldset"
And I should not see "User profile fields" in the "New filter" "fieldset"
And I should not see "Course role" in the "New filter" "fieldset"
And I should not see "Enrolled in any course" in the "New filter" "fieldset"
And I should not see "System role" in the "New filter" "fieldset"
And I should not see "Cohort ID" in the "New filter" "fieldset"
And I should not see "First access" in the "New filter" "fieldset"
And I should not see "Last access" in the "New filter" "fieldset"
And I should not see "Last modified" in the "New filter" "fieldset"
And I should not see "Authentication" in the "New filter" "fieldset"
And I should not see "ID number" in the "New filter" "fieldset"
And I should not see "Last IP address" in the "New filter" "fieldset"
And I should not see "MNet ID provider" in the "New filter" "fieldset"
And I navigate to "Users > Accounts > Bulk user actions" in site administration
Then I should see "User full name"
And I should not see "Surname" in the "New filter" "fieldset"
And I should not see "Firstname" in the "New filter" "fieldset"
And I should not see "Username" in the "New filter" "fieldset"
And I should not see "Email address" in the "New filter" "fieldset"
And I should not see "City/town" in the "New filter" "fieldset"
And I should not see "Country" in the "New filter" "fieldset"
And I should not see "Confirmed" in the "New filter" "fieldset"
And I should not see "Suspended account" in the "New filter" "fieldset"
And I should not see "User profile fields" in the "New filter" "fieldset"
And I should not see "Course role" in the "New filter" "fieldset"
And I should not see "Enrolled in any course" in the "New filter" "fieldset"
And I should not see "System role" in the "New filter" "fieldset"
And I should not see "Cohort ID" in the "New filter" "fieldset"
And I should not see "First access" in the "New filter" "fieldset"
And I should not see "Last access" in the "New filter" "fieldset"
And I should not see "Last modified" in the "New filter" "fieldset"
And I should not see "Authentication" in the "New filter" "fieldset"
And I should not see "ID number" in the "New filter" "fieldset"
And I should not see "Last IP address" in the "New filter" "fieldset"
And I should not see "MNet ID provider" in the "New filter" "fieldset"
3 changes: 3 additions & 0 deletions lang/en/admin.php
Expand Up @@ -1385,6 +1385,9 @@
$string['userimagesdisabled'] = 'Profile user images are disabled';
$string['userlist'] = 'Browse list of users';
$string['userdefaultpreferences'] = 'User default preferences';
$string['userfiltersdefault'] = 'Default user filters';
$string['userfiltersdefault_desc'] = 'Select the filters that should be shown on the \'Browse list of users\' page and on the \'Bulk user actions\' page. Hold down the Ctrl key to select multiple items. Any filters not selected will be available by clicking the \'Show more\' link.';
$string['usermanagement'] = 'User management';
$string['userpreference'] = 'User preference';
$string['userpolicies'] = 'User policies';
$string['users'] = 'Users';
Expand Down
21 changes: 20 additions & 1 deletion user/filters/lib.php
Expand Up @@ -64,11 +64,30 @@ public function __construct($fieldnames = null, $baseurl = null, $extraparams =
}

if (empty($fieldnames)) {
$fieldnames = array('realname' => 0, 'lastname' => 1, 'firstname' => 1, 'username' => 1, 'email' => 1, 'city' => 1,
// As a start, add all fields as advanced fields (which are only available after clicking on "Show more").
$fieldnames = array('realname' => 1, 'lastname' => 1, 'firstname' => 1, 'username' => 1, 'email' => 1, 'city' => 1,
'country' => 1, 'confirmed' => 1, 'suspended' => 1, 'profile' => 1, 'courserole' => 1,
'anycourses' => 1, 'systemrole' => 1, 'cohort' => 1, 'firstaccess' => 1, 'lastaccess' => 1,
'neveraccessed' => 1, 'timemodified' => 1, 'nevermodified' => 1, 'auth' => 1, 'mnethostid' => 1,
'idnumber' => 1, 'lastip' => 1);

// Get the config which filters the admin wanted to show by default.
$userfiltersdefault = get_config('core', 'userfiltersdefault');

// If the admin did not enable any filter, the form will not make much sense if all fields are hidden behind
// "Show more". Thus, we enable the 'realname' filter automatically.
if ($userfiltersdefault == '') {
$userfiltersdefault = array('realname');

// Otherwise, we split the enabled filters into an array.
} else {
$userfiltersdefault = explode(',', $userfiltersdefault);
}

// Show these fields by default which the admin has enabled in the config.
foreach ($userfiltersdefault as $key) {
$fieldnames[$key] = 0;
}
}

$this->_fields = array();
Expand Down

0 comments on commit a292ed5

Please sign in to comment.