0

I want to be able to add and remove a role to a user via a simple click of a button on almost any node. (Specifically the plan is to allow a user to give themselves a role that would give them extra editing powers, but so that they can remove it when generally browsing the site so all the editing options don't clog up the UI).

The best method I could think of for this is to have two nodes, and set up a rule so visiting these nodes added or removed the user role. I could then create simple menu links that linked to these nodes.

Essentially what I have set up is one rule which goes:

Event: Content is Viewed
Condition: Node is of alias - node url
Action: Add user role - Edit Powers

This rule works fine. When the node is visited the role is added to the user. However the reverse rule doesn't work despite being nearly identical to the other. It reads:

Event: Content is viewed
Conidtion: Node is of alias - node url
Action: Remove user role - Edit Powers

However visiting this URL doesn't remove the user role. The question here is two-fold.

a) Why would the rule not be working, and why can't it remove a role from the user?

b) Is this a really complex way of achieving something that might be quite simple? At the moment I assume this rule is effectively being checked when any user visits any page, which I'm sure isn't great from a resource point of view - but I couldn't think of an easier way to do it with flags etc. So please do advise if there is an easier way.

Thanks in advance for any help.

3 Answers 3

0

Try creating a condition that the user have the role, before trying to remove it. Also, you could look into Rules Link - you may be able to add it to a custom Profile Page, allowing the user to access and change their settings via My Account - at least from a UI standpoint it might make more sense.

0

There are two ways I can think of doing this.

  1. Install and Enable Roles Assign Module. Once this module is enabled the user can go to his account and then assign roles(A subset selected by the admin) or remove them from his account.

  2. Install Flag module. Create one flag for each of the roles. This will give you Add/remove flag options and your can integrate it with Flag actions to assign or remove the Roles.

1
  • I had considered the flags options. The reason I dismissed it - is to my knowledge you can't set, effectively, a global flag. In other words if you made the flag appear on nodes it would only change on a specific node if flagged, not all nodes. If a flag could be added as a sort of generic button to blocks that would be great, but don't think you can do that.
    – gdhp
    Commented Jun 24, 2014 at 14:48
0

In the condition "Node is of alias", what have you entered? It might be wrong. Post it here to help you if you want.

2
  • I posted the actual relative node url, in this case: node/119 & node/120. Thanks for your help.
    – gdhp
    Commented Jun 24, 2014 at 14:46
  • Download this module [drupal.org/project/pathrules] and use that for your condition. I think this is your problem. You are providing the node path instead of the node alias. The module above will provide a new condition that checks the path instead of the path alias. Waiting for your feedback.
    – TheMGamer
    Commented Jun 24, 2014 at 16:48

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.