james2m / canard

Makes role based authorization in Rails really simple. Wraps CanCan and RoleModel up with a smattering of syntactic sugar, some generators and scopes.
MIT License
125 stars 28 forks source link

Allow one role to inherit abilities of other roles #23

Closed hoenth closed 9 years ago

hoenth commented 9 years ago

Though one can assign multiple roles to user, to try to keep the abilities DRY, we would prefer to get the same affect when assigning a single role to a user. For example, if I had the following roles

Instead of making sure that the Supervisor user also was assigned to all of the preceding roles, I would like to define the Supervisor's abilities so that it inherited from all of the preceding abilities.

I am thinking that at the top of an abilities definition, I include a call like:

includes_abilities_of :user, :writer, :editor, :manager

Then add the following to the Ability class:

  def includes_abilities_of(*other_roles)
    other_roles.each { |other_role| append_abilities(other_role) }
  end

If this makes sense to you, i am happy to issue a pull request

james2m commented 9 years ago

@hoenth It's come up before, so happy to look at a pull request with tests. :)

james2m commented 9 years ago

Released in 0.4.3