This might be an obvious issue for some one good with CanCanCan, but I am finding it hard to wrap my head around it.
I got an application that has many roles around it (campus_rep, campus_manager, operations_manager, admin etc). They all have acces to an 'admin' section but will see different menu options based on their role.
For example:
- Admin can manage all 'Customers'
- Operations managers can manage customers for the schools they belong to
Extract of ability.rb
if user.role == 'admin'
can :manage, JobApplication
elsif user.role == 'operations_manager'
can :manage, JobApplication, school_id: user.schools.map(&:id)
elsif ser.role == 'campus_rep'
# blah but nothing to do with JobApplication
end
I have been thinking to use if can? :manage, Customer
but then even 'operations_managers' don't pass it which makes sense.
What is the recommended way to get out of a similar situation?
I tried if can? :manage, Customer.new(school: current_user.schools.first)
which kinda works but looks not alright.
I though of doing some thing like adding can :see, JobApplication
to both 'admin' and 'operations_managers' and then doing the check like if can? :see, JobApplication
.
What is recommended? Is there any better way? Hopefully there is...
Also highly appreciate any advice in the matter