Skip to content

Commit

Permalink
Creates subclasses of JudgeTask for two actions (#8072)
Browse files Browse the repository at this point in the history
Connects #8033

### Description
Creates subclasses of JudgeTask for two actions.

### Acceptance Criteria
- [ ] Code compiles correctly
  • Loading branch information
tomas-nava authored and va-bot committed Dec 3, 2018
1 parent 7ef20ba commit 82f9d37
Show file tree
Hide file tree
Showing 23 changed files with 170 additions and 49 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ client/yarn-error.log
/reports/*
!/reports/.keep

# Ignore vim swap files
# Ignore vim swap and tag files
*.swp
tags

# Ignore hidden files
.*
Expand All @@ -48,4 +49,4 @@ ci-bin/circle_docker_container/instant*
docker-bin/oracle_libs/*
oracle_libs/*

config/build_version.yml
config/build_version.yml
2 changes: 1 addition & 1 deletion app/controllers/idt/api/v1/appeals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def tasks_assigned_to_user
if feature_enabled?(:idt_ama_appeals)
tasks += Task.where(assigned_to: user).where.not(status: [:completed, :on_hold])
end
tasks.reject { |task| task.action == "assign" }
tasks.reject { |task| task.action == "assign" || task.is_a?(JudgeAssignTask) }
end

def role
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class TasksController < ApplicationController
AttorneyTask: AttorneyTask,
GenericTask: GenericTask,
QualityReviewTask: QualityReviewTask,
JudgeTask: JudgeTask,
JudgeTask: JudgeAssignTask,
JudgeAssignTask: JudgeAssignTask,
ScheduleHearingTask: ScheduleHearingTask,
MailTask: MailTask,
InformalHearingPresentationTask: InformalHearingPresentationTask
Expand Down
2 changes: 1 addition & 1 deletion app/models/appeal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def attorney_case_reviews
end

def reviewing_judge_name
task = tasks.where(type: "JudgeTask").order(:created_at).last
task = tasks.order(:created_at).select { |t| t.is_a?(JudgeTask) }.last
task ? task.assigned_to.try(:full_name) : ""
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/taskable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module Taskable
extend ActiveSupport::Concern

def assigned_attorney
tasks.select { |t| t.class == AttorneyTask }.first.try(:assigned_to)
tasks.select { |t| t.is_a?(AttorneyTask) }.first.try(:assigned_to)
end

def assigned_judge
tasks.select { |t| t.class == JudgeTask }.first.try(:assigned_to)
tasks.select { |t| t.is_a?(JudgeTask) }.first.try(:assigned_to)
end
end
5 changes: 4 additions & 1 deletion app/models/distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def validate_judge_has_no_pending_distributions

def judge_has_no_unassigned_cases
pending_statuses = [Constants.TASK_STATUSES.assigned, Constants.TASK_STATUSES.in_progress]
return false if JudgeTask.where(assigned_to: judge, action: "assign", status: pending_statuses).any?
assigned_tasks = judge.tasks.select do |t|
((t.is_a?(JudgeTask) && t.action == "assign") || t.is_a?(JudgeAssignTask)) && pending_statuses.include?(t.status)
end
return false if assigned_tasks.any?

legacy_tasks = QueueRepository.tasks_for_user(judge.css_id)
legacy_tasks.none? { |task| task.assigned_to_attorney_date.nil? }
Expand Down
4 changes: 2 additions & 2 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ def assign_to_user_data

def assign_to_judge_data
{
selected: root_task.children.find { |task| task.type == JudgeTask.name }.assigned_to,
selected: root_task.children.find { |task| task.is_a?(JudgeTask) }.assigned_to,
options: users_to_options(Judge.list_all),
type: JudgeTask.name
type: JudgeAssignTask.name
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/tasks/attorney_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AttorneyTask < Task
validate :parent_attorney_child_count, on: :create

def available_actions(user)
if parent.type == JudgeTask.name && parent.assigned_to == user
if parent.is_a?(JudgeTask) && parent.assigned_to == user
return [
Constants.TASK_ACTIONS.ASSIGN_TO_ATTORNEY.to_h
]
Expand Down
11 changes: 11 additions & 0 deletions app/models/tasks/judge_assign_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class JudgeAssignTask < JudgeTask
def available_actions(_user)
[
Constants.TASK_ACTIONS.ASSIGN_TO_ATTORNEY.to_h
]
end

def label
COPY::JUDGE_ASSIGN_TASK_LABEL
end
end
14 changes: 14 additions & 0 deletions app/models/tasks/judge_review_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class JudgeReviewTask < JudgeTask
def available_actions(_user)
[
{
label: COPY::JUDGE_CHECKOUT_DISPATCH_LABEL,
value: "dispatch_decision/special_issues"
}
]
end

def label
COPY::JUDGE_REVIEW_TASK_LABEL
end
end
30 changes: 16 additions & 14 deletions app/models/tasks/judge_task.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
class JudgeTask < Task
validates :action, inclusion: { in: %w[assign review] }

include RoundRobinAssigner

def available_actions(user)
return [] if assigned_to != user

def available_actions(_user)
if action.eql? "assign"
[
Constants.TASK_ACTIONS.ASSIGN_TO_ATTORNEY.to_h
Expand All @@ -20,6 +16,10 @@ def available_actions(user)
end
end

def no_actions_available?(user)
assigned_to != user
end

def timeline_title
COPY::CASE_TIMELINE_JUDGE_TASK
end
Expand All @@ -28,23 +28,23 @@ def self.create_from_params(params, user)
new_task = super(params, user)

parent = Task.find(params[:parent_id]) if params[:parent_id]
if parent && parent.type == QualityReviewTask.name
if parent && parent.is_a?(QualityReviewTask)
parent.update!(status: :on_hold)
end

new_task
end

def self.modify_params(params)
super(params.merge(action: "assign"))
super(params.merge(type: JudgeAssignTask.name))
end

def self.verify_user_can_assign!(user)
QualityReview.singleton.user_has_access?(user) || super(user)
end

def when_child_task_completed
update!(action: :review)
update!(type: JudgeReviewTask.name)
super
end

Expand Down Expand Up @@ -78,12 +78,14 @@ def self.assign_ramp_judge_tasks(dry_run: false, batch_size: 10)
def self.assign_judge_tasks_for_root_tasks(root_tasks)
root_tasks.each do |root_task|
Rails.logger.info("Assigning judge task for appeal #{root_task.appeal.id}")
task = create!(appeal: root_task.appeal,
parent: root_task,
appeal_type: Appeal.name,
assigned_at: Time.zone.now,
assigned_to: next_assignee,
action: "assign")

task = JudgeAssignTask.create!(
appeal: root_task.appeal,
parent: root_task,
appeal_type: Appeal.name,
assigned_at: Time.zone.now,
assigned_to: next_assignee
)
Rails.logger.info("Assigned judge task with task id #{task.id} to #{task.assigned_to.css_id}")
end
end
Expand Down
7 changes: 5 additions & 2 deletions client/COPY.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,16 @@
"CASE_TIMELINE_NOD_PENDING": "Notice of disagreement pending",
"CASE_TIMELINE_JUDGE_TASK": "Decision signed by judge",
"CASE_TIMELINE_ATTORNEY_TASK": "Decision drafted by attorney",

"DECISION_ISSUE_MODAL_TITLE": "Describe what the Veteran is appealing and what you decided.",
"DECISION_ISSUE_MODAL_SUB_TITLE": "You can also add additional decisions to better address the Veteran's concerns or situation.",
"DECISION_ISSUE_MODAL_DESCRIPTION": "Description",
"DECISION_ISSUE_MODAL_DESCRIPTION_EXAMPLE": "Ex: Increased rating for arthritis is granted with an evaluation of 90%",
"DECISION_ISSUE_MODAL_DISPOSITION": "Disposition",
"DECISION_ISSUE_MODAL_BENEFIT_TYPE": "Benefit type",

"UNAUTHORIZED_PAGE_ACCESS_MESSAGE": "You aren't authorized to use this part of Caseflow yet."
"UNAUTHORIZED_PAGE_ACCESS_MESSAGE": "You aren't authorized to use this part of Caseflow yet.",

"JUDGE_ASSIGN_TASK_LABEL": "assign",
"JUDGE_REVIEW_TASK_LABEL": "review"
}
4 changes: 2 additions & 2 deletions client/constants/TASK_ACTIONS.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"REASSIGN_TO_PERSON": { "label": "Re-assign to person", "value": "modal/reassign_to_person", "func": "assign_to_user_data" },
"RETURN_TO_JUDGE": { "label": "Return to judge", "value": "modal/assign_to_person", "func": "assign_to_judge_data" },
"SCHEDULE_VETERAN": { "label": "Schedule Veteran", "value": "modal/schedule_veteran" },
"ASSIGN_TO_ATTORNEY": { "label": "Assign to attorney", "value": "modal/assign_to_attorney" }
"ASSIGN_TO_ATTORNEY": { "label": "Assign to attorney", "value": "modal/assign_to_attorney" },
"JUDGE_CHECKOUT": { "label": "Ready for Dispatch", "value": "dispatch_decision/special_issues" }
}

2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def create_task_at_quality_review(qr_user = nil)

judge = FactoryBot.create(:user)
FactoryBot.create(:staff, :judge_role, user: judge)
judge_task = JudgeTask.create!(appeal: appeal, parent: root_task, assigned_to: judge, action: "assign")
judge_task = JudgeAssignTask.create!(appeal: appeal, parent: root_task, assigned_to: judge)

atty = FactoryBot.create(:user)
FactoryBot.create(:staff, :attorney_role, user: atty)
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/case_reviews_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
expect(task.reload.status).to eq "completed"
expect(task.completed_at).to_not eq nil
expect(task.parent.reload.status).to eq "assigned"
expect(task.parent.action).to eq "review"
expect(task.parent.type).to eq JudgeReviewTask.name

expect(bva_dispatch_task_count_before).to eq(BvaDispatchTask.count)
end
Expand Down Expand Up @@ -110,7 +110,7 @@
expect(task.reload.status).to eq "completed"
expect(task.completed_at).to_not eq nil
expect(task.parent.reload.status).to eq "assigned"
expect(task.parent.action).to eq "review"
expect(task.parent.type).to eq JudgeReviewTask.name

expect(bva_dispatch_task_count_before).to eq(BvaDispatchTask.count)
FeatureToggle.disable!(:ama_decision_issues)
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/idt/api/appeals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@

let!(:tasks) do
[
create(:ama_judge_task, assigned_to: user, appeal: ama_appeals.first, action: "assign"),
create(:ama_judge_task, assigned_to: user, appeal: ama_appeals.second, action: "review")
create(:ama_judge_task, assigned_to: user, appeal: ama_appeals.first),
create(:ama_judge_review_task, assigned_to: user, appeal: ama_appeals.second)
]
end

Expand Down
11 changes: 8 additions & 3 deletions spec/factories/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@
appeal { create(:appeal) }
end

factory :ama_judge_task, class: JudgeTask do
type JudgeTask.name
factory :ama_judge_task, class: JudgeAssignTask do
type JudgeAssignTask.name
appeal_type Appeal.name
appeal { create(:appeal) }
end

factory :ama_judge_review_task, class: JudgeReviewTask do
type JudgeReviewTask.name
appeal_type Appeal.name
action :assign
appeal { create(:appeal) }
end

Expand Down
10 changes: 5 additions & 5 deletions spec/feature/queue/case_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,13 @@
let!(:appeal2) { FactoryBot.create(:appeal) }
let!(:root_task) { create(:root_task, appeal: appeal, assigned_to: user) }
let!(:attorney_task) do
FactoryBot.create(:task, appeal: appeal, type: AttorneyTask.name, parent: root_task,
assigned_to: user, completed_at: Time.zone.now - 4.days)
create(:ama_attorney_task, appeal: appeal, parent: root_task, assigned_to: user,
completed_at: Time.zone.now - 4.days)
end
let!(:judge_task) do
FactoryBot.create(:task, appeal: appeal, type: JudgeTask.name, parent: attorney_task,
assigned_to: user, status: Constants.TASK_STATUSES.completed,
completed_at: Time.zone.now)
create(:ama_judge_review_task, appeal: appeal, parent: attorney_task, assigned_to: user,
status: Constants.TASK_STATUSES.completed,
completed_at: Time.zone.now)
end

before do
Expand Down
5 changes: 2 additions & 3 deletions spec/feature/queue/checkout_flows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,11 @@ def select_issue_level_options(opts)
let(:root_task) { FactoryBot.create(:root_task) }
let(:parent_task) do
FactoryBot.create(
:ama_judge_task,
:ama_judge_review_task,
:in_progress,
assigned_to: judge_user,
appeal: appeal,
parent: root_task,
action: "review"
parent: root_task
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/feature/queue/judge_assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

context "Can view their queue" do
scenario "when viewing the review task queue" do
judge_review_task = create(:ama_judge_task, :in_progress, assigned_to: judge, action: :review)
judge_review_task = create(:ama_judge_review_task, :in_progress, assigned_to: judge)
expect(judge_review_task.status).to eq("in_progress")
appeal_review = judge_review_task.appeal
vet = appeal_review.veteran
Expand Down
22 changes: 22 additions & 0 deletions spec/models/appeal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,26 @@
end
end
end

context "is taskable" do
context "#assigned_attorney" do
let(:attorney) { create(:user) }
let(:appeal) { create(:appeal) }
let!(:task) { create(:ama_attorney_task, assigned_to: attorney, appeal: appeal) }

subject { appeal.assigned_attorney }

it { is_expected.to eq attorney }
end

context "#assigned_judge" do
let(:judge) { create(:user) }
let(:appeal) { create(:appeal) }
let!(:task) { create(:ama_judge_task, assigned_to: judge, appeal: appeal) }

subject { appeal.assigned_judge }

it { is_expected.to eq judge }
end
end
end
Loading

0 comments on commit 82f9d37

Please sign in to comment.