Reputation: 1
My code implementation
def ability
Ability.new(current_user, current_organization)
end
inside Ability:
def can_assign_this_responsible(teams_list)
can :assign_this_responsible, Hr::Employee do |responsible|
(responsible.not_regular? && teams_list.include?(responsible.hr_team)) || owner_of_organization(responsible)
end
end
Execution:
def can_assign_responsible
ability.can?(:assign_this_responsible, @user)
end
the problem is that even though the condition
(responsible.not_regular? && teams_list.include?(responsible.hr_team)) || owner_of_organization(responsible) => false
returns false
the call
ability.can?(:assign_this_responsible, @user) => true
return true which makes no sense
I am looking for a solution to this problem, why is this happening?
I'm using cancancan 2.0.0
Additional debugging of condition:
(responsible.not_regular? && teams_list.include?(responsible.hr_team)) || owner_of_organization(responsible)
responsible.not_regular? => false
teams_list.include?(responsible.hr_team) => true
owner_of_organization(responsible) => false
Upvotes: 0
Views: 25