MDL-63211 core_message: respect new setting 'messagingallusers'

This commit is contained in:
Mark Nelson
2018-10-03 11:58:39 +08:00
parent c886e2c94d
commit 0d203bbf8d
5 changed files with 100 additions and 2 deletions
+24
View File
@@ -1319,6 +1319,30 @@ class api {
return $conversation->id;
}
/**
* Checks if a user can create a contact request.
*
* @param int $userid The id of the user who is creating the contact request
* @param int $requesteduserid The id of the user being requested
* @return bool
*/
public static function can_create_contact(int $userid, int $requesteduserid) : bool {
global $CFG;
// If we can't message at all, then we can't create a contact.
if (empty($CFG->messaging)) {
return false;
}
// If we can message anyone on the site then we can create a contact.
if ($CFG->messagingallusers) {
return true;
}
// We need to check if they are in the same course.
return enrol_sharing_course($userid, $requesteduserid);
}
/**
* Handles creating a contact request.
*