diff --git a/app/controllers/cms_entry_points_controller.rb b/app/controllers/cms_entry_points_controller.rb index c8845db85..68ffeb718 100644 --- a/app/controllers/cms_entry_points_controller.rb +++ b/app/controllers/cms_entry_points_controller.rb @@ -12,6 +12,12 @@ def record_ga? = false def home_page policy = policy(:cms_portal) + if session[:email_evaluator_link].present? + email_evaluator_link = session[:email_evaluator_link] + session.delete(:email_evaluator_link) + return email_evaluator_link + end + return support_root_path if policy.access_proc_ops_portal? return engagement_root_path if policy.access_e_and_o_portal? return support_case_statistics_path if policy.access_statistics? diff --git a/app/services/create_user.rb b/app/services/create_user.rb index eedc5e13c..cb41fb14e 100644 --- a/app/services/create_user.rb +++ b/app/services/create_user.rb @@ -27,6 +27,7 @@ def call update_user! if current_user update_support_agent! if current_support_agent.present? + update_support_evaluator! if current_support_evaluator.present? if member_of_a_supported_establishment? || internal_staff_member? current_user || create_user! @@ -77,6 +78,15 @@ def update_support_agent! track_event("CreateUser/AgentUpdated", agent_id: current_support_agent.id) end + def current_support_evaluator + Support::Evaluator.where("lower(email) = lower(?)", email) + end + + def update_support_evaluator! + current_support_evaluator.update!(dsi_uid: user_id) + track_event("CreateUser/EvaluatorUpdated", evaluator_email: email) + end + # @return [User, nil] def current_user User.find_by(dfe_sign_in_uid: user_id) diff --git a/spec/services/specify/create_user_spec.rb b/spec/services/specify/create_user_spec.rb index 6fb72a2b6..5662892bb 100644 --- a/spec/services/specify/create_user_spec.rb +++ b/spec/services/specify/create_user_spec.rb @@ -196,5 +196,16 @@ end end end + + context "when there's a support evaluator" do + let(:dfe_sign_in_uid) { "evaluator-uid" } + let(:email) { "evaluator@example.com" } + let!(:support_evaluator) { create(:support_evaluator, email: email.downcase) } + + it "updates the support evaluator to have the dsi uid of the user" do + service.call + expect(support_evaluator.reload.dsi_uid).to eq(dfe_sign_in_uid) + end + end end end