chaps-io / access-granted

Multi-role and whitelist based authorization gem for Rails (and not only Rails!)
MIT License
774 stars 41 forks source link

Object and Subobject #44

Closed sadjehwty closed 6 years ago

sadjehwty commented 6 years ago

How can I define rule for a subobject extends object rule. es.

can :delete, Object do |obj, user|
  post.author_id == user.id
end
can :delete, Subobject do |sub, user|
  can? :delete, sub.parent && sub.id>3
end
pokonski commented 6 years ago

Hi! If I understood you correctly, then: there is no inheritance between can blocks and Access Granted has no special handling for inheritance of Ruby classes.

You can DRY it up by extracting common logic into methods and use that in blocks