Skip to content

Commit

Permalink
MDL-65093 core_message: dont show users with cap as blocked
Browse files Browse the repository at this point in the history
It is possible that before this patch the user blocked a
teacher from messaging them, even though this would have
no effect. It is also possible for a user to block a user,
then that user gets 'promoted' to a teacher role and the
block becoming ineffective. In these cases we dont show the
user's status as blocked.
  • Loading branch information
mdjnelson committed Jul 29, 2019
1 parent 90403c5 commit 66fffdb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
11 changes: 7 additions & 4 deletions message/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,10 @@ public static function get_member_info(int $referenceuserid, array $userids, boo

// Set contact and blocked status indicators.
$data->iscontact = ($member->contactid) ? true : false;
$data->isblocked = ($member->blockedid) ? true : false;

// We don't want that a user has been blocked if they can message the user anyways.
$canmessageifblocked = api::can_send_message($referenceuserid, $member->id, true);
$data->isblocked = ($member->blockedid && !$canmessageifblocked) ? true : false;

$data->isdeleted = ($member->deleted) ? true : false;

Expand All @@ -594,9 +597,9 @@ public static function get_member_info(int $referenceuserid, array $userids, boo
$privacysetting = api::get_user_privacy_messaging_preference($member->id);
$data->requirescontact = $privacysetting == api::MESSAGE_PRIVACY_ONLYCONTACTS;

// Here we check that if the sender wanted to block the recipient, the recipient would
// still be able to message them regardless.
$data->canmessageevenifblocked = api::can_send_message($referenceuserid, $member->id, true);
// Here we check that if the sender wanted to block the recipient, the
// recipient would still be able to message them regardless.
$data->canmessageevenifblocked = !$data->isdeleted && $canmessageifblocked;
$data->canmessage = !$data->isdeleted && api::can_send_message($member->id, $referenceuserid);
}

Expand Down
24 changes: 24 additions & 0 deletions message/tests/behat/block_user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,27 @@ Feature: To be able to block users that we are able to or to see a message if we
And I open contact menu
When I click on "Block" "link" in the "[data-region='header-container']" "css_element"
Then I should see "You are unable to block Teacher 1"

Scenario: Block a user who then gets an elevated role
Given I log in as "student1"
And I select "Student 2" user in messaging
And I open contact menu
And I click on "Block" "link" in the "[data-region='header-container']" "css_element"
And I click on "Block" "button" in the "[data-region='confirm-dialogue']" "css_element"
And I log out
And I log in as "admin"
And I am on "Course 1" course homepage
And I navigate to course participants
And I click on "Unenrol" "icon" in the "student2" "table_row"
And I click on "Unenrol" "button" in the "Unenrol" "dialogue"
And I enrol "Student 2" user as "Teacher"
And I log out
And I log in as "student2"
And I select "Student 1" user in messaging
And I should not see "You are unable to message this user"
And I log out
And I log in as "student1"
And I select "Student 2" user in messaging
And I open contact menu
When I click on "Block" "link" in the "[data-region='header-container']" "css_element"
Then I should see "You are unable to block Student 2"

0 comments on commit 66fffdb

Please sign in to comment.