Skip to content

Commit 62186d8

Browse files
committed
WIP
1 parent 75ba45e commit 62186d8

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

app/controllers/case_contacts_controller.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ def index
2020
) || return
2121

2222
@pagy, @filtered_case_contacts = pagy(@filterrific.find)
23-
case_contacts = CaseContact.case_hash_from_cases(@filtered_case_contacts)
24-
case_contacts = case_contacts.select { |k, _v| current_user.casa_cases.pluck(:id).include?(k) } if current_user.volunteer?
25-
case_contacts = case_contacts.select { |k, _v| k == params[:casa_case_id].to_i } if params[:casa_case_id].present?
23+
24+
casa_case_id_to_case_contacts = CaseContact.case_hash_from_cases(@filtered_case_contacts)
25+
if params[:casa_case_id].present?
26+
casa_case_id_to_case_contacts = casa_case_id_to_case_contacts.select { |k, _v| k == params[:casa_case_id].to_i }
27+
end
28+
if current_user.volunteer?
29+
current_user_casa_case_ids = current_user.casa_cases.pluck(:id)
30+
casa_case_id_to_case_contacts = casa_case_id_to_case_contacts.select { |case_contact_id, _cases| current_user_casa_case_ids.include?(case_contact_id) }
31+
end
2632

27-
@presenter = CaseContactPresenter.new(case_contacts)
33+
@presenter = CaseContactPresenter.new(casa_case_id_to_case_contacts)
2834
end
2935

3036
def drafts

spec/requests/casa_cases_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "rails_helper"
2-
2+
# hi
33
RSpec.describe "/casa_cases", type: :request do
44
let(:date_in_care) { Date.today }
55
let(:organization) { build(:casa_org) }

spec/requests/case_contacts_spec.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "rails_helper"
2-
2+
# hi
33
RSpec.describe "/case_contacts", type: :request do
44
let(:organization) { build(:casa_org) }
55
let(:admin) { create(:casa_admin, casa_org: organization) }
@@ -21,21 +21,24 @@
2121

2222
it { is_expected.to have_http_status(:success) }
2323

24-
it "returns all case contacts" do
25-
page = request.parsed_body.to_html
26-
expect(page).to include(past_contact.creator.display_name, recent_contact.creator.display_name)
27-
end
28-
29-
context "with filters applied" do
30-
let(:filterrific) { {occurred_starting_at: 1.week.ago} }
31-
24+
context "when logged in as an admin" do
3225
it "returns all case contacts" do
3326
page = request.parsed_body.to_html
34-
expect(page).to include(recent_contact.creator.display_name)
35-
expect(page).not_to include(past_contact.creator.display_name)
27+
expect(page).to include(past_contact.creator.display_name, recent_contact.creator.display_name)
28+
end
29+
30+
context "with filters applied" do
31+
let(:filterrific) { {occurred_starting_at: 1.week.ago} }
32+
33+
it "returns all case contacts" do
34+
page = request.parsed_body.to_html
35+
expect(page).to include(recent_contact.creator.display_name)
36+
expect(page).not_to include(past_contact.creator.display_name)
37+
end
3638
end
3739
end
3840

41+
3942
context "when logged in as a volunteer" do
4043
let(:assigned_case) { create(:casa_case, :with_one_case_assignment, casa_org: organization) }
4144
let(:unassigned_case) { casa_case }

0 commit comments

Comments
 (0)