davydovanton / kan

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

PoC: plugins #34

Open davydovanton opened 5 years ago

davydovanton commented 5 years ago

We can use kan not only roles and user. Also, same interface is good for working with permissions, experiments and etc.

That's why we can start use plugin system for helping use kan with other areas.

I have no idea how it should look like, but we can start discussion and find what the best way for this.

My general points around plugin system:

  1. Easy integrate outside core code (plugin container can help here, I think)
  2. Ability to use different plugins with different instances of library

Also, we can move callbacks and notifications to plugins too

API ideas

Kan::Plugin.register(:roles) { Kan::Plugin::Roles }
Kan::Plugin.register(:custom) { CustomKanPlugin }

class Post::Abilities
  include Kan::Abilities
  extend Kan::Plugin[:roles]

  register('read') { |_, _| true }
  register('edit') { |user, post| user.id == post.user_id }
  register('delete') { |_, _| false }
end
davydovanton commented 5 years ago

cc @IvanShamatov @apotonick