I'm trying to create a rule which creates a piece of content whenever a user account is created. I've managed to do this fine, but whenever I try to specify that the rule should only be triggered when the user account being created is of a certain role, the rule rule stops working.

When I edit the condition "User has role(s)" I get the option of specifying an argument: "registered user" or "acting user". I've tried both, and neither work. My guess is that "registered user" means the user which has been created, and the "acting user" is the user that's done the creating.

Any tips on getting this to work?

Comments

fago’s picture

Component: Rules Core » Rules Engine

hm, please try again with the latest development snapshot of rules.

fago’s picture

>My guess is that "registered user" means the user which has been created, and the "acting user" is the user that's done the creating.

right

rowdypostman’s picture

Any resolution on this? I'm having the same issue. Tried using latest dev snapshot and beta3.

fago’s picture

Title: Problem with getting rule to trigger » roles of newly created users not accessible
Version: 6.x-1.0-beta3 » 6.x-1.x-dev
Category: support » bug

ok, so probably $user looks somehow different. Perhaps we can sanitize it before invoking rules.

asak’s picture

subscribing. I'm having this problem when trying to use Auto Assign Role - the role is assigned, the condition is for that role, but the actions isn't executed. it does work when setting the condition to Authenticated role. I thought this might mean that the problem is with AAR - but seems this is where the solution is...

rlnorthcutt’s picture

I am having the same issue with Adding a role on New Account Creation... it no worky...

However, when I change the rule to "User Page Has Been Viewed", it does work (because the site goes to the user profile by default). So, when the account is created, the user is thrown to the user profile and this triggers the additional role.

Would be cleaner to have the New Account rule to work :)

fago’s picture

Category: bug » support

I just gave this a test in it's working fine in both cases. Make sure you assign the role to the "registered user", not the acting one. Furthmore there might be conflicts with modules like AAR. If a module comes and overwrites the values without the new role right after we have saved the roles, we can't do anything about that.

asak’s picture

I'm using Content Profile as well, and set some fields for display on registration, and then set the rule to invoke on "New content has been created" - and everything works... similar solution to what's offered by rlnorthcutt...

mitchell’s picture

Title: roles of newly created users not accessible » Assigning roles to newly created users
Status: Active » Fixed

Solution provided in #8.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

capellic’s picture

Category: support » feature
Status: Closed (fixed) » Active

Boy, I wish I had found this earlier! But it didn't occur to me until the end of my sleuthing that there was a problem between Auto Assign Roles and Rules. I would like to see a more straight-forward solution to this in the future (the solutions used in #6 and #8 will do for now), so I am changing this to feature request and active.

Below are the gory details of my R&D session should anybody find them useful.

I am using the Auto Assign Role (http://drupal.org/project/autoassignrole) module during registration.

I have a condition and action setup so that on user creation, if they are assigned to the role Newbie, they get referred to another URL.

I have had trouble getting this working and I feel that there is a race condition.

I first had a lot of trouble figuring out if I should be using "Acting User" or "Registered User" because I am not sure about the state of the user when they are creating their own account as an anonymous user -- Or I should say immediately after creating their account. I realized "Registered User" is the way to go.

I then selected Newbie as the role to be affected. I added a simple redirect action to send people to Google.com. Instead of newly created accounts with role Newbie being sent to Google, they were sent to the website's home page. I checked the user's role and it was properly set to Newbie.

Well, yes, the role of the user is Newbie, but the user isn't technically logged in, so I then added Anonymous User in addition to Newbie and was sure that "Match against any or all of the selected roles" was set to "any". That didn't work either. I checked the role for the user and it again was set to Newbie.

I then added Authenticated User to the list of roles so now I have Authenticated User, Anonymous User and Newbie with "any" for the matching. My user, upon registration, was sent to Google.com! Huh, so I needed to have Authenticated User checked as a role? That's incredibly odd considering that my users are initially blocked when registering and are only allowed to login when an admin has approved their account. I then went to look at the user's account and there was no role assigned -- it should have been Newbie. And this is why I think there is a race condition.

Rules is firing off *before* Auto Assign Role, therefore there is no role for the user and the condition is not met. Then Auto Assign Role fires and sets the role, but by then it is too late.

In the case where my rule's conditions are being met is where the registered user is meeting the broad definition of a "Authenticated User" and being redirected. Since the redirection is occurring before Auto Assign Role can do it's thing, the role of Newbie is never set.

So then I thought I would go into the system table and change the weight of the rules module -- but I saw that autoassignrole.module has a weight of 0 and rules.module has a weight of 20. Odd, very odd.

capellic’s picture

It occurs to me that my problem is that the reason I am having such a difficult time is because my user is blocked. Sure, now it sounds obvious, but I was thinking that the user may have been in some odd state during registration that would allow Rules to override this. I guess not.

mitchell’s picture

Category: feature » support
Status: Active » Closed (fixed)

Please do not reopen issues and change their category. This is not likely to get reviewed properly. Please open a separate issue.