Hi, I would like to add a rule to test whether a node is protected and, if so, unlock it for some user roles.

This documentation makes mention of an event called "Content is going to be viewed", offered by the Protected Node rules extension. I believe I could use that in a rule to test the protect status of the node and then unlock it for given roles. I cannot use the event "Content is viewed", because the password challenge page at example.com/protected-node comes before the actual node in question.

I have the Protected Node rules extension enabled but unfortunately "Content is going to be viewed" is not offered as an event option. Has this been deprecated? Any ideas why this option is unavailable?

Thanks in advance.

Comments

stuwat created an issue. See original summary.

Grimreaper’s picture

Status: Active » Postponed

Hello stuwat,

Thanks for reporting this.

Effectively "Content is going to be viewed" no more exists. I think it was in D6.

Using "Content is viewed" works for me. Here is the rule I used to test.

{ "rules_test_protected_node" : {
    "LABEL" : "test protected node",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "protected_node_rules", "rules" ],
    "ON" : { "node_view" : [] },
    "IF" : [
      { "protected_node_rules_condition_content_is_protected" : { "node" : [ "node" ] } }
    ],
    "DO" : [ { "protected_node_rules_action_unlock" : { "node" : [ "node" ] } } ]
  }
}

Is it ok for you?

Grimreaper’s picture

Status: Postponed » Active

I think I put the issue in a wrong status.

stuwat’s picture

Thank you for your reply.

I tried your rule and it did not work for me. The event will not fire until after the user has correctly answered the password challenge and been redirected to the node page.

As a test, I created an additional action on the rule to display a system message "You are entitled to view this node". It did not appear until after the password challenge was met and the user had arrived at the node.

Because the node is protected, the user is redirected to the /protected-node page which does not trigger the "Content is viewed" event. That event only gets triggered on successful viewing of the node.

Grimreaper’s picture

Do you have other modules on your site? Especially cache/performance modules.

I have just remade a test on simplytest.me and it works, so I think there is another module which interferes with Drupal's bootstrap.

stuwat’s picture

My suspicion is that Panels may be the culprit here. I disabled the node template provided by Panels and that had no effect, but that's no guarantee that Panels isn't still invoking itself somehow.

Varnish was disabled and all other caching turned off.

Grimreaper’s picture

Status: Active » Postponed (maintainer needs more info)

Ok,

Maybe try the event "Drupal is initializing".

stuwat’s picture

Yes, I did try "Drupal is initializing", but did not then have access to the node in the rule's conditions and actions, so could not unlock it. If I am mistaken about that or if there is another way, please let me know.

stuwat’s picture

I resorted to using the bypass permission for the roles I wanted to access the protected nodes. That's fine for now, but in the future there may be other node types that I want protected and that should not be accessible by those roles (unless of course they have the password). I was hoping Rules would solve that problem for me.

As a suggestion, it would be nice to have password bypass permissions for different node types in the future. That would satisfy my requirement without the use of Rules.

Grimreaper’s picture

Hello,

Can you provide the list of modules you use?

Because as mentioned in comment 2, it works with Rules on a fresh Drupal install.

stuwat’s picture

Hi Grimreaper. The site is built from a Panopoly distribution, which includes Panels and a whole lot more.

Grimreaper’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Hello,

I close the issue because it is more than one year without activity.

Feel free to reopen if needed.