I'm building an event calendar that accepts submissions from anonymous users - but before the submitted events are published, they have to be approved by a moderator.
I have a event content type, with publish set to default. Anonymous users have the right to create events, but can only view published content. The problem is that after an event is submitted, users get "You are not authorized to access this page.", which makes sense.
So, I've installed Rules (7.x-2.0-rc1) and created the following rule, which checks to see if the user has submitted content and has the anonymous role:
{ "rules_redirect_anonymous_users_after_submitting_event" : {
"LABEL" : "Redirect anonymous users after submitting event",
"PLUGIN" : "reaction rule",
"TAGS" : [ "anonymous", "event", "redirect" ],
"REQUIRES" : [ "rules" ],
"ON" : [ "node_insert" ],
"IF" : [
{ "user_has_role" : {
"account" : [ "site:current-user" ],
"roles" : { "value" : { "1" : "1" } }
}
}
],
"DO" : [ { "redirect" : { "url" : "\/thank-you", "force" : 0 } } ]
}
}
Unfortunately, it doesn't work. The user is not redirected and still sees the "not authorized" page. I've tried forcing the redirect as well, but to no effect. This occurs with both the rc1 and current dev versions of Rules.
There are two similar reported issues where it seems the issue has been resolved - but I'm still experiencing it w/node create.
http://drupal.org/node/931260
http://drupal.org/node/1024306#comment-4070132
Comments
Comment #1
mkelly commentedWorkaround:
Setting a negated condition of "role = authenticated user" seems to solve the problem & the redirect works.
{ "rules_redirect_anonymous_users_after_submitting_event" : {
"LABEL" : "Redirect anonymous users after submitting event",
"PLUGIN" : "reaction rule",
"TAGS" : [ "anonymous", "event", "redirect" ],
"REQUIRES" : [ "rules" ],
"ON" : [ "node_insert" ],
"IF" : [
{ "NOT user_has_role" : {
"account" : [ "site:current-user" ],
"roles" : { "value" : { "2" : "2" } }
}
}
],
"DO" : [ { "redirect" : { "url" : "\/thank-you", "destination" : 1 } } ]
}
}
Comment #2
Taxoman commentedhm, odd... (subscribing)
Comment #3
Taxoman commentedComment #4
bayousoft commentedI can report the same issue trying to set a condition for an anonymous user role. Negating authenticated user role also worked for me.
Comment #5
jramby commentedI have the same issue here, I'm in 7.x-2.0 and negated authenticated user doesn't even work for me. I also tryed for anonymous users in 7.x-2.1 but seems to be broken.
I tested on a rule that triggers on the event "After a new content has been saved" with the condition "User has a role of anonymous user" and an action of redirecting to the user/login page via data selector "site:login-url". Also tryed with "NOT authenticated user" condition.
Am I missing something?
thx.
Comment #6
jramby commentedHi all,
I found my problem about this. I had another configured rule about redirecting after saving a new content without condition. So it overwritten the redirection I created.
thx!
Comment #7
Taxoman commentedok, can the others reporting this kind of behaviour please double-check their setup against @jramby's findings in #6, and report back here? Is this actually a bug?
Comment #8
Golem07 commentedI am having the same problem with rules 2.1. No redirect works for this rule:
{ "rules_redirect_role" : {
"LABEL" : "Redirect",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "user_login" ],
"IF" : [
{ "user_has_role" : {
"account" : [ "site:current-user" ],
"roles" : { "value" : { "4" : "4" } }
}
}
],
"DO" : [ { "redirect" : { "url" : "administration\u002Ftest" } } ]
}
}
I have no other redirection rule and not authenticated user action did not help either.
Comment #9
tr commentedFeel free to reopen if this is still a problem in the current version of Rules.