diff --git a/privatemsg.module b/privatemsg.module index 2610f62..73c64be 100644 --- a/privatemsg.module +++ b/privatemsg.module @@ -286,8 +286,8 @@ function privatemsg_menu() { 'page callback' => 'privatemsg_list_page', 'page arguments' => array('list', 1), 'file' => 'privatemsg.pages.inc', - 'access callback' => 'privatemsg_user_access', - 'access arguments' => array('read all private messages'), + 'access callback' => 'privatemsg_ownuser_access', + 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, ); return $items; @@ -349,6 +349,29 @@ function privatemsg_user_access($permission = 'read privatemsg', $account = NULL } /** + * Checks access for the messages tab on the user profile. + * + * Privatemsg wrapper for user_access and the user/%/messages menu options, + * allows access to the own profile, otherwise calls to privatemsg_user_access. + * + * @param $uid + * ID of the user which profile is being showed. + * + * @return + * TRUE if user has access, FALSE if not. + */ +function privatemsg_ownuser_access ($uid = NULL) { + global $user ; + + if ($user->uid && $uid == $user->uid){ + return TRUE ; + } else { + return privatemsg_user_access('read all private messages', $uid) ; + } +} + + +/** * Check access to the view messages page. * * Function to restrict the access of the view messages page to just the diff --git a/privatemsg.pages.inc b/privatemsg.pages.inc index 162aba1..0136802 100644 --- a/privatemsg.pages.inc +++ b/privatemsg.pages.inc @@ -150,6 +150,11 @@ function privatemsg_list_page($argument = 'list', $uid = NULL) { // Has rights and user_load return an array so user does exist $account = $account_check; } + // Redirects to 'messages' if it's the own profile. + else if ((int)$uid > 0 && $uid == $user->uid) { + drupal_goto('messages'); + return; + } return drupal_get_form('privatemsg_list', $argument, $account); }