diff --git a/app/models/legacy_appeal.rb b/app/models/legacy_appeal.rb index fc4c69f5604..56e2889fb43 100644 --- a/app/models/legacy_appeal.rb +++ b/app/models/legacy_appeal.rb @@ -936,14 +936,16 @@ def paper_case? end def attorney_case_review - # # Created at date will be nil if there is no decass record created for this appeal yet + # Created at date will be nil if there is no decass record created for this appeal yet return unless vacols_case_review&.created_at - AttorneyCaseReview.find_by(task_id: "#{vacols_id}-#{VacolsHelper.day_only_str(vacols_case_review.created_at)}") + task_id = "#{vacols_id}-#{VacolsHelper.day_only_str(vacols_case_review.created_at)}" + + @attorney_case_review ||= AttorneyCaseReview.find_by(task_id: task_id) end def vacols_case_review - VACOLS::CaseAssignment.latest_task_for_appeal(vacols_id) + @vacols_case_review ||= VACOLS::CaseAssignment.latest_task_for_appeal(vacols_id) end def death_dismissal! @@ -983,6 +985,22 @@ def latest_appeal_event TaskEvent.new(version: versions.last) if versions.any? end + # Hacky logic to determine if an acting judge should see judge actions or attorney actions on a case assigned to them + # See https://github.com/department-of-veterans-affairs/caseflow/issues/14886 for details + def assigned_to_acting_judge_as_judge?(acting_judge) + # First try to determine role on the case by inspecting the attorney_case_review, if there is one present. + if attorney_case_review.present? + return false if attorney_case_review.attorney_id == acting_judge.id + + return true if attorney_case_review.reviewing_judge_id == acting_judge.id + end + + # In case an attorney case review does not exist in caseflow or if this acting judge was neither the judge or + # attorney listed in the review, check to see if a decision has already been written for the appeal. If so, assume + # this appeal is assigned to the acting judge as a judge task as a best guess + vacols_case_review.valid_document_id? + end + private def soc_eligible_for_opt_in?(receipt_date:, covid_flag: false) diff --git a/app/models/queues/legacy_work_queue.rb b/app/models/queues/legacy_work_queue.rb index 266114b4273..e4eb7481793 100644 --- a/app/models/queues/legacy_work_queue.rb +++ b/app/models/queues/legacy_work_queue.rb @@ -31,7 +31,7 @@ def tasks_from_vacols_tasks(vacols_tasks, user = nil) # If the user is a judge they are only assigned JudgeLegacyTasks # If the user is an acting judge, assume any case that already has a decision doc is assigned to them as a judge if user&.vacols_roles&.first&.downcase == "judge" || - (user&.acting_judge_in_vacols? && appeal.vacols_case_review.valid_document_id?) + (user&.acting_judge_in_vacols? && appeal.assigned_to_acting_judge_as_judge?(user)) task_class = JudgeLegacyTask end diff --git a/spec/models/legacy_appeal_spec.rb b/spec/models/legacy_appeal_spec.rb index 8d96c8ce87c..00c25ccd784 100644 --- a/spec/models/legacy_appeal_spec.rb +++ b/spec/models/legacy_appeal_spec.rb @@ -2993,4 +2993,63 @@ it_behaves_like "latest informal hearing presentation task" end + + describe "#assigned_to_acting_judge_as_judge?" do + shared_examples "assumes user is the decision drafter" do + it { is_expected.to be false } + end + + shared_examples "assumes user is the decision signer" do + it { is_expected.to be true } + end + + let(:acting_judge) { create(:user, :with_vacols_acting_judge_record) } + let!(:appeal) { create(:legacy_appeal, vacols_case: create(:case, :assigned, user: acting_judge)) } + + subject { appeal.assigned_to_acting_judge_as_judge?(acting_judge) } + + context "when the attorney review process has happened outside of caseflow" do + context "when a decision has not been written for the case" do + it_behaves_like "assumes user is the decision drafter" + end + + context "when a decision has been written for the case" do + before { VACOLS::Decass.where(defolder: appeal.vacols_id).update_all(dedocid: "02255-00000002") } + + it_behaves_like "assumes user is the decision signer" + end + end + + context "when the attorney review process has happened within caseflow" do + let(:created_at) { VACOLS::Decass.where(defolder: appeal.vacols_id).first.deadtim } + let!(:case_review) { create(:attorney_case_review, task_id: "#{appeal.vacols_id}-#{created_at}") } + + context "when the user does not match the judge or attorney on the case review" do + it_behaves_like "assumes user is the decision drafter" + + it "falls back to check the presence of a decision document" do + expect_any_instance_of(VACOLS::CaseAssignment).to receive(:valid_document_id?).once + subject + end + end + + context "when the user matches the attorney on the case review" do + before do + case_review.update!(attorney: acting_judge) + expect_any_instance_of(VACOLS::CaseAssignment).not_to receive(:valid_document_id?) + end + + it_behaves_like "assumes user is the decision drafter" + end + + context "when the user matches the judge on the case review" do + before do + case_review.update!(reviewing_judge: acting_judge) + expect_any_instance_of(VACOLS::CaseAssignment).not_to receive(:valid_document_id?) + end + + it_behaves_like "assumes user is the decision signer" + end + end + end end