MDL-63211 core_message: deprecated api::is_user_blocked
This commit is contained in:
+12
-5
@@ -913,8 +913,14 @@ class api {
|
||||
if ($sender !== null && isset($sender->id)) {
|
||||
$senderid = $sender->id;
|
||||
}
|
||||
|
||||
$systemcontext = \context_system::instance();
|
||||
if (has_capability('moodle/site:readallmessages', $systemcontext, $senderid)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The recipient has specifically blocked this sender.
|
||||
if (self::is_user_blocked($recipient->id, $senderid)) {
|
||||
if (self::is_blocked($recipient->id, $senderid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -959,12 +965,16 @@ class api {
|
||||
* Note: This function will always return false if the sender has the
|
||||
* readallmessages capability at the system context level.
|
||||
*
|
||||
* @deprecated since 3.6
|
||||
* @param int $recipientid User ID of the recipient.
|
||||
* @param int $senderid User ID of the sender.
|
||||
* @return bool true if $sender is blocked, false otherwise.
|
||||
*/
|
||||
public static function is_user_blocked($recipientid, $senderid = null) {
|
||||
global $USER, $DB;
|
||||
debugging('\core_message\api::is_user_blocked is deprecated and should not be used.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
global $USER;
|
||||
|
||||
if (is_null($senderid)) {
|
||||
// The message is from the logged in user, unless otherwise specified.
|
||||
@@ -1552,9 +1562,6 @@ class api {
|
||||
/**
|
||||
* Checks if a user is already blocked.
|
||||
*
|
||||
* This is different than self::is_user_blocked() as it does not check any capabilities.
|
||||
* It simply checks if an entry exists in the DB.
|
||||
*
|
||||
* @param int $userid
|
||||
* @param int $blockeduserid
|
||||
* @return bool Returns true if they are a blocked, false otherwise
|
||||
|
||||
@@ -101,7 +101,8 @@ class messages implements templatable, renderable {
|
||||
$data->messages[] = $message->export_for_template($output);
|
||||
}
|
||||
|
||||
$data->isblocked = api::is_user_blocked($this->currentuserid, $this->otheruserid);
|
||||
$blockeduserid = $this->otheruserid ?? $USER->id;
|
||||
$data->isblocked = api::is_blocked($this->currentuserid, $blockeduserid);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -1388,16 +1388,19 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
|
||||
// User shouldn't be blocked.
|
||||
$this->assertFalse(\core_message\api::is_user_blocked($user1->id, $user2->id));
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
// Block the user.
|
||||
\core_message\api::block_user($user1->id, $user2->id);
|
||||
|
||||
// User should be blocked.
|
||||
$this->assertTrue(\core_message\api::is_user_blocked($user1->id, $user2->id));
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
// Unblock the user.
|
||||
\core_message\api::unblock_user($user1->id, $user2->id);
|
||||
$this->assertFalse(\core_message\api::is_user_blocked($user1->id, $user2->id));
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1418,6 +1421,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
|
||||
// As the admin you should still be able to send messages to the user.
|
||||
$this->assertFalse(\core_message\api::is_user_blocked($user1->id));
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -26,6 +26,8 @@ information provided here is intended especially for developers.
|
||||
- message_block_contact()
|
||||
- message_get_contact()
|
||||
Please see their declaration in lib/deprecatedlib.php to view their alternatives (if applicable).
|
||||
* The following methods have been deprecated and should not be used any more:
|
||||
- \core_message\api::is_user_blocked()
|
||||
* The following web services have been deprecated. Please do not call these any more.
|
||||
- core_message_external::block_contacts, please use core_message_external::block_user instead.
|
||||
- core_message_external::unblock_contacts, please use core_message_external::unblock_user instead.
|
||||
|
||||
Reference in New Issue
Block a user