Commit 4b84de9a authored by Gerhard Killesreiter's avatar Gerhard Killesreiter

#14591, User.module links for blocked/non-existant accounts + menu 403/404...

#14591, User.module links for blocked/non-existant accounts + menu 403/404 issue, patch by Steven and merlinofchaos
parent 5db4a65d
......@@ -260,6 +260,10 @@ function drupal_not_found() {
menu_set_active_item($path);
$return = menu_execute_active_handler();
}
else {
// Redirect to a non-existant menu item to make possible tabs disappear.
menu_set_active_item('#');
}
if (empty($return)) {
drupal_set_title(t('Page not found'));
......@@ -279,6 +283,10 @@ function drupal_access_denied() {
menu_set_active_item($path);
$return = menu_execute_active_handler();
}
else {
// Redirect to a non-existant menu item to make possible tabs disappear.
menu_set_active_item('#');
}
if (empty($return)) {
drupal_set_title(t('Access denied'));
......
......@@ -320,8 +320,12 @@ function contact_admin_settings_submit($form_id, $form_values) {
function contact_mail_user() {
global $user;
if ($account = user_load(array('uid' => arg(1), 'status' => 1))) {
if (!$account->contact && !user_access('administer users')) {
if ($account = user_load(array('uid' => arg(1)))) {
$admin_access = user_access('administer users');
if (!$account->status && !$admin_access) {
drupal_access_denied();
}
else if (!$account->contact && !$admin_access) {
$output = t('%name is not accepting e-mails.', array('%name' => $account->name));
}
else if (!$user->uid) {
......
......@@ -320,8 +320,12 @@ function contact_admin_settings_submit($form_id, $form_values) {
function contact_mail_user() {
global $user;
if ($account = user_load(array('uid' => arg(1), 'status' => 1))) {
if (!$account->contact && !user_access('administer users')) {
if ($account = user_load(array('uid' => arg(1)))) {
$admin_access = user_access('administer users');
if (!$account->status && !$admin_access) {
drupal_access_denied();
}
else if (!$account->contact && !$admin_access) {
$output = t('%name is not accepting e-mails.', array('%name' => $account->name));
}
else if (!$user->uid) {
......
......@@ -65,9 +65,17 @@ function tracker_menu($may_cache) {
*/
function tracker_track_user() {
if ($account = user_load(array('uid' => arg(1)))) {
if ($account->status || user_access('administer users')) {
drupal_set_title($account->name);
return tracker_page($account->uid);
}
else {
drupal_access_denied();
}
}
else {
drupal_not_found();
}
}
/**
......
......@@ -65,9 +65,17 @@ function tracker_menu($may_cache) {
*/
function tracker_track_user() {
if ($account = user_load(array('uid' => arg(1)))) {
if ($account->status || user_access('administer users')) {
drupal_set_title($account->name);
return tracker_page($account->uid);
}
else {
drupal_access_denied();
}
}
else {
drupal_not_found();
}
}
/**
......
......@@ -686,8 +686,7 @@ function user_menu($may_cache) {
$admin_access = user_access('administer users');
$access_access = user_access('administer access control');
// Users should always be allowed to see their own user page
$view_access = (user_access('access user profiles') || ($user->uid == arg(1)));
$view_access = user_access('access user profiles');
if ($may_cache) {
$items[] = array('path' => 'user', 'title' => t('user account'),
......@@ -769,15 +768,21 @@ function user_menu($may_cache) {
}
else {
if (arg(0) == 'user' && is_numeric(arg(1))) {
$user_exists = user_load(array('uid' => arg(1), 'status' => 1));
$account = user_load(array('uid' => arg(1)));
if ($user !== FALSE) {
// Always let a user view their own account
$view_access |= $user->uid == arg(1);
// Only admins can view blocked accounts
$view_access &= $account->status || $admin_access;
$items[] = array('path' => 'user/'. arg(1), 'title' => t('user'),
'type' => MENU_CALLBACK, 'callback' => 'user_view',
'callback arguments' => array(arg(1)), 'access' => $view_access);
if ($user_exists !== FALSE || $admin_access) {
$items[] = array('path' => 'user/'. arg(1) .'/view', 'title' => t('view'),
'access' => $view_access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$items[] = array('path' => 'user/'. arg(1) .'/edit', 'title' => t('edit'),
'callback' => 'user_edit', 'access' => $admin_access || $user->uid == arg(1),
'type' => MENU_LOCAL_TASK);
......@@ -1406,7 +1411,10 @@ function user_edit_submit($form_id, $form_values) {
function user_view($uid = 0) {
global $user;
if ($account = user_load(array('uid' => $uid, 'status' => 1))) {
$account = user_load(array('uid' => $uid));
if ($account === FALSE) {
return drupal_not_found();
}
// Retrieve and merge all profile fields:
$fields = array();
foreach (module_list() as $module) {
......@@ -1421,10 +1429,6 @@ function user_view($uid = 0) {
}
drupal_set_title($account->name);
return theme('user_profile', $account, $fields);
}
else {
drupal_not_found();
}
}
/*** Administrative features ***********************************************/
......
......@@ -686,8 +686,7 @@ function user_menu($may_cache) {
$admin_access = user_access('administer users');
$access_access = user_access('administer access control');
// Users should always be allowed to see their own user page
$view_access = (user_access('access user profiles') || ($user->uid == arg(1)));
$view_access = user_access('access user profiles');
if ($may_cache) {
$items[] = array('path' => 'user', 'title' => t('user account'),
......@@ -769,15 +768,21 @@ function user_menu($may_cache) {
}
else {
if (arg(0) == 'user' && is_numeric(arg(1))) {
$user_exists = user_load(array('uid' => arg(1), 'status' => 1));
$account = user_load(array('uid' => arg(1)));
if ($user !== FALSE) {
// Always let a user view their own account
$view_access |= $user->uid == arg(1);
// Only admins can view blocked accounts
$view_access &= $account->status || $admin_access;
$items[] = array('path' => 'user/'. arg(1), 'title' => t('user'),
'type' => MENU_CALLBACK, 'callback' => 'user_view',
'callback arguments' => array(arg(1)), 'access' => $view_access);
if ($user_exists !== FALSE || $admin_access) {
$items[] = array('path' => 'user/'. arg(1) .'/view', 'title' => t('view'),
'access' => $view_access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$items[] = array('path' => 'user/'. arg(1) .'/edit', 'title' => t('edit'),
'callback' => 'user_edit', 'access' => $admin_access || $user->uid == arg(1),
'type' => MENU_LOCAL_TASK);
......@@ -1406,7 +1411,10 @@ function user_edit_submit($form_id, $form_values) {
function user_view($uid = 0) {
global $user;
if ($account = user_load(array('uid' => $uid, 'status' => 1))) {
$account = user_load(array('uid' => $uid));
if ($account === FALSE) {
return drupal_not_found();
}
// Retrieve and merge all profile fields:
$fields = array();
foreach (module_list() as $module) {
......@@ -1421,10 +1429,6 @@ function user_view($uid = 0) {
}
drupal_set_title($account->name);
return theme('user_profile', $account, $fields);
}
else {
drupal_not_found();
}
}
/*** Administrative features ***********************************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment