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" ] } }
]
}
}
Comment | File | Size | Author |
---|---|---|---|
#1 | 2012-12-18_12-56-26.png | 14.42 KB | kalabro |
#1 | 2012-12-18_12-55-01.png | 21.66 KB | kalabro |
Comments
Comment #1
kalabroCould you please enable debug mode for Rules (admin/config/workflow/rules/settings) and show us what happens:
Comment #2
jjpost CreditAttribution: jjpost commentedThis is what the log says:
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.
Comment #3
kalabroTry to add “Save entity” action and check “Force saving immediately” option.
Comment #3.0
kalabroa little extra markup
Comment #4
TR CreditAttribution: TR commentedNo further information provided.