From a6f9bad45b1d8caa75931b645b63c3c46a0f6280 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 3 Aug 2021 23:00:12 +0100 Subject: [PATCH] MDL-71347 user: add time created filter to browse users page. AMOS BEGIN CPY [timecreated,core_contentbank],[timecreated,moodle] AMOS END --- admin/settings/users.php | 1 + lang/en/moodle.php | 1 + user/filters/lib.php | 5 +- user/tests/behat/filter_timecreated.feature | 52 +++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 user/tests/behat/filter_timecreated.feature diff --git a/admin/settings/users.php b/admin/settings/users.php index aa602290f6e6f..c420becfffd72 100644 --- a/admin/settings/users.php +++ b/admin/settings/users.php @@ -42,6 +42,7 @@ $choices['firstaccess'] = new lang_string('firstaccess', 'filters'); $choices['lastaccess'] = new lang_string('lastaccess'); $choices['neveraccessed'] = new lang_string('neveraccessed', 'filters'); + $choices['timecreated'] = new lang_string('timecreated'); $choices['timemodified'] = new lang_string('lastmodified'); $choices['nevermodified'] = new lang_string('nevermodified', 'filters'); $choices['auth'] = new lang_string('authentication'); diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 549e25ba96578..1e243eea90ae1 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -2125,6 +2125,7 @@ $string['thiscategory'] = 'This category'; $string['thiscategorycontains'] = 'This category contains'; $string['time'] = 'Time'; +$string['timecreated'] = 'Time created'; $string['timecreatedcourse'] = 'Course time created'; $string['timezone'] = 'Timezone'; $string['to'] = 'To'; diff --git a/user/filters/lib.php b/user/filters/lib.php index 0bb6c893a4bce..9cfb1bb99be72 100644 --- a/user/filters/lib.php +++ b/user/filters/lib.php @@ -68,8 +68,8 @@ public function __construct($fieldnames = null, $baseurl = null, $extraparams = $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, 'institution' => 1, 'department' => 1, 'lastip' => 1); + 'neveraccessed' => 1, 'timecreated' => 1, 'timemodified' => 1, 'nevermodified' => 1, 'auth' => 1, + 'mnethostid' => 1, 'idnumber' => 1, 'institution' => 1, 'department' => 1, 'lastip' => 1); // Get the config which filters the admin wanted to show by default. $userfiltersdefault = get_config('core', 'userfiltersdefault'); @@ -175,6 +175,7 @@ public function get_field($fieldname, $advanced) { case 'firstaccess': return new user_filter_date('firstaccess', get_string('firstaccess', 'filters'), $advanced, 'firstaccess'); case 'lastaccess': return new user_filter_date('lastaccess', get_string('lastaccess'), $advanced, 'lastaccess'); case 'neveraccessed': return new user_filter_checkbox('neveraccessed', get_string('neveraccessed', 'filters'), $advanced, 'firstaccess', array('lastaccess_sck', 'lastaccess_eck', 'firstaccess_eck', 'firstaccess_sck')); + case 'timecreated': return new user_filter_date('timecreated', get_string('timecreated'), $advanced, 'timecreated'); case 'timemodified': return new user_filter_date('timemodified', get_string('lastmodified'), $advanced, 'timemodified'); case 'nevermodified': return new user_filter_checkbox('nevermodified', get_string('nevermodified', 'filters'), $advanced, array('timemodified', 'timecreated'), array('timemodified_sck', 'timemodified_eck')); case 'cohort': return new user_filter_cohort($advanced); diff --git a/user/tests/behat/filter_timecreated.feature b/user/tests/behat/filter_timecreated.feature new file mode 100644 index 0000000000000..8c6f02da32958 --- /dev/null +++ b/user/tests/behat/filter_timecreated.feature @@ -0,0 +1,52 @@ +@core @core_user +Feature: Filter users by time created + In order to find users created relative to a date + As an admin + I need to be able to filter users by their time created date + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | user01 | User | One | user01@example.com | + + @javascript + Scenario Outline: Matching user filter by time created + Given I log in as "admin" + And I navigate to "Users > Accounts > Browse list of users" in site administration + And I follow "Show more..." + # Set the filter fields, excluding admin. + When I set the following fields to these values: + | [enabled] | 1 | + | [year] | | + | Username field limiter | doesn't contain | + | Username value | admin | + And I press "Add filter" + Then I should see "User One" in the "users" "table" + And I should see "1 / 2 Users" + Examples: + | enablefield | year | + # Time created, is after. + | timecreated_sdt | ## -1 year ## %Y ## | + # Time created, is before. + | timecreated_edt | ## +1 year ## %Y ## | + + @javascript + Scenario Outline: Non-matching user filter by time created + Given I log in as "admin" + And I navigate to "Users > Accounts > Browse list of users" in site administration + And I follow "Show more..." + # Set the filter fields, excluding admin. + When I set the following fields to these values: + | [enabled] | 1 | + | [year] | | + | Username field limiter | doesn't contain | + | Username value | admin | + And I press "Add filter" + Then "Users" "table" should not exist + And I should see "0 / 2 Users" + Examples: + | enablefield | year | + # Time created, is after. + | timecreated_sdt | ## +1 year ## %Y ## | + # Time created, is before. + | timecreated_edt | ## -1 year ## %Y ## |