This is a suggested update to the USER.MODULE.

Purpose: to allow drupal site administrators to toggle "ACCESS USERS" in the ADMINISTER -> USERS -> CONFIG -> PERMISSONS page for certain roles and restrict access to the USER LIST & USER PROFILES on a drupal site.

ADJUSTMENT #1: Adding in extra option on permissions page

search for function user_perm() and replace the lines you see in your user.module with this.

function user_perm() {
return array('administer users', 'access users');
}

Adjustment #2: Instructing drupal to check to see if the user has access to view the user list & user profiles before displaying them.

Search for the following string theme_user_function and replace the lines you see in your user.module with this.

function theme_user_profile($account, $fields) {
global $user;
if (user_access('access users')) // check to see if the user has access
{
$output = "<div class=\"profile\">\n";
$output .= theme('user_picture', $account); // if so display the user account details
foreach ($fields as $category => $value) {
$output .= "<h2>$category</h2>$value";
}
$output .= "</div>\n";
}
else
{
// if the user is not logged in display a message
$output = "<div class=\"profile\">\n";
$output .= "Sorry. You must <a href='?q=user/login'>LOGIN</a> to have access to view this 
page.";
$output .= "</div>\n";
}
return $output;
}

Hope thats of use to others.

Dublin Drupaller

Comments

Anonymous’s picture

Hi,

Cheers for that. This is exactly what I was looking for. I've updated the module with the new code. It prevents full profiles being shown, but if an anonymous user goes to http://site/?q=profile, they still get a list of all users?!?

Have I misunderstood your intention here, as it does mention restricting access to USER LIST?

Dublin Drupaller’s picture

which version of drupal are you using?

I'm not sure if this works (the above snippets) with 4.6 or versions later than 4.5.0.

Dub

Anonymous’s picture

Hi,

Am using 4.5.1... had another look and noticed that there is another function

function theme_user_list($items, $title = NULL) {
  return theme('item_list', $items, $title);
}

I'm supposing that this has something to do with it!

forngren’s picture

Title: Restricting access to user list and user profiles » Restricting access to user list
Version: 4.5.0 » x.y.z

Access to user profile is fixed, access to user list remains.

lilou’s picture

Version: x.y.z » 7.x-dev
lilou’s picture

Category: task » feature
Wolfflow’s picture

subscribe

mdupont’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +access permissions
jhedstrom’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs issue summary update

There are several contrib modules that allow for this. Anything left to be done here?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dpi’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

@ #9

Don't think so. You can just clone the people view and change the route permission requirements as needed.