I am trying to use Rules to automatically add a user to a role when that user becomes a member of an OG group.
This seems to be very easy:

Event:
User has become a group member

Condition:
none

Action
Add user role
Parameter: User: [account], Roles: Member

It just does not work, user does not get added to the role.

However, if I debug the [account] value in the same rule after "add user role", I can see the role is added:

roles (Array, 2 elements)
2 (String, 18 characters ) authenticated user
5 (String, 6 characters ) Member

But it is not saved. If I look under "people" afterwards, the role member is not assigned to the user that gets approved to be a OG member.

If I change [account] to [site:current_user], the current user gets added to the role, and that works fine. So something goes wrong with [account], it does not gets saved.

This is the export of my rule:

{ "add_to_role" : {
    "LABEL" : "Add User to role after OG",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "devel", "og" ],
    "ON" : [ "og_user_insert" ],
    "IF" : [ { "data_is" : { "data" : [ "og-membership:state" ], "value" : "1" } } ],
    "DO" : [
      { "user_add_role" : { "account" : [ "account" ], "roles" : { "value" : { "5" : "5" } } } },
      { "devel_debug" : { "value" : [ "account" ] } }
    ]
  }
}
CommentFileSizeAuthor
#1 2012-12-18_12-56-26.png14.42 KBkalabro
#1 2012-12-18_12-55-01.png21.66 KBkalabro
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kalabro’s picture

Status: Active » Postponed (maintainer needs more info)
FileSize
21.66 KB
14.42 KB

Could you please enable debug mode for Rules (admin/config/workflow/rules/settings) and show us what happens:
2012-12-18_12-55-01.png

jjpost’s picture

This is what the log says:

Rules debug information:
"
 
Reacting on event User has become a group member.
0 ms Reacting on event User has become a group member.
5.077 ms Evaluating conditions of rule Add User to role after OG. [edit]
6.123 ms The condition data_is evaluated to TRUE [edit]
6.133 ms AND evaluated to TRUE.
"
 
Rule Add User to role after OG fires. [edit]
0 ms Rule Add User to role after OG fires.
0.163 ms Evaluating the action user_add_role. [edit]
2.196 ms Rule Add User to role after OG has fired.
8.371 ms Saved account of type user.
47.363 ms Finished reacting on event User has become a group member

Like I said, It changes the user account (debug field account has the new role in it), but does not save it, or what I think: overwrites it later with the original data.
BTW this is the only active rule, so no other rule or anything will undo the work of this rule.

kalabro’s picture

Try to add “Save entity” action and check “Force saving immediately” option.

kalabro’s picture

Issue summary: View changes

a little extra markup

TR’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

No further information provided.