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

Itangalo’s picture

Component: Rules Core » Rules Engine
Status: Active » Postponed (maintainer needs more info)

I 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?

Road Kill’s picture

Hi 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" ] } } ]
}
}

Itangalo’s picture

Priority: Critical » Normal

Road 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.

Road Kill’s picture

The 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.

Road Kill’s picture

The 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.

Itangalo’s picture

@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.

Road Kill’s picture

Hi 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

Road Kill’s picture

This 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

Road Kill’s picture

This 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

Road Kill’s picture

This 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

Road Kill’s picture

This 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

Road Kill’s picture

Hi 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.

Itangalo’s picture

@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

Road Kill’s picture

No worries just thought it might help if you had access.

sebish’s picture

I 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.

Road Kill’s picture

Hi 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.

Itangalo’s picture

Title: Publish for user role not working » Checking roles on node:author seems to fail
Category: support » bug
Status: Postponed (maintainer needs more info) » Active

This 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. :-)

GBurg’s picture

I 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:

{ "rules_test" : {
    "LABEL" : "test",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "devel" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "user_has_role" : { "account" : [ "node:author" ], "roles" : { "value" : { "1" : "1" } } } }
    ],
    "DO" : [
      { "devel_debug" : { "value" : [ "node:author:roles" ] } },
      { "drupal_message" : { "message" : "test bericht - [node:author:roles:0] -  [node:author:roles:1] [node:author:roles:2] [node:author:roles:3]" } }
    ]
  }
}

And now is:

{ "rules_test" : {
    "LABEL" : "test",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "devel" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "NOT user_has_role" : { "account" : [ "node:author" ], "roles" : { "value" : { "2" : "2" } } } }
    ],
    "DO" : [
      { "devel_debug" : { "value" : [ "node:author:roles" ] } },
      { "drupal_message" : { "message" : "test bericht - [node:author:roles:0] -  [node:author:roles:1] [node:author:roles:2] [node:author:roles:3]" } }
    ]
  }
}
arlingtonvoicellc’s picture

This solution (#18) worked for me. I didn't ever think to negate them.

markabur’s picture

Component: Rules Engine » Rules Core

#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.

Itangalo’s picture

I 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.

lyricnz’s picture

Yeah, 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)

Itangalo’s picture

It 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.

jakobdo’s picture

Issue summary: View changes

Problem still exists. #18 saved the day. :)

cheureul’s picture

Had 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...

TR’s picture

Status: Active » Closed (works as designed)

Comments #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.

{ "rules_specialist_publish" : {
    "LABEL" : "Specialist Publish",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Specialist" ],
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert" : [] },
    "IF" : [
      { "user_has_role" : { "account" : [ "node:author" ], "roles" : { "value" : { "6" : "6" } } } }
    ],
    "DO" : [ { "node_publish" : { "node" : [ "node" ] } } ]
  }
}

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.