MDL-63691 core_message: added api::can_create_group_conversation

This commit is contained in:
Mark Nelson
2018-10-22 10:21:27 +08:00
parent a66ae84911
commit e66b915c40
2 changed files with 48 additions and 0 deletions
+19
View File
@@ -1385,6 +1385,25 @@ class api {
return $conversation->id;
}
/**
* Checks if a user can create a group conversation.
*
* @param int $userid The id of the user attempting to create the conversation
* @param \context $context The context they are creating the conversation from, most likely course context
* @return bool
*/
public static function can_create_group_conversation(int $userid, \context $context) : bool {
global $CFG;
// If we can't message at all, then we can't create a conversation.
if (empty($CFG->messaging)) {
return false;
}
// We need to check they have the capability to create the conversation.
return has_capability('moodle/course:creategroupconversations', $context, $userid);
}
/**
* Checks if a user can create a contact request.
*