Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'MDL-32082_messaging_readability_21' of git://github.com…

…/andyjdavis/moodle into MOODLE_21_STABLE
  • Loading branch information...
commit b2313c434fd90f09eda6cb86f5480655cc8a33a1 2 parents 4790c88 + 8b19610
@stronk7 stronk7 authored
Showing with 23 additions and 6 deletions.
  1. +1 −6 message/index.php
  2. +22 −0 message/lib.php
View
7 message/index.php
@@ -118,12 +118,7 @@
// 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');
}
View
22 message/lib.php
@@ -2416,3 +2416,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;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.