Hello,
I installed the module Auto Assign Role for user account creation. I set it up so that users can choose their own profile role when creating account. It works! When I go to admin and check USERS ... the roles are being assigned as hoped.

I am trying to wrap my mind around Drupal - very new. I am trying to figure out HOW to target specific user roles in order to create specific content for the roles. I though I could for example use a db query ... if role, then else and not fuss with sessions. Looking at users table in the db, it looks as those the role 'rid' is not stored there.

Sorry for dumb questions ... how are others accomplishing this?

Do I now create content pages somehow are grant access to those pages through permissions? I think I am getting it ... I have a PHp mind ... and this is UI oriented.

Thank you for your help!

Odisey

Comments

adshill’s picture

In order to provide specific content to specific roles you need some level of access control. You can get this from modules such as ACL: http://drupal.org/project/acl

This with other modules can give you quite detailed viewing access to each individual role. You may also want to look at taxonomy access depending on how detailed your requirements are:

http://drupal.org/project/taxonomy_access
http://drupal.org/project/tac_lite

There are a number of other access control modules - I'm just providing ones I have used before.

Hope that's helpful,

Adam

odisey’s picture

Thank you Adam!

After I installed the auto assign roles module, as mentioned it worked. Because it worked, Drupal is referencing some variable in the DB to identify a user as being assigned to some specific role. Therefore, knowing 'what' Drupal is referencing will enable me to 'join' this reference to provide additional variables for individual users based on their role. For example, I can create account variables for individuals based on their role. Customers(role) can create and edit personal customer accounts, and businesses(role) can create and edit business accounts - including products, etc.

Does anyone 'know' 'what' Drupal is referencing to assign individuals roles when using this module?

Thank you!

Odisey

adshill’s picture

Hi Odisey,

I don't have any knowledge of the specific module you reference but I would strongly suggest you log a support request on the module specific issue page. This will make the question available to the people who wrote the module and will most likely end up in a quicker and more reliable answer. Also it looks like this module is very well maintained.

Please see the issue queue for this module here:

http://drupal.org/project/issues/autoassignrole?status=All&categories=All

Hope this helps you find an answer/solution. All the best,

Adam

cyberswat’s picture

cyberswat’s picture

Hi Odisey,

Here's some additional information that may help now that I've found this thread.

Drupal stores the reference between users and roles in the {user_roles} table. Roles themselves are stored in the {role} table. Here's one snippet of code that will let you know if a user is in a specific role:

<?php
global $user;
$sql = "SELECT ur.rid FROM {users_roles} ur WHERE ur.rid = (SELECT rid FROM {role} r WHERE r.name = '%s') AND  ur.uid = %d";
if ($role = db_fetch_object($sql, 'My Nifty Role', $user->uid)) {
  drupal_print_message('User has role');
}
else {
  drupal_print_message('User does not have role');
}
?>

However, most access control is done with permissions and not roles. Take a look at http://api.drupal.org/api/function/user_access/6

So rather than checking for the role, you normally check a specific permission that the role contains ... a lot of time this done in the menu system:

<?php
/**
 * Implementation of hook_menu().
 */
function user_menu() {
  $items['user/autocomplete'] = array(
    'title' => 'User autocomplete',
    'page callback' => 'user_autocomplete',
    'access callback' => 'user_access',
    'access arguments' => array('access user profiles'),
    'type' => MENU_CALLBACK,
    'file' => 'user.pages.inc',
  );
}
?>

In the above example the user can't access the user/autocomplete path unless they have the permission 'access user profiles' ... to tie that to your request, the 'access user profiles' would be a permission that makes your role unique.

Does that make more sense?