1

I am trying to set up a rule (using the Rules module) that will email a user if their user record has been updated by an admin.

It is easy to generate an email when their profile is updated, but I can't see any way to make a Rules condition that the logged in user has a specific role.

3
  • 1
    add condition user has a role Nov 11, 2015 at 12:35
  • But that relates to the user record being edited, not the user doing the editing.
    – James
    Nov 11, 2015 at 14:11
  • Hey @James , did you ever get this to work? Oct 23, 2017 at 18:30

1 Answer 1

1

Interesting Rules question! Have a look at this rule (in Rules export format, just import it in your site and check the results of it):

{ "rules_notify_user_about_profile_updates_by_an_admin" : {
    "LABEL" : "Notify user about profile updates by an admin",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "user_update" : [] },
    "IF" : [
      { "entity_is_of_type" : { "entity" : [ "site:current-user" ], "type" : "user" } },
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "3" : "3" } }
        }
      }
    ],
    "DO" : [ { "drupal_message" : { "message" : "Bingo ... it seems to work ..." } } ]
  }
}

To verify if it does what you're looking for, perform these steps:

  • use a userid with role "administrator" (which I assume to be role id = 3, if not adapt that to the role id you're using for admins).
  • edit any existing user profile.

If you get a drupal "message" like "Bingo ... it seems to work ...", then adapt the Rules "Action" with that "easy to generate eMail" you seem to already have (or know about).

Of course, if you have another userid available that has permission to edit user profiles, but without admin permission, then that should NOT result in such a "Bingo ...".

For anyone wondering what the actual missing piece of your puzzle was (= the "clue"): adding the condition with entity_is_of_type makes the user_has_role available. That role is related to the user performing the profile update (the "logged in user") ... which of course is different from the account being updated ...

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.