Merge branch 'MDL-66133-master' of git://github.com/abias/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2019-08-28 17:38:25 +02:00
commit 998f605d5c
4 changed files with 213 additions and 9 deletions

View File

@ -1,6 +1,6 @@
<?php
// This file defines settingpages and externalpages under the "users" category
// This file defines settingpages and externalpages under the "users" category.
$ADMIN->add('users', new admin_category('accounts', new lang_string('accounts', 'admin')));
$ADMIN->add('users', new admin_category('roles', new lang_string('permissions', 'role')));
@ -13,15 +13,47 @@ if ($hassiteconfig
or has_capability('moodle/role:manage', $systemcontext)
or has_capability('moodle/role:assign', $systemcontext)
or has_capability('moodle/cohort:manage', $systemcontext)
or has_capability('moodle/cohort:view', $systemcontext)) { // speedup for non-admins, add all caps used on this page
or has_capability('moodle/cohort:view', $systemcontext)) { // Speedup for non-admins, add all caps used on this page.
// stuff under the "accounts" subcategory
// Stuff under the "accounts" subcategory.
$ADMIN->add('accounts', new admin_externalpage('editusers', new lang_string('userlist','admin'), "$CFG->wwwroot/$CFG->admin/user.php", array('moodle/user:update', 'moodle/user:delete')));
$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 default preferences" settingpage.
// 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) {
$choices = array();
@ -62,9 +94,9 @@ if ($hassiteconfig
$ADMIN->add('accounts', new admin_externalpage('cohorts', new lang_string('cohorts', 'cohort'), $CFG->wwwroot . '/cohort/index.php', array('moodle/cohort:manage', 'moodle/cohort:view')));
// stuff under the "roles" subcategory
// Stuff under the "roles" subcategory.
// "userpolicies" settingpage
// User policies settingpage.
$temp = new admin_settingpage('userpolicies', new lang_string('userpolicies', 'admin'));
if ($ADMIN->fulltree) {
if (!during_initial_install()) {
@ -138,7 +170,7 @@ if ($hassiteconfig
$temp->add(new admin_setting_configselect('restorernewroleid', new lang_string('restorernewroleid', 'admin'),
new lang_string('restorernewroleid_help', 'admin'), $defaultteacherid, $restorersnewrole));
// release memory
// Release memory.
unset($otherroles);
unset($guestroles);
unset($userroles);
@ -209,7 +241,7 @@ if ($hassiteconfig
$ADMIN->add('roles', new admin_externalpage('assignroles', new lang_string('assignglobalroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=".$systemcontext->id, 'moodle/role:assign'));
$ADMIN->add('roles', new admin_externalpage('checkpermissions', new lang_string('checkglobalpermissions', 'role'), "$CFG->wwwroot/$CFG->admin/roles/check.php?contextid=".$systemcontext->id, array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage')));
} // end of speedup
} // End of speedup.
// Privacy settings.
if ($hassiteconfig) {

View File

@ -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"

View File

@ -1385,6 +1385,9 @@ $string['userbulkdownload'] = 'Export users as';
$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';

View File

@ -64,11 +64,30 @@ class user_filtering {
}
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();