From cdcf6f44fc158f2aa509b4147c8fd689fd4b6b53 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 | 33 ++++++++++++++++++----- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/report/log/classes/renderable.php b/report/log/classes/renderable.php index 5500d7a460c..76433fa6515 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 c53bcedf704..ec67c4de7ee 100644 --- a/report/log/classes/table_log.php +++ b/report/log/classes/table_log.php @@ -132,7 +132,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]; } @@ -596,7 +596,7 @@ class report_log_table_log extends table_sql { " 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 2a172821a89..da4dc9ff40e 100644 --- a/report/log/tests/behat/user_log.feature +++ b/report/log/tests/behat/user_log.feature @@ -9,9 +9,9 @@ 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 | @@ -25,6 +25,17 @@ Feature: User can view activity log. | section | 1 | | assignsubmission_onlinetext_enabled | 1 | | assignsubmission_file_enabled | 0 | + 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: + | Assignment name | Test assignment name | + | Description | Submit your online text | + | assignsubmission_onlinetext_enabled | 1 | + | assignsubmission_file_enabled | 0 | + And I log out And I log in as "student1" And I am on "Course 1" course homepage And I follow "Test assignment name" @@ -38,10 +49,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" @@ -53,9 +64,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"