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;
}
* 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.
/**
* 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
$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;
}
// 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();
}
/**
// 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();
}
/*
- 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.