From 2cde957897726a657275ad6c0f796c88028c0449 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Tue, 21 Mar 2023 16:01:33 +0100 Subject: [PATCH] MDL-77468 user: Fix invalid check for group belonging --- lib/myprofilelib.php | 3 +- user/lib.php | 1 + user/tests/behat/view_full_profile.feature | 51 ++++++++++++++++++++-- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/lib/myprofilelib.php b/lib/myprofilelib.php index 57a90741849..eb6baaa394e 100644 --- a/lib/myprofilelib.php +++ b/lib/myprofilelib.php @@ -299,7 +299,8 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $groupstr = ''; foreach ($usergroups as $group) { if ($course->groupmode == SEPARATEGROUPS and !$accessallgroups and $user->id != $USER->id) { - if (!groups_is_member($group->id, $user->id)) { + // In separate groups mode, I only have to see the groups shared between both users. + if (!groups_is_member($group->id, $USER->id)) { continue; } } diff --git a/user/lib.php b/user/lib.php index 5471d9a6c57..463228b277a 100644 --- a/user/lib.php +++ b/user/lib.php @@ -1381,3 +1381,4 @@ function user_edit_map_field_purpose($userid, $fieldname) { return $purpose; } + diff --git a/user/tests/behat/view_full_profile.feature b/user/tests/behat/view_full_profile.feature index 5a0071f0922..75e6220d096 100644 --- a/user/tests/behat/view_full_profile.feature +++ b/user/tests/behat/view_full_profile.feature @@ -9,17 +9,19 @@ Feature: Access to full profiles of users | username | firstname | lastname | email | | student1 | Student | 1 | student1@example.com | | student2 | Student | 2 | student2@example.com | - | student3 | Student | 3 | student2@example.com | + | student3 | Student | 3 | student3@example.com | | teacher1 | Teacher | 1 | teacher1@example.com | And the following "courses" exist: - | fullname | shortname | format | - | Course 1 | C1 | topics | - | Course 2 | C2 | topics | + | fullname | shortname | format | groupmode | + | Course 1 | C1 | topics | 0 | + | Course 2 | C2 | topics | 1 | And the following "course enrolments" exist: | user | course | role | | student1 | C1 | student | | student2 | C1 | student | | teacher1 | C1 | editingteacher | + | teacher1 | C2 | editingteacher | + | student1 | C2 | student | | student3 | C2 | student | And the following config values are set as admin: | messaging | 1 | @@ -79,6 +81,42 @@ Feature: Access to full profiles of users When I follow "Profile" in the user menu Then I should see "First access to site" + Scenario: View only shared groups in a course with separate groups forced + Given the following "groups" exist: + | name | course | idnumber | + | Group 1 | C2 | G1 | + | Group 2 | C2 | G2 | + And the following "group members" exist: + | user | group | + | student1 | G1 | + | student3 | G2 | + | teacher1 | G1 | + | teacher1 | G2 | + When I log in as "student3" + And I am on "Course 2" course homepage + And I navigate to course participants + And I follow "Teacher 1" + Then I should see "Group 2" + And I should not see "Group 1" + + Scenario: View all groups in a course with visible groups + Given the following "groups" exist: + | name | course | idnumber | + | Group 1 | C1 | G1 | + | Group 2 | C1 | G2 | + And the following "group members" exist: + | user | group | + | student1 | G1 | + | student2 | G2 | + | teacher1 | G1 | + | teacher1 | G2 | + When I log in as "student1" + And I am on "Course 1" course homepage + And I navigate to course participants + And I follow "Teacher 1" + Then I should see "Group 1" + And I should see "Group 2" + @javascript Scenario: Viewing full profiles of someone with the course contact role Given I log in as "admin" @@ -96,6 +134,11 @@ Feature: Access to full profiles of users When I log in as "student1" And I open messaging And I search for "Student 3" in messaging + Then I should see "Student 3" + And I log out + When I log in as "student2" + And I open messaging + And I search for "Student 3" in messaging Then I should see "No results" @javascript