Commit e5eba802 authored by Sara Arjona's avatar Sara Arjona
Browse files

MDL-63289 message: Deprecate is_user_non_contact_blocked method

This function has been deprecated and no other function has been
added to replace it. It was only called from can_post_message, so
its code has been moved there.
parent 7983fb83
......@@ -987,11 +987,14 @@ class api {
* contact. If not then it checks to make sure the sender is in the
* recipient's contacts.
*
* @deprecated since 3.6
* @param \stdClass $recipient The user object.
* @param \stdClass|null $sender The user object.
* @return bool true if $sender is blocked, false otherwise.
*/
public static function is_user_non_contact_blocked($recipient, $sender = null) {
debugging('\core_message\api::is_user_non_contact_blocked() is deprecated', DEBUG_DEVELOPER);
global $USER, $CFG;
if (is_null($sender)) {
......
......@@ -1582,28 +1582,33 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// By default, user only can be messaged by contacts and members of any of his/her courses.
$this->assertTrue(\core_message\api::is_user_non_contact_blocked($user2));
$this->assertDebuggingCalled();
// Enable all users privacy messaging and check now the default user's preference has been set to allow receiving
// messages from everybody.
set_config('messagingallusers', true);
// Check that the return result is now false because any site user can contact him/her.
$this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2));
$this->assertDebuggingCalled();
// Set the second user's preference to not receive messages from non-contacts.
set_user_preference('message_blocknoncontacts', \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS, $user2->id);
// Check that the return result is still true (because is even more restricted).
$this->assertTrue(\core_message\api::is_user_non_contact_blocked($user2));
$this->assertDebuggingCalled();
// Add the first user as a contact for the second user.
\core_message\api::add_contact($user2->id, $user1->id);
// Check that the return result is now false.
$this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2));
$this->assertDebuggingCalled();
// Set the second user's preference to receive messages from course members.
set_user_preference('message_blocknoncontacts', \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER, $user2->id);
// Check that the return result is still false (because $user1 is still his/her contact).
$this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2));
$this->assertDebuggingCalled();
}
/**
......
......@@ -29,6 +29,7 @@ information provided here is intended especially for developers.
* The following methods have been deprecated and should not be used any more:
- \core_message\api::is_user_blocked()
- \core_message\api::delete_conversation()
- \core_message\api::is_user_non_contact_blocked()
* The method \core_message\api::can_delete_conversation() now expects a 'conversationid' to be passed
as the second parameter.
* The following web services have been deprecated. Please do not call these any more.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment