I am trying to satisfy the following requirements using CanCan:
If a deal is assigned to 1-many networks, the user can read the deal if s/he is a member of any of the assigned networks.
If a deal is not assigned to any network, it can be viewed by any registered user regardless of their network memberships.
If a deal is not assigned to a network, but the deal is marked member_only = true, the user can read the deal if s/he is a member of any network.If a deal is not assigned to a network and marked member_only = false, any registered user can read the deal.Guests (i.e., not a user) cannot read any deals
I think I have 2-4 covered with the following:
if current_user.persisted?
can :read, Deal, current_user.networks.empty? ? { member_only: false } : {}
end
But, I am unsure how to further restrict deals assigned to a network. Is this possible with CanCan. If so, suggestions on how? Thanks.