Skip to content

Commit

Permalink
MDL-83256 user: account for course context instances of teacher fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Dec 16, 2024
1 parent aa55f38 commit eac6320
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions user/profile/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,10 @@ public function is_visible(?context $context = null): bool {
return true;
} else if ($this->userid > 0) {
return has_capability('moodle/user:viewalldetails', $context);
} else if ($context instanceof context_course) {
return has_capability('moodle/site:viewuseridentity', $context);
} else {
// Fall back to the global course object.
$coursecontext = context_course::instance($COURSE->id);
return has_capability('moodle/site:viewuseridentity', $coursecontext);
}
Expand Down
2 changes: 1 addition & 1 deletion user/tests/fields_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public function test_get_identity_fields(): void {

// Give the student the basic identity fields permission (also makes them count as 'teacher'
// for the teacher-restricted field).
$COURSE = $course; // Horrible hack, because PROFILE_VISIBLE_TEACHERS relies on this global.
$roleid = $DB->get_field('role', 'id', ['shortname' => 'student']);
role_change_permission($roleid, $coursecontext, 'moodle/site:viewuseridentity', CAP_ALLOW);
$this->assertEquals(['department', 'profile_field_a', 'profile_field_d'],
Expand Down Expand Up @@ -132,6 +131,7 @@ public function test_get_identity_fields(): void {
$this->assertEquals([], fields::get_identity_fields($usercontext));

// Give them basic permission.
$COURSE = $course; // Horrible hack, because PROFILE_VISIBLE_TEACHERS relies on this global.
role_change_permission($roleid, $usercontext, 'moodle/site:viewuseridentity', CAP_ALLOW);
$this->assertEquals(['department', 'profile_field_a', 'profile_field_d'],
fields::get_identity_fields($usercontext));
Expand Down

0 comments on commit eac6320

Please sign in to comment.