From 85e7298b2696b882a67e7ebe5986eaad0b95acff Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Fri, 27 Sep 2024 11:42:05 +0100 Subject: [PATCH] Update policies to use team where possible This updates the policies to filter the objects on the teams directly rather than from the programme, which is removing the concept of programmes being attached to teams. --- app/policies/batch_policy.rb | 6 +++--- app/policies/consent_form_policy.rb | 2 +- app/policies/consent_policy.rb | 2 +- app/policies/patient_session_policy.rb | 2 +- app/policies/session_policy.rb | 2 +- app/policies/vaccination_record_policy.rb | 2 +- app/policies/vaccine_policy.rb | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/policies/batch_policy.rb b/app/policies/batch_policy.rb index d9eeb37c4..50a7420ce 100644 --- a/app/policies/batch_policy.rb +++ b/app/policies/batch_policy.rb @@ -8,9 +8,9 @@ def initialize(user, scope) end def resolve - @scope.joins(vaccine: { programmes: :team }).where( - teams: { - id: @user.teams.ids + @scope.joins(vaccine: :programmes).where( + programmes: { + team: @user.teams } ) end diff --git a/app/policies/consent_form_policy.rb b/app/policies/consent_form_policy.rb index 71e8ddc5a..b5f99caeb 100644 --- a/app/policies/consent_form_policy.rb +++ b/app/policies/consent_form_policy.rb @@ -8,7 +8,7 @@ def initialize(user, scope) end def resolve - @scope.joins(:programme).where(programme: { team_id: @user.teams.ids }) + @scope.joins(:session).where(session: { team: @user.teams }) end end end diff --git a/app/policies/consent_policy.rb b/app/policies/consent_policy.rb index ec30f4ec1..4fb34174c 100644 --- a/app/policies/consent_policy.rb +++ b/app/policies/consent_policy.rb @@ -8,7 +8,7 @@ def initialize(user, scope) end def resolve - @scope.joins(:programme).where(programme: { team_id: @user.teams.ids }) + @scope.joins(:programme).where(programme: { team: @user.teams }) end end end diff --git a/app/policies/patient_session_policy.rb b/app/policies/patient_session_policy.rb index c0156ad9c..8435fbdea 100644 --- a/app/policies/patient_session_policy.rb +++ b/app/policies/patient_session_policy.rb @@ -8,7 +8,7 @@ def initialize(user, scope) end def resolve - @scope.joins(:session).where(session: { team_id: @user.teams.ids }) + @scope.joins(:session).where(session: { team: @user.teams }) end end end diff --git a/app/policies/session_policy.rb b/app/policies/session_policy.rb index 0a1d36a9a..5cb90d378 100644 --- a/app/policies/session_policy.rb +++ b/app/policies/session_policy.rb @@ -8,7 +8,7 @@ def initialize(user, scope) end def resolve - @scope.where(team_id: @user.teams.ids) + @scope.where(team: @user.teams) end end end diff --git a/app/policies/vaccination_record_policy.rb b/app/policies/vaccination_record_policy.rb index 147e135e9..c4d1a1621 100644 --- a/app/policies/vaccination_record_policy.rb +++ b/app/policies/vaccination_record_policy.rb @@ -8,7 +8,7 @@ def initialize(user, scope) end def resolve - @scope.joins(:programme).where(programme: { team_id: @user.teams.ids }) + @scope.joins(:session).where(session: { team: @user.teams }) end end end diff --git a/app/policies/vaccine_policy.rb b/app/policies/vaccine_policy.rb index cbd78261c..8424fdc73 100644 --- a/app/policies/vaccine_policy.rb +++ b/app/policies/vaccine_policy.rb @@ -8,7 +8,7 @@ def initialize(user, scope) end def resolve - @scope.joins(:programmes).where(programmes: { team_id: @user.teams.ids }) + @scope.joins(:programmes).where(programmes: { team: @user.teams }) end end end