From b74abdbea1df0567fe349c7d519072e2aa2b6157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Sat, 6 Feb 2021 15:47:04 +0100 Subject: [PATCH] MDL-70786 report_log: respect fullname setting. --- report/log/classes/renderable.php | 9 +++++++- report/log/classes/table_log.php | 4 ++-- report/log/tests/behat/filter_log.feature | 14 ++++++++----- report/log/tests/behat/user_log.feature | 25 ++++++++++++++++------- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/report/log/classes/renderable.php b/report/log/classes/renderable.php index 10b580ffff7..597ae1f226f 100644 --- a/report/log/classes/renderable.php +++ b/report/log/classes/renderable.php @@ -299,7 +299,14 @@ class report_log_renderable implements renderable { */ public function get_selected_user_fullname() { $user = core_user::get_user($this->userid); - return fullname($user); + if (empty($this->course)) { + // We are in system context. + $context = context_system::instance(); + } else { + // We are in course context. + $context = context_course::instance($this->course->id); + } + return fullname($user, has_capability('moodle/site:viewfullnames', $context)); } /** diff --git a/report/log/classes/table_log.php b/report/log/classes/table_log.php index 845fac2e696..a02a715ede2 100644 --- a/report/log/classes/table_log.php +++ b/report/log/classes/table_log.php @@ -130,7 +130,7 @@ class report_log_table_log extends table_sql { return false; } - $this->userfullnames[$userid] = fullname($user); + $this->userfullnames[$userid] = fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())); return $this->userfullnames[$userid]; } @@ -592,7 +592,7 @@ class report_log_table_log extends table_sql { $users = $DB->get_records_sql("SELECT id," . get_all_user_name_fields(true) . " FROM {user} WHERE id " . $usql, $uparams); foreach ($users as $userid => $user) { - $this->userfullnames[$userid] = fullname($user); + $this->userfullnames[$userid] = fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())); unset($userids[$userid]); } diff --git a/report/log/tests/behat/filter_log.feature b/report/log/tests/behat/filter_log.feature index 9f2174d652d..a6619e97fa5 100644 --- a/report/log/tests/behat/filter_log.feature +++ b/report/log/tests/behat/filter_log.feature @@ -9,12 +9,16 @@ Feature: In a report, admin can filter log data | fullname | shortname | category | groupmode | | Course 1 | C1 | 0 | 1 | And the following "users" exist: - | username | firstname | lastname | email | - | student1 | Student | 1 | student1@example.com | + | username | firstname | lastname | email | idnumber | middlename | alternatename | firstnamephonetic | lastnamephonetic | + | teacher1 | Teacher | One | teacher1@example.com | t1 | | fred | | | + | student1 | Grainne | Beauchamp | student1@example.com | s1 | Ann | Jill | Gronya | Beecham | And the following "course enrolments" exist: | user | course | role | | admin | C1 | editingteacher | | student1 | C1 | student | + And the following config values are set as admin: + | fullnamedisplay | firstname | + | alternativefullnameformat | middlename, alternatename, firstname, lastname | And I log in as "admin" Scenario: Filter log report for standard and legacy log reader @@ -25,7 +29,7 @@ Feature: In a report, admin can filter log data And I follow "Home" And I am on "Course 1" course homepage And I navigate to course participants - And I follow "Student 1" + And I follow "Ann, Jill, Grainne, Beauchamp" And I click on "Log in as" "link" And I press "Continue" And I log out @@ -44,7 +48,7 @@ Feature: In a report, admin can filter log data Scenario: Filter log report for standard log reader Given I am on "Course 1" course homepage And I navigate to course participants - And I follow "Student 1" + And I follow "Ann, Jill, Grainne, Beauchamp" And I click on "Log in as" "link" And I press "Continue" And I log out @@ -66,7 +70,7 @@ Feature: In a report, admin can filter log data And I follow "Home" And I am on "Course 1" course homepage And I navigate to course participants - And I follow "Student 1" + And I follow "Ann, Jill, Grainne, Beauchamp" And I click on "Log in as" "link" And I press "Continue" And I log out diff --git a/report/log/tests/behat/user_log.feature b/report/log/tests/behat/user_log.feature index b8726726f82..d4106aee7be 100644 --- a/report/log/tests/behat/user_log.feature +++ b/report/log/tests/behat/user_log.feature @@ -9,13 +9,16 @@ Feature: User can view activity log. | fullname | shortname | category | groupmode | | Course 1 | C1 | 0 | 1 | And the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - | student1 | Student | 1 | student1@example.com | + | username | firstname | lastname | email | idnumber | middlename | alternatename | firstnamephonetic | lastnamephonetic | + | teacher1 | Teacher | One | teacher1@example.com | t1 | | fred | | | + | student1 | Grainne | Beauchamp | student1@example.com | s1 | Ann | Jill | Gronya | Beecham | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | + And the following config values are set as admin: + | fullnamedisplay | firstname | + | alternativefullnameformat | middlename, alternatename, firstname, lastname | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And I add a "Assignment" to section "1" and I fill the form with: @@ -37,10 +40,10 @@ Feature: User can view activity log. Given I log in as "teacher1" And I am on "Course 1" course homepage And I navigate to course participants - And I follow "Student 1" + And I follow "Ann, Jill, Grainne, Beauchamp" When I follow "Today's logs" And I should see "Assignment: Test assignment name" - And I follow "Student 1" + And I follow "Ann, Jill, Grainne, Beauchamp" And I follow "All logs" Then I should see "Assignment: Test assignment name" @@ -52,9 +55,17 @@ Feature: User can view activity log. And I log in as "teacher1" And I am on "Course 1" course homepage And I navigate to course participants - And I follow "Student 1" + And I follow "Ann, Jill, Grainne, Beauchamp" When I follow "Today's logs" And I should see "No log reader enabled" - And I follow "Student 1" + And I follow "Ann, Jill, Grainne, Beauchamp" And I follow "All logs" Then I should see "No log reader enabled" + + Scenario: View Todays' log report for user through Course log report + Given I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Reports > Logs" in current page administration + And I set the field with xpath "//select[@name='user']" to "Ann, Jill, Grainne, Beauchamp" + When I click on "Get these logs" "button" + Then I should see "Ann, Jill, Grainne, Beauchamp"