CanCanCan with Rails 5 and defining abilities in the database -
i'm using cancancan in rails 5 app (5.1.3) , defining abilities in database. structure defining abilities -
person --- role --- permission --- actions. 1 person can have many roles, each role maps many permissions , each permission has many actions. permissionsrole , actionspermission both have has_and_belongs_to_many relation.
in actions table, i've defined fields name, resource_name, , is_object.
this in ability.rb -
person.roles.first.permissions.each |permission| permission.actions.each |action| if action.is_object can action.name.to_sym, action.resource_name.constantize else can action.name.to_sym, action.resource_name.to_sym end end end
this seems working fine if is_object false ie if it's controller without model. i'm trying use show records of object , i'm getting accessdenied error though associations have been setup properly.
does know how fix this?
edit : had overwritten default_scope model in question causing access denied records. when remove works, see records, instead of records user can access. there anyway overwrite default scope , record authorizations working?
Comments
Post a Comment