I have inherited resources working in my controllers and I use cancan for authorization. However, I have a problem writing required abilities.
I can display particular order in 2 ways:
/profile/123/orders/321
/store/456/orders/321
in controller:
class OrdersController < ApplicationController
inherit_resources
belongs_to :profile, :store, :optional => true
load_and_authorize_resource
...
end
Roles are: user (has_one :profile in Model) and manager (has_one :store in Model)
The requirements (in words) are:
- Manager can display order(s) in context of (that belongs to) his store.
- Manager cannot display order(s) in context of any user's profile (Access should be denied)
- User can display order(s) in context of his profile
- User cannot display order(s) in context of any store (denied)
I couldn't meet these requirements, maybe I should load resource in special way or actually in 2 ways? Intuition says to me, that access to orders should be based on the access to parent resource in both cases. Thank You for help.