mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-65093 core_message: deprecate can_post_message()
This commit is contained in:
parent
f622ee97e3
commit
06d046c1ff
7 changed files with 237 additions and 16 deletions
|
@ -1844,6 +1844,8 @@ class api {
|
|||
* Determines if a user is permitted to send another user a private message.
|
||||
* If no sender is provided then it defaults to the logged in user.
|
||||
*
|
||||
* @deprecated since 3.8
|
||||
* @todo Final deprecation in MDL-66266
|
||||
* @param \stdClass $recipient The user object.
|
||||
* @param \stdClass|null $sender The user object.
|
||||
* @return bool true if user is permitted, false otherwise.
|
||||
|
@ -1851,22 +1853,37 @@ class api {
|
|||
public static function can_post_message($recipient, $sender = null) {
|
||||
global $USER;
|
||||
|
||||
debugging('\core_message\api::can_post_message is deprecated, please use ' .
|
||||
'\core_message\api::can_send_message instead.', DEBUG_DEVELOPER);
|
||||
|
||||
if (is_null($sender)) {
|
||||
// The message is from the logged in user, unless otherwise specified.
|
||||
$sender = $USER;
|
||||
}
|
||||
|
||||
return self::can_send_message($recipient->id, $sender->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a user is permitted to send another user a private message.
|
||||
*
|
||||
* @param int $recipientid The recipient user id.
|
||||
* @param int $senderid The sender user id.
|
||||
* @return bool true if user is permitted, false otherwise.
|
||||
*/
|
||||
public static function can_send_message(int $recipientid, int $senderid) : bool {
|
||||
$systemcontext = \context_system::instance();
|
||||
if (!has_capability('moodle/site:sendmessage', $systemcontext, $sender)) {
|
||||
|
||||
if (!has_capability('moodle/site:sendmessage', $systemcontext, $senderid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (has_capability('moodle/site:readallmessages', $systemcontext, $sender->id)) {
|
||||
if (has_capability('moodle/site:readallmessages', $systemcontext, $senderid)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the recipient can be messaged by the sender.
|
||||
return (self::can_contact_user($recipient->id, $sender->id));
|
||||
return self::can_contact_user($recipientid, $senderid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -592,14 +592,7 @@ class helper {
|
|||
if ($includeprivacyinfo) {
|
||||
$privacysetting = api::get_user_privacy_messaging_preference($member->id);
|
||||
$data->requirescontact = $privacysetting == api::MESSAGE_PRIVACY_ONLYCONTACTS;
|
||||
|
||||
$recipient = new \stdClass();
|
||||
$recipient->id = $member->id;
|
||||
|
||||
$sender = new \stdClass();
|
||||
$sender->id = $referenceuserid;
|
||||
|
||||
$data->canmessage = !$data->isdeleted && api::can_post_message($recipient, $sender);
|
||||
$data->canmessage = !$data->isdeleted && api::can_send_message($member->id, $referenceuserid);
|
||||
}
|
||||
|
||||
// Populate the contact requests, even if we don't need them.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue