From 0edf8449c934df127b37b4c4d6d414f986e75e20 Mon Sep 17 00:00:00 2001 From: RyanEddyIC Date: Fri, 26 Jul 2024 09:05:36 -0400 Subject: [PATCH] refactor policy --- app/policies/person_policy.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/policies/person_policy.rb b/app/policies/person_policy.rb index a184f1402dc..f08e97ea950 100644 --- a/app/policies/person_policy.rb +++ b/app/policies/person_policy.rb @@ -85,16 +85,17 @@ def can_broker_modify? end def broker_agency_profile_matches? - agency_id = role.benefit_sponsors_broker_agency_profile_id + agency_id = role&.benefit_sponsors_broker_agency_profile_id family_active_broker = associated_family&.active_broker_agency_account - family_active_broker_matches = family_active_broker.present? && family_active_broker.benefit_sponsors_broker_agency_profile_id == agency_id - active_er = associated_family.primary_person&.active_employee_roles&.first employer_active_broker = active_er&.employer_profile&.active_broker_agency_account - employer_active_broker_matches = employer_active_broker.present? && employer_active_broker.benefit_sponsors_broker_agency_profile_id == agency_id - family_active_broker_matches || employer_active_broker_matches + broker_matches?(family_active_broker, agency_id) || broker_matches?(employer_active_broker, agency_id) + end + + def broker_matches?(broker, agency_id) + broker.present? && broker.benefit_sponsors_broker_agency_profile_id == agency_id end def role