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.

CommentFileSizeAuthor
#4 autoassignrole.module.patch3.64 KBkenorb

Comments

kenorb’s picture

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 pages
      case 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).

cyberswat’s picture

Assigned: Unassigned » cyberswat
cyberswat’s picture

Status: Active » Postponed (maintainer needs more info)

Please generate this (and all of your code submissions) as a standard patch http://drupal.org/patch/create

kenorb’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new3.64 KB
kenorb’s picture

Status: Needs review » Postponed

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.

cyberswat’s picture

Status: Postponed » Closed (fixed)

Closing this out due to lack of movement.

perarnet’s picture

Status: Closed (fixed) » Active

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.

kenorb’s picture

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.

cyberswat’s picture

Status: Active » Closed (won't fix)

I don't think administrators should be able to create users in this fashion.

JayKayAu’s picture

Hi cyberswat,

Would you be able to explain why you don't think admins should be able to create users?

I'm trying to find a solution to a problem where "Staff" users are able to sign up "Customer" users based on supplied information. This is for a physical store where staff are literally speaking face-to-face with customers at the checkout while using a computer with the website open on it.

I would normally just create an ordinary CCK Content Type to store the customer data, except we want to allow these customers to log into the site as well in future.

Is there an alternate solution that you might suggest if it's genuinely not a good idea to do this through autoassignrole?

remaye’s picture

I suscribe.
I'm desperately looking for a solution (with AAR or any other module) to allow users with Administrator role to create new accounts for new users assigning specific role to them.

Administrator users can create accounts if "access user profiles" and "administer users" permissions are enabled for that role, but are not allowed to choose role for this accounts, why ? And why is this so hard to achieve ?

I really don't understand why "administrators shouldn't be able to create users in this fashion"...
unless there is indeed any other way to achieve this in a more appropriate manner ?
Thanks for any clue...