3

I have two user roles:

  • business_users
  • company_users

I want to set the permission for all users to see the user profile of users in "business_users" role only.

  • User with the "company_user" role should not to see user profile of user in their role but they can see user profile of user in "business_users" role.

  • User with the "business_users" role can see user profile of users with their role but they should not see the user profile of users with the "company_user" role.

  • Anonymous users should see user profile of user in "business_users" role only.

Can you tell how can I implement it?

2 Answers 2

1

You can make a template file for your profile content type, probably called something like node_profile.tpl.

At the top of this file, write some code that will get the user object of the node owner, and check this against user's roles in $user->roles.

It's easier if you do this with the roleID numbers (you can see these by going to user>role and hovering your mouse over the various links for the roles - the roleID appears as a number somewhere in the link).

Your code in the template then may look something like this. You'll need to know php to understand how it executes.

$userRoles = $GLOBALS['user']->roles;
$account = user_load($node->nid);
if(!empty($userRoles[2])) {
  // user is a company user
  if(!empty($account->roles[2])) {
    // profile belongs to a company user
    print 'Company users are only allowed to see business user profiles';
    return; // this will stop execution of the template file, and return to the page template
  } elseif(!empty($account->roles[1])) {
    // profile belongs to a business user
    // do nothing - just continue code execution of this template
  }
}

For your listings of users, you'll want to make three different views, with views filters in each to determine which users you want displayed. For this, you can create a page which chooses the name of the view based on the user's role(s) - either a "page" with the php code in the body (if you have php code as one of your input types), or else a page you create with a small custom module using hook_menu().

1
  • So this is a possible solution, but 'user_access' is typically the best way to restrict and check user permissions based off of their role. Jun 7, 2013 at 13:28
0

Hello Dakshina Murthy I think you can refer this link and most probably It would help you out http://drupalmodules.com/category/User+management?page=6

1
  • hai.i couldn't find any module for my requirement. can you tell me which module will satisfies my requirement?
    – Moorthy
    Apr 16, 2011 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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