davydovanton / kan

Simple, functional authorization library and role management for ruby
http://www.kanrb.org
MIT License
232 stars 12 forks source link

Add alias registration #38

Closed ilyasovd closed 5 years ago

ilyasovd commented 5 years ago

Reference to https://github.com/davydovanton/kan/issues/33

davydovanton commented 5 years ago

@ilyasovd thanks for PR. Could you rebase from current master branch? (I dropped support for <2.3 ruby versions and added 2.6)

davydovanton commented 5 years ago

Also, I think I found a bug in this solution (correct me please if I'm wrong). If we register alias and after that register ability for alias we will call alias ability instead new ability.

Example:


class Post::Abilities
  include Kan::Abilities

  register(:edit) { |_, _| true }
  register_alias(:correct, 'edit')

  register(:correct) { |_, _| false }
end

abilities = Kan::Application.new(
  post: Post::Abilities.new
)

abilities['post.correct'].call(current_user, post) # => true

WDYT? Could you also add tests for this case?

ilyasovd commented 5 years ago

@davydovanton yeah, I agree with you. Do you think that it should return the last ability result or raising an error that name has already taken? I think the last ability result will be better.

ilyasovd commented 5 years ago

@davydovanton I've rebased request but Travis CI still red. Looks like ruby 2.6.2 have to be 2.6.0. :)