Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi can’t get rules to publish content for a specific role. I had it working but had to revert the site and lost all my work in Rules. I recreated the rule but now content is not publishing for that specific desired role.
Event has the value after saving content
Elements has User has roles with node: author
Actions has Publish content node
Comments
Comment #1
Itangalo CreditAttribution: Itangalo commentedI don't get the line "Elements has User has roles with node: author". Could you explain the steps of the rule further, or paste an export of it?
Comment #2
Road Kill CreditAttribution: Road Kill commentedHi Itangalo, what I am trying to do is make all posts for users that have a role called specialist to post automatically. I created the following rule below but it has not effect. Is this a a bug or have I done something wrong.
Thank you for your time.
{ "rules_specialist_publish" : {
"LABEL" : "Specialist Publish",
"PLUGIN" : "reaction rule",
"TAGS" : [ "Specialist" ],
"REQUIRES" : [ "rules" ],
"ON" : [ "node_insert" ],
"IF" : [
{ "NOT user_has_role" : { "account" : [ "node:author" ], "roles" : { "value" : { "19" : "19" } } } }
],
"DO" : [ { "node_publish" : { "node" : [ "node" ] } } ]
}
}
Comment #3
Itangalo CreditAttribution: Itangalo commentedRoad Kill: It seems there is a "not" too much in your export – is seems the rule publishes nodes if they are written by users who don't have role number 19. Inspect the condition, and see if the "negate" checkbox is selected.
Comment #4
Road Kill CreditAttribution: Road Kill commentedThe negate box was not checked. I tested it with the negate box checked but nodes created by the Specialst Role still do not publish automatically.
Comment #5
Road Kill CreditAttribution: Road Kill commentedThe way I understand this is that the Event should be (After saving new content)
/********************************************************************/
The Condition should be the Role that is saving the content (User has role(s))
User has role(s)
Parameter: User: [node:author], Roles: Specialist
/********************************************************************/
The Actions should be (Publish content)
Publish content
Parameter: Content: [node]
This structure above should make all nodes created by authors who have the specialist Role publish immediately after saving, correct or incorrect.
The funny thing is when a user with the specialist role save's a new node it is not published.
Comment #6
Itangalo CreditAttribution: Itangalo commented@Road Kill: Then I suggest turning on the Rules debug information, so you can see more clearly what's happening step by step. It could be a bug in the check-for-roles condition, but it could also be errors in the configuration.
Note 1: When trying to import the code you pasted in #2, I get a reaction rule where the "negate" checkbox is checked for the condition.
Note 2: It may also help to chenge the configuration in the condition so "any" of the selected roles must mach, not "all". (This shouldn't make any difference, but it might be that Rules checks if all the user's role matches all the selected roles – not just if the user has (at least) all the selected roles.
Comment #7
Road Kill CreditAttribution: Road Kill commentedHi Itangalo here is the debugging info when I published a new node with the Specialist Role
Type rules
Date Tuesday, October 4, 2011 - 14:39
User SPECIALIST
Location http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overla...
Referrer http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overlay
Message Rules debug information:
" Reacting on event After saving new content.
0 ms Reacting on event After saving new content.
35.706 ms Evaluating conditions of rule Specialist Publish. [edit]
41.999 ms The condition user_has_role evaluated to TRUE [edit]
42.026 ms AND evaluated to TRUE.
" Rule Specialist Publish fires. [edit]
0 ms Rule Specialist Publish fires.
0.243 ms Evaluating the action node_publish. [edit]
20.911 ms Rule Specialist Publish has fired.
63.089 ms Saved node of type node.
1729.363 ms Finished reacting on event After saving new content.
Severity notice
Comment #8
Road Kill CreditAttribution: Road Kill commentedThis test was run with match roles any and negate on
Type rules
Date Tuesday, October 4, 2011 - 14:58
User SPECIALIST
Location http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overla...
Referrer http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overlay
Message Rules debug information:
" Reacting on event After saving new content.
0 ms Reacting on event After saving new content.
37.622 ms Evaluating conditions of rule Specialist Publish. [edit]
42.418 ms The condition user_has_role evaluated to TRUE [edit]
42.441 ms AND evaluated to FALSE.
42.487 ms Finished reacting on event After saving new content.
Severity notice
Comment #9
Road Kill CreditAttribution: Road Kill commentedThis test was run with match roles any and negate off
rules
Date Tuesday, October 4, 2011 - 15:02
User SPECIALIST
Location http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overla...
Referrer http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overlay
Message Rules debug information:
" Reacting on event After saving new content.
0 ms Reacting on event After saving new content.
55.797 ms Evaluating conditions of rule Specialist Publish. [edit]
61.206 ms The condition user_has_role evaluated to TRUE [edit]
61.231 ms AND evaluated to TRUE.
" Rule Specialist Publish fires. [edit]
0 ms Rule Specialist Publish fires.
0.225 ms Evaluating the action node_publish. [edit]
22.165 ms Rule Specialist Publish has fired.
83.553 ms Saved node of type node.
1105.761 ms Finished reacting on event After saving new content.
Severity notice
Comment #10
Road Kill CreditAttribution: Road Kill commentedThis test was run with match roles all and negate on
Type rules
Date Tuesday, October 4, 2011 - 15:05
User SPECIALIST
Location http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overla...
Referrer http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overlay
Message Rules debug information:
" Reacting on event After saving new content.
0 ms Reacting on event After saving new content.
39.604 ms Evaluating conditions of rule Specialist Publish. [edit]
45.58 ms The condition user_has_role evaluated to TRUE [edit]
45.606 ms AND evaluated to FALSE.
45.656 ms Finished reacting on event After saving new content.
Severity notice
Comment #11
Road Kill CreditAttribution: Road Kill commentedThis test was run with match roles all and negate off
Type rules
Date Tuesday, October 4, 2011 - 15:08
User SPECIALIST
Location http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overla...
Referrer http://spice4life.co.za.plesk13.wadns.net/node/add/article?render=overlay
Message Rules debug information:
" Reacting on event After saving new content.
0 ms Reacting on event After saving new content.
29.953 ms Evaluating conditions of rule Specialist Publish. [edit]
34.467 ms The condition user_has_role evaluated to TRUE [edit]
34.491 ms AND evaluated to TRUE.
" Rule Specialist Publish fires. [edit]
0 ms Rule Specialist Publish fires.
0.232 ms Evaluating the action node_publish. [edit]
15.441 ms Rule Specialist Publish has fired.
50.067 ms Saved node of type node.
329.014 ms Finished reacting on event After saving new content.
Severity notice
Comment #12
Road Kill CreditAttribution: Road Kill commentedHi Itangalo you would like I can give you access to the backend of the site if that will help. I hope the above will help.
Comment #13
Itangalo CreditAttribution: Itangalo commented@Road Kill – sorry, can't get involved with individual sites.
Maybe this link will provide some more help on how to use Rules: http://nodeone.se/node/984
Comment #14
Road Kill CreditAttribution: Road Kill commentedNo worries just thought it might help if you had access.
Comment #15
sebish CreditAttribution: sebish commentedI confirm the "User has roles" with "node: author" has a problem. I tried a bunch of different configuration to unpublish a node (called Event) if the author has the role anonymous. The log says "The condition user_has_role evaluated to FALSE" but it should say TRUE as I created the node using an Anonymous account.. Here is the report:
7.807 ms Evaluating conditions of rule Notify Event Created. [edit]
8.812 ms The condition user_has_role evaluated to FALSE [edit]
8.823 ms AND evaluated to FALSE.
8.843 ms Finished reacting on event After saving new content.
This used to work in a previous version of Rules however.
Comment #16
Road Kill CreditAttribution: Road Kill commentedHi Sebish thought I was going made because I had it working but had to revert the website and in doing so lost all my work in Rules.
I set up the rule again and this time no joy. I am not sure now but I think out of desperation I am going to uninstall flush cache update database and reinstall.
Comment #17
Itangalo CreditAttribution: Itangalo commentedThis sounds like a bug to me.
I'm a bit surprised, since I haven't seen any bugs of this kind before, but it is difficult to argue against empirical evidence. :-)
Comment #18
GBurg CreditAttribution: GBurg commentedI also tried to use User has Role on Node:Author checking if they where anonymous users, but it couldn't pass the test...
I solved it by checking if User has role on the Node:Author whether it is a registered user, and negate it. This works (finally) and I hope I have helped someone with my finding.
Anyway, a clean solution would be great.
My setup was:
And now is:
Comment #19
arlingtonvoicellc CreditAttribution: arlingtonvoicellc commentedThis solution (#18) worked for me. I didn't ever think to negate them.
Comment #20
markabur CreditAttribution: markabur commented#18 works for me too. If the condition is "node:author = Anonymous", my rule doesn't trigger, but if the condition is "NOT node:author = Authenticated" then it does.
Comment #21
Itangalo CreditAttribution: Itangalo commentedI don't think there is any user object for the anonymous user, and so any attempts to load roles from the user object would fail.
A check on "data is empty" for node:author should probably do the trick.
Comment #22
lyricnz CreditAttribution: lyricnz commentedYeah, I ran into another issue with author=FALSE for anonymous users today : #1835050: Create entity fails when the user is anonymous. Maybe it would be better to provide drupal_anonymous_user() earlier, and so remove the need for kludges further into the system? (like the one in that issue)
Comment #23
Itangalo CreditAttribution: Itangalo commentedIt seems that drupal_anonymous_user() is still missing some properties that might be expected (such as name and email), but it is worth considering IMHO.
Comment #24
jakobdo CreditAttribution: jakobdo commentedProblem still exists. #18 saved the day. :)
Comment #25
cheureul CreditAttribution: cheureul commentedHad the same issue today, so I applied the #18 fix.
I also tried to detect anonymous author using the "data is empty" check but I had no chance making it work...
Comment #26
TR CreditAttribution: TR commentedComments #18-#25 talk about a different issue than the original post. Namely, they talk about the fact that 'anonymous' users IN DRUPAL don't have a user object associated with them - thus, they have to be treated differently than other users. IMO, that's a DRUPAL problem, not a Rules problem - this affects many parts of Drupal and is very annoying. The above comments show a way to deal with that.
As for the original problem described by the original poster and discussed in comments #1-#17, here is an export of a Rule that does exactly what was asked for. The only differences between this and what was posted in #2 are 1) on my system, the 'specialist' role has id=6, and 2) I removed the 'NOT' in the condition, which was clearly wrong.
This works with the current version of Rules (7.x-2.11). Because we can't change previous versions (this is how Drupal works - fixed-point releases are immutable), and because this works in the current version, there's nothing to fix here anymore.