Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

action aliases used in definition of abilities #946

Open
drventure opened this Issue · 1 comment

1 participant

@drventure

I've run into a small issue where a dev on the team used an action alias in the abilities.rb file to define the abilities for a particular user. In this case, it was :index defined as an alias for :read (pretty standard stuff).

However, from what I can tell, CanCan searches for aliases in one direction but not the other, so in this case, when a controller checked can? :read, Object, it missed the alias.

I'd think that the can? function should check in both directions for an alias (ie alias to value, and values to their aliases).

I'll investigate and see if I can make that mod myself and post a pull request.

@drventure

In looking at it, added a call to aliases_for_actions in the expand_actions method appears to do the trick.

Ie

def expand_actions(actions)
  actions.map do |action|
    aliased_actions[action] ? [action, *expand_actions(aliased_actions[action])] + aliases_for_action(action) : [action] + aliases_for_action(action)
  end.flatten
end

In other words,when expanding the actions, expand them in both dirs. You'll end up with duplicates in the list, but that doesn't matter, (and could be resolved with a .uniq anyway)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.