Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/controllers/case_contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def index

@pagy, @filtered_case_contacts = pagy(@filterrific.find)
case_contacts = CaseContact.case_hash_from_cases(@filtered_case_contacts)
if current_user.volunteer?
case_contacts = case_contacts.slice(*current_user.casa_cases.pluck(:id))
end
case_contacts = case_contacts.select { |k, _v| k == params[:casa_case_id].to_i } if params[:casa_case_id].present?

@presenter = CaseContactPresenter.new(case_contacts)
Expand Down Expand Up @@ -82,7 +85,8 @@ def update_or_create_additional_expense(all_ae_params, cc)
id = ae_params[:id]
current = AdditionalExpense.find_by(id: id)
if current
current.assign_attributes(other_expense_amount: ae_params[:other_expense_amount], other_expenses_describe: ae_params[:other_expenses_describe])
current.assign_attributes(other_expense_amount: ae_params[:other_expense_amount],
other_expenses_describe: ae_params[:other_expenses_describe])
save_or_add_error(current, cc)
else
create_new_exp = cc.additional_expenses.build(ae_params)
Expand Down Expand Up @@ -125,7 +129,8 @@ def set_case_contact
def build_draft_case_ids(params, casa_cases)
# Use case(s) from params if present
return params[:draft_case_ids] if params[:draft_case_ids].present?
return casa_cases.where(id: params.dig(:case_contact, :casa_case_id)).pluck(:id) if params.dig(:case_contact, :casa_case_id).present?
return casa_cases.where(id: params.dig(:case_contact, :casa_case_id)).pluck(:id) if params.dig(:case_contact,
:casa_case_id).present?
return [casa_cases.first.id] if casa_cases.count == 1

[]
Expand Down
2 changes: 1 addition & 1 deletion noop
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Thu Mar 20 09:44:23 PDT 2025
Sun Mar 30 20:08:28 PDT 2025
20 changes: 20 additions & 0 deletions spec/requests/case_contacts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "/case_contacts", type: :request do
Expand Down Expand Up @@ -35,6 +37,24 @@
expect(page).not_to include(past_contact.creator.display_name)
end
end

context "when logged in as a volunteer" do
let(:assigned_case) { create(:casa_case, :with_one_case_assignment, casa_org: organization) }
let(:unassigned_case) { casa_case }
let(:volunteer) { assigned_case.assigned_volunteers.first }
let!(:assigned_case_contact) { create(:case_contact, casa_case: assigned_case, creator: volunteer) }
let!(:unassigned_case_contact) do
create(:case_contact, casa_case: unassigned_case, creator: volunteer, duration_minutes: 180)
end

before { sign_in volunteer }

it "returns only currently assigned cases" do
page = request.parsed_body.to_html
expect(page).to include("60 minutes")
expect(page).not_to include("3 hours")
end
end
end

describe "GET /new" do
Expand Down
Loading