diff --git a/app/controllers/case_contacts_controller.rb b/app/controllers/case_contacts_controller.rb
index 5f4275ea82..3780e15d7d 100644
--- a/app/controllers/case_contacts_controller.rb
+++ b/app/controllers/case_contacts_controller.rb
@@ -6,7 +6,8 @@ class CaseContactsController < ApplicationController
before_action :set_case_contact, only: %i[edit destroy]
before_action :set_contact_types, only: %i[new edit create]
before_action :require_organization!
- after_action :verify_authorized, except: %i[leave]
+ before_action :set_volunteer, only: %i[impersonate_and_edit]
+ after_action :verify_authorized, except: %i[leave impersonate_and_edit]
def index
load_case_contacts
@@ -61,6 +62,12 @@ def leave
redirect_back_to_referer(fallback_location: case_contacts_path)
end
+ def impersonate_and_edit
+ impersonate_user(@volunteer)
+
+ redirect_to casa_case_path(params[:casa_case_id])
+ end
+
private
def update_or_create_additional_expense(all_ae_params, cc)
@@ -98,4 +105,8 @@ def build_draft_case_ids(params, casa_cases)
[]
end
+
+ def set_volunteer
+ @volunteer = Volunteer.find(params[:creator_id])
+ end
end
diff --git a/app/views/case_contacts/_case_contact.html.erb b/app/views/case_contacts/_case_contact.html.erb
index c3324c52a4..baf8203b67 100644
--- a/app/views/case_contacts/_case_contact.html.erb
+++ b/app/views/case_contacts/_case_contact.html.erb
@@ -38,8 +38,14 @@
<% if Pundit.policy(current_user, contact).update? %>
<%= render "case_contacts/followup", contact: contact, followup: contact.requested_followup %>
- <%= link_to edit_case_contact_path(contact), class: "text-danger", data: { turbo: false } do %>
- Edit
+ <% if (current_user.casa_admin? || current_user.supervisor?) && contact.creator&.volunteer? && contact.creator != current_user %>
+ <%= link_to case_contacts_impersonate_and_edit_path(creator_id: contact.creator.id, casa_case_id: @casa_case), class: "text-danger", data: { turbo: false } do %>
+ View/Edit
+ <% end %>
+ <% else %>
+ <%= link_to edit_case_contact_path(contact), class: "text-danger", data: { turbo: false } do %>
+ Edit
+ <% end %>
<% end %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index d3d77105b7..c34d217e9d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -85,6 +85,7 @@
# Feature flag for new case contact table design
get "case_contacts/new_design", to: "case_contacts/case_contacts_new_design#index"
post "case_contacts/new_design/datatable", to: "case_contacts/case_contacts_new_design#datatable", as: "datatable_case_contacts_new_design"
+ get "case_contacts/impersonate_and_edit", to: "case_contacts#impersonate_and_edit"
resources :case_contacts, except: %i[create update show], concerns: %i[with_datatable] do
member do
post :restore
diff --git a/spec/views/case_contacts/case_contact.html.erb_spec.rb b/spec/views/case_contacts/case_contact.html.erb_spec.rb
index 924ad29a09..d62210f8c7 100644
--- a/spec/views/case_contacts/case_contact.html.erb_spec.rb
+++ b/spec/views/case_contacts/case_contact.html.erb_spec.rb
@@ -73,17 +73,16 @@
enable_pundit(view, admin)
allow(view).to receive(:current_user).and_return(admin)
end
-
context "occurred_at is before the last day of the month in the quarter that the case contact was created" do
let(:case_contact) { build_stubbed(:case_contact, creator: volunteer) }
let(:case_contact2) { build_stubbed(:case_contact, deleted_at: Time.current, creator: volunteer) }
- it "shows edit button" do
+ it "shows view/edit button" do
assign :case_contact, case_contact
assign :casa_cases, [case_contact.casa_case]
render(partial: "case_contacts/case_contact", locals: {contact: case_contact})
- expect(rendered).to have_link(nil, href: "/case_contacts/#{case_contact.id}/edit")
+ expect(rendered).to have_link(nil, href: "/case_contacts/impersonate_and_edit?creator_id=#{case_contact.creator.id}")
end
it "shows make reminder button" do