/
appeal_active_task_cancellation.rb
50 lines (39 loc) · 1.31 KB
/
appeal_active_task_cancellation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
class AppealActiveTaskCancellation
delegate :request_issues, :tasks, to: :appeal
def initialize(appeal)
@appeal = appeal
end
def call
if appeal.withdrawn?
# Withdrawn appeals must be included in the automatic distribution pool.
# For an appeal to be considered ready for distribution, it must have an
# assigned DistributionTask. In order for the appeal to progress after
# distribution, its RootTask and TrackVeteranTask cannot be cancelled.
cancel_active_tasks_except_those_needed_for_distribution
assign_distribution_task
elsif no_active_request_issues?
cancel_active_tasks
end
end
private
attr_reader :appeal
def cancel_active_tasks_except_those_needed_for_distribution
all_tasks_except_those_needed_for_distribution.each(&:cancel_task_and_child_subtasks)
end
def assign_distribution_task
tasks.find_by(type: "DistributionTask").update!(status: "assigned")
end
def all_tasks_except_those_needed_for_distribution
tasks.where.not(type: tasks_needed_for_distribution)
end
def tasks_needed_for_distribution
%w[TrackVeteranTask RootTask]
end
def no_active_request_issues?
request_issues.active.empty?
end
def cancel_active_tasks
tasks.each(&:cancel_task_and_child_subtasks)
end
end