Skip to content

Commit

Permalink
Merge branch 'MDL-80843' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Mar 22, 2024
2 parents 9f10899 + d3557d9 commit e366db6
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 68 deletions.
43 changes: 16 additions & 27 deletions reportbuilder/classes/local/entities/user.php
Expand Up @@ -445,6 +445,7 @@ protected function get_user_fields(): array {
'suspended' => new lang_string('suspended'),
'confirmed' => new lang_string('confirmed', 'admin'),
'username' => new lang_string('username'),
'auth' => new lang_string('authentication', 'moodle'),
'moodlenetprofile' => new lang_string('moodlenetprofile', 'user'),
'timecreated' => new lang_string('timecreated', 'core_reportbuilder'),
'timemodified' => new lang_string('timemodified', 'core_reportbuilder'),
Expand Down Expand Up @@ -550,32 +551,6 @@ protected function get_all_filters(): array {
))
->add_joins($this->get_joins());

// Authentication method filter.
$filters[] = (new filter(
select::class,
'auth',
new lang_string('authentication', 'moodle'),
$this->get_entity_name(),
"{$tablealias}.auth"
))
->add_joins($this->get_joins())
->set_options_callback(static function(): array {
$plugins = core_component::get_plugin_list('auth');
$enabled = get_string('pluginenabled', 'core_plugin');
$disabled = get_string('plugindisabled', 'core_plugin');
$authoptions = [$enabled => [], $disabled => []];

foreach ($plugins as $pluginname => $unused) {
$plugin = get_auth_plugin($pluginname);
if (is_enabled_auth($pluginname)) {
$authoptions[$enabled][$pluginname] = $plugin->get_title();
} else {
$authoptions[$disabled][$pluginname] = $plugin->get_title();
}
}
return $authoptions;
});

return $filters;
}

Expand All @@ -598,6 +573,20 @@ protected function get_options_for(string $fieldname): ?array {
return $cached[$fieldname];
}

/**
* List of options for the field auth
*
* @return string[]
*/
public static function get_options_for_auth(): array {
$authlist = array_keys(core_component::get_plugin_list('auth'));

return array_map(
fn(string $auth) => get_auth_plugin($auth)->get_title(),
array_combine($authlist, $authlist),
);
}

/**
* List of options for the field country.
*
Expand All @@ -610,7 +599,7 @@ public static function get_options_for_country(): array {
/**
* List of options for the field theme.
*
* @return array
* @return string[]
*/
public static function get_options_for_theme(): array {
return array_map(
Expand Down
4 changes: 2 additions & 2 deletions reportbuilder/tests/datasource_test.php
Expand Up @@ -55,7 +55,7 @@ public static function add_columns_from_entity_provider(): array {
'All column' => [
[],
[],
30,
31,
],
'Include columns (picture, fullname, fullnamewithlink, fullnamewithpicture, fullnamewithpicturelink)' => [
['picture', 'fullname*'],
Expand All @@ -65,7 +65,7 @@ public static function add_columns_from_entity_provider(): array {
'Exclude columns (picture, fullname, fullnamewithlink, fullnamewithpicture, fullnamewithpicturelink)' => [
[],
['picture', 'fullname*'],
25,
26,
],
];
}
Expand Down
130 changes: 91 additions & 39 deletions user/tests/reportbuilder/datasource/users_test.php
Expand Up @@ -112,59 +112,103 @@ public function test_datasource_non_default_columns(): void {
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastaccess']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:suspended']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:confirmed']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:auth']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:moodlenetprofile']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:timecreated']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:timemodified']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastip']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:theme']);

// Tags.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'tag:name']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'tag:namewithlink']);

// Cohort.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'cohort:name']);

$content = $this->get_custom_report_content($report->get('id'));
$this->assertCount(2, $content);

[$adminrow, $userrow] = array_map('array_values', $content);

$this->assertStringContainsString('Admin User', $adminrow[0]);
$this->assertStringContainsString('Admin User', $adminrow[1]);
$this->assertStringContainsString('Admin User', $adminrow[2]);
$this->assertNotEmpty($adminrow[3]);
$this->assertEquals('Admin', $adminrow[4]);
$this->assertEquals('User', $adminrow[5]);

$this->assertStringContainsString(fullname($user), $userrow[0]);
$this->assertStringContainsString(fullname($user), $userrow[1]);
$this->assertStringContainsString(fullname($user), $userrow[2]);
$this->assertNotEmpty($userrow[3]);
$this->assertEquals($user->firstname, $userrow[4]);
$this->assertEquals($user->lastname, $userrow[5]);
$this->assertEquals($user->city, $userrow[6]);
$this->assertEquals('United Kingdom', $userrow[7]);
$this->assertEquals($user->description, $userrow[8]);
$this->assertEquals($user->firstnamephonetic, $userrow[9]);
$this->assertEquals($user->lastnamephonetic, $userrow[10]);
$this->assertEquals($user->middlename, $userrow[11]);
$this->assertEquals($user->alternatename, $userrow[12]);
$this->assertEquals($user->idnumber, $userrow[13]);
$this->assertEquals($user->institution, $userrow[14]);
$this->assertEquals($user->department, $userrow[15]);
$this->assertEquals($user->phone1, $userrow[16]);
$this->assertEquals($user->phone2, $userrow[17]);
$this->assertEquals($user->address, $userrow[18]);
$this->assertEmpty($userrow[19]);
$this->assertEquals('No', $userrow[20]);
$this->assertEquals('Yes', $userrow[21]);
$this->assertEquals($user->moodlenetprofile, $userrow[22]);
$this->assertNotEmpty($userrow[23]);
$this->assertEquals('0.0.0.0', $userrow[24]);
$this->assertEquals('Boost', $userrow[25]);
$this->assertEquals('Horses', $userrow[26]);
$this->assertStringContainsString('Horses', $userrow[27]);
$this->assertEquals($cohort->name, $userrow[28]);
// Admin row.
[
$fullnamewithlink,
$fullnamewithpicture,
$fullnamewithpicturelink,
$picture,
$lastname,
$firstname,
] = array_values($content[0]);

$this->assertStringContainsString('Admin User', $fullnamewithlink);
$this->assertStringContainsString('Admin User', $fullnamewithpicture);
$this->assertStringContainsString('Admin User', $fullnamewithpicturelink);
$this->assertNotEmpty($picture);
$this->assertEquals('Admin', $lastname);
$this->assertEquals('User', $firstname);

// User row.
[
$fullnamewithlink,
$fullnamewithpicture,
$fullnamewithpicturelink,
$picture,
$firstname,
$lastname,
$city,
$country,
$description,
$firstnamephonetic,
$lastnamephonetic,
$middlename,
$alternatename,
$idnumber,
$institution,
$department,
$phone1,
$phone2,
$address,
$lastaccess,
$suspended,
$confirmed,
$auth,
$moodlenetprofile,
$timecreated,
$timemodified,
$lastip,
$theme,
$tag,
$cohortname,
] = array_values($content[1]);

$this->assertStringContainsString(fullname($user), $fullnamewithlink);
$this->assertStringContainsString(fullname($user), $fullnamewithpicture);
$this->assertStringContainsString(fullname($user), $fullnamewithpicturelink);
$this->assertNotEmpty($picture);
$this->assertEquals($user->firstname, $firstname);
$this->assertEquals($user->lastname, $lastname);
$this->assertEquals($user->city, $city);
$this->assertEquals('United Kingdom', $country);
$this->assertEquals($user->description, $description);
$this->assertEquals($user->firstnamephonetic, $firstnamephonetic);
$this->assertEquals($user->lastnamephonetic, $lastnamephonetic);
$this->assertEquals($user->middlename, $middlename);
$this->assertEquals($user->alternatename, $alternatename);
$this->assertEquals($user->idnumber, $idnumber);
$this->assertEquals($user->institution, $institution);
$this->assertEquals($user->department, $department);
$this->assertEquals($user->phone1, $phone1);
$this->assertEquals($user->phone2, $phone2);
$this->assertEquals($user->address, $address);
$this->assertEmpty($lastaccess);
$this->assertEquals('No', $suspended);
$this->assertEquals('Yes', $confirmed);
$this->assertEquals('Manual accounts', $auth);
$this->assertEquals($user->moodlenetprofile, $moodlenetprofile);
$this->assertNotEmpty($timecreated);
$this->assertNotEmpty($timemodified);
$this->assertEquals('0.0.0.0', $lastip);
$this->assertEquals('Boost', $theme);
$this->assertEquals('Horses', $tag);
$this->assertEquals($cohort->name, $cohortname);
}

/**
Expand Down Expand Up @@ -368,6 +412,14 @@ public function datasource_filters_provider(): array {
'user:timecreated_from' => 1619823600,
'user:timecreated_to' => 1622502000,
], false],
'Filter timemodified' => ['user:timemodified', [
'user:timemodified_operator' => date::DATE_RANGE,
'user:timemodified_from' => 1622502000,
], true],
'Filter timemodified (no match)' => ['user:timemodified', [
'user:timemodified_operator' => date::DATE_RANGE,
'user:timemodified_to' => 1622502000,
], false],
'Filter lastaccess' => ['user:lastaccess', [
'user:lastaccess_operator' => date::DATE_EMPTY,
], true],
Expand Down

0 comments on commit e366db6

Please sign in to comment.