MDL-77468 user: Fix invalid check for group belonging

This commit is contained in:
Juan Leyva 2023-03-21 16:01:33 +01:00 committed by Rodrigo Mady
parent 4c533b8204
commit 2cde957897
3 changed files with 50 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -1381,3 +1381,4 @@ function user_edit_map_field_purpose($userid, $fieldname) {
return $purpose;
}

View File

@ -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