Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I just want to do something really simple.

Disable access to the user/s profile for viewing and editing. Basically users can create and account but won't be able to edit or view their own/or other users profiles.

What's the best way to do this?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Add this to a custom module:

function MYMODULE_menu_alter(&$items) {
  $items['user/%user']['access arguments'] = array('access user profiles');
  $items['user/%user']['access callback'] = 'user_access';
  $items['user/%user/edit']['access arguments'] = array('administer users');
  $items['user/%user/edit']['access callback'] = 'user_access';
}

This will put the user profile view under 'View user profiles' permission and edit under 'Administer users'.

share|improve this answer
    
thanks very much! worked a treat. I thought that I tried to do this with hook_menu but I suppose it was in the wrong place and should be in hook_menu_alter –  space_balls Aug 20 at 6:25

you can also use below method. Go to "admin/config/people/accounts/display". Set permission for individual fields don't want to show user by using https://www.drupal.org/project/field_permissions.

share|improve this answer

Instead of creating a module for that you could simply create a rule.

Here's a how-to:

step 1: create a rule that acts on this event: "User account page is viewed"

step 2: set a condition, something like: "NOT User has role(s) Parameter: User: [account], Roles: administrator"

step 3: create an action: "Page redirect Parameter: URL: toboggan/denied" (in case you are using login toboggan but any page url should work here so you could create a page especially for that saying something like: "We're very sorry but at this moment you can't access your profile page."

step 4: make this rule active for example in case you wanted to get the latest version of your production site, download a sql backup, fiddle around with it locally and then be sure to upload it again without disappointing any users who might wanted to update their profile in the mean time.

additionally you could also add another condition to check if the user is viewing another user's profile page or their own so that you make two different rules, one which shows a page saying that they temporarily can't update their profile and another rule which shows a page that states why they can't view a particular user's profile.

I've tested this and added this condition: "Data comparison Parameter: Data to compare: [account], Data value: [site:current-user]" What this does is only deny access to view their own account and then show the correct page you created for this denied access. I think this makes more sense.

share|improve this answer
    
Always excited to use the power of rules. However this didn't work if the user has the direct URL to the edit page /user/nn/edit. It does prevent them from going to the /user page though. –  Tony Dec 8 at 23:44
    
Well spotted. If we could just add one more condition that checks if a url is of the string user/* then we'd be saved. I've tried it with a text comparison comparing the [account:edit-url] and the [site:current-user:edit-url] but that didn't work. Neither did the "Path has url alias" [site:current-user:edit-url] condition. I'll keep looking. –  BassPlaya Dec 10 at 7:33
    
I couldn't figure it out and the code from the accepted answer worked well so I gave up. –  Tony Dec 10 at 13:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.