Display Item visibility depends on role (Assign from Path)
kenorb - October 14, 2008 - 14:26
| Project: | Auto Assign Role |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | cyberswat |
| Status: | won't fix |
Description
I've rewrote following permission functions:
function _autoassignrole_path_access($rid = NULL) {
$roles = user_roles(TRUE); // receive all roles
return array_key_exists($rid, $roles) ? user_access("access {$roles[$rid]} registration") : TRUE;
}
/**
* Implementation of hook_perm().
* @return array
*/
function autoassignrole_perm() {
$perm = array('administer autoassignrole');
$result = db_query("SELECT rid FROM {autoassignrole_page}"); // get all used roles by autoassignrole
if ($result) {
while ($db_role = db_fetch_object($result)) { // get db records...
$db_roles[$db_role->rid] = $db_role->rid; // ...and save them to the array
}
$roles = user_roles(TRUE); // receive all roles
foreach ($db_roles as $role) { // for each used role...
if (array_key_exists($role,$roles)) { // .. check if role exist...
$perm[] = "access {$roles[$role]} registration"; // ...and add the new permission
}
}
}
return $perm;
}Then you will see on Permission page additional access separately for each enabled registration form.
So you can disable creation user's link on anonymous page and enable it for specified role.
It's a good solution, but it will make a little more complicated module with the permissions.

#1
I've forgotten. And you need to add 'access arguments' item for main menu item:
case 0:$items[$r->path] = array(
'title' => check_plain($r->title),
'page arguments' => array($r->rid),
'page callback' => 'autoassignrole_path',
'access callback' => '_autoassignrole_path_access',
'access arguments' => array($r->rid),
'file' => 'autoassignrole-path.inc',
'weight' => $r->weight
);
And for tabs as well:
// tabs on user registration pagescase 1:
$items['user/'. $r->path] = array(
'title' => check_plain($r->title),
'page arguments' => array($r->rid),
'page callback' => 'autoassignrole_path',
'access callback' => '_autoassignrole_path_access',
'access arguments' => array($r->rid),
'file' => 'autoassignrole-path.inc',
'type' => MENU_LOCAL_TASK,
'weight' => $r->weight
);
break;
After this patch clear cache is needed to do it working (admin/settings/performance).
#2
#3
Please generate this (and all of your code submissions) as a standard patch http://drupal.org/patch/create
#4
#5
But I think it no point to commit that, because you can always have possibility to separate your menus to different blocks and then you can set role permission to specified blocks.
http://drupal.org/node/227418
But this patch can be useful for some people which they can't separate their menu easly, so they can make access by specified form.
#6
Closing this out due to lack of movement.
#7
Hello,
I am in the same situation as described above.
Roles:
role_1
role_2
role_3
administrator
Assign from path:
user/register/role_1
user/register/role_2
user/register/role_3
As it works now, paths work fine for anonymous users. But I also want the
administrator role to be able to use the user/register/role_x to create new
users. I think the solution above with permission control is a great way to
solve this issue.
#8
perarnet:
You can try to make some patch, because I've got AAR so much patched, so it will be difficult for me to patch it for the latest version.
#9
I don't think administrators should be able to create users in this fashion.