2

I would like to use Rules to notify all administrator users of new comments that have been posted to the site.

I can get as far as getting the notifications working for all comments, but I would like to set it for notifications to just comments by non-administrators. Administrators will then not be notified for their own responses to comments.

Any hints?

Note: I want to do this so that I just have to specify the admin role only, as many new roles will be added that are non-admin roles. This way I do not have to update the rule every time a new role is added by site admins.

3

What you are trying to do is pretty straightforward. I suspect that you have a Rule that is active and has the following:

On event After publishing a comment

(no condition)

DO

Send an email to user (or whatever you want to be your notification method; it doesn't really matter)

What you need to do is add a condition by clicking on the respective option. In the "Condition to add" option, you need to select: "User has role(s)" and press Next.

In the next page, select "Published Comment Author" in the User option and select all the roles of your site except for the Admin role. Leave the rest unchanged.

Now your admins should be receiving notifications for comments from non-admins only.

  • Is there any way to do this so that I just have to specify the admin role only, as many new roles will be added that are non-admin roles? this way I do not have to update the rule every time a new role is added by site admins. – user842 May 30 '11 at 17:00
  • Thanks so much for your help. figured out the last bit. Just needed to choose the admin role and negate the condition. – user842 May 30 '11 at 22:43
  • Yes, just noticed your comment. This is a common practice in Rules: you can either select some options or select the rest of the options and negate. Glad that I could help :D – F1234k May 31 '11 at 7:59
0

The previous (and accepted) answer is a pretty good solution to answer this question. But it does have some challenges:

  • the question states that "all administrator users" should be notified, which is not exactly the same as sending a notification to a user (as suggested in the accepted answer).
  • if new roles get added afterwards, you'd have to also update (not forget ...) the custom rule.

Therefor, I think an improved version of the answer is to use a rule, which looks like so (in Rules export format):

{ "rules_notify_admins_about_new_comments" : {
    "LABEL" : "Notify admins about new comments",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "comment" ],
    "ON" : { "comment_insert" : [] },
    "IF" : [
      { "NOT user_has_role" : {
          "account" : [ "comment:author" ],
          "roles" : { "value" : { "3" : "3" } }
        }
      }
    ],
    "DO" : [
      { "mail_to_users_of_role" : {
          "roles" : { "value" : { "3" : "3" } },
          "subject" : "A new comment was posted for node with id [comment:node:nid] ...",
          "message" : "This is to inform you that a new comment was added to the node with id [comment:node:nid] ... The comment can be found at [comment:url]"
        }
      }
    ]
  }
}

Some details about this rule:

  • Rules Event: After saving a new comment.
  • Rules Condition: the author of the comment does NOT (!!!) have the role "administrator".
  • Rules Action: send mail to all users of a role, with role = administrator.

Use the Rules UI to import this rule in your own site, no tuning of any kind needed to make it work as requested in this question, except that you may want to refine the eMail title and eMail body to fit your own needs.

Think about it: it doesn't matter what happens after you enable this rule, i.e. new users are granted the admin role also, or new roles are added (as in the "Note" in your question). In all such future updates to a site, the business logic as requested in the question will continue to function with zero maintenance required to this custom rule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy