mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-32082 message: added a function to make user checks more readable
This commit is contained in:
parent
93fb7b528b
commit
85427358fc
2 changed files with 23 additions and 6 deletions
|
@ -118,12 +118,7 @@ unset($user2id);
|
|||
|
||||
// Is the user involved in the conversation?
|
||||
// Do they have the ability to read other user's conversations?
|
||||
// There will always be a $user1
|
||||
// but $user2 may be null. For example, if viewing $user1's recent conversations
|
||||
if ($user1->id != $USER->id
|
||||
&& (empty($user2) || $user2->id != $USER->id)
|
||||
&& !has_capability('moodle/site:readallmessages', $context)){
|
||||
|
||||
if (!message_current_user_is_involved($user1, $user2) && !has_capability('moodle/site:readallmessages', $context)) {
|
||||
print_error('accessdenied','admin');
|
||||
}
|
||||
|
||||
|
|
|
@ -2418,3 +2418,25 @@ function translate_message_default_setting($plugindefault, $processorname) {
|
|||
function message_page_type_list($pagetype, $parentcontext, $currentcontext) {
|
||||
return array('messages-*'=>get_string('page-message-x', 'message'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is $USER one of the supplied users?
|
||||
*
|
||||
* $user2 will be null if viewing a user's recent conversations
|
||||
*
|
||||
* @param stdClass the first user
|
||||
* @param stdClass the second user or null
|
||||
* @return bool True if the current user is one of either $user1 or $user2
|
||||
*/
|
||||
function message_current_user_is_involved($user1, $user2) {
|
||||
global $USER;
|
||||
|
||||
if (empty($user1->id) || (!empty($user2) && empty($user2->id))) {
|
||||
throw new coding_exception('Invalid user object detected. Missing id.');
|
||||
}
|
||||
|
||||
if ($user1->id != $USER->id && (empty($user2) || $user2->id != $USER->id)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue