-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a Vacate appeal stream for a Motion to Vacate #13325
Changes from all commits
77c8e66
980a29f
ec66b31
88bbf9d
857d00a
d630e5b
ed9610c
519a095
5424fe5
f7f3d4d
22997f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# The PostDecisionMotionUpdater validates and creates a PostDecisionMotion from the JudgeAddressMotionToVacateTask, | ||
# and creates the subsequent tasks or appeal streams. | ||
|
||
class PostDecisionMotionUpdater | ||
include ActiveModel::Model | ||
|
||
attr_reader :task, :params | ||
attr_reader :task, :params, :disposition, :instructions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My turn for a newbie Rails question... What does it mean to add attr_reader for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just means Ruby (not Rails, iiuc) will automatically make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think since we're using it in two places below, I thought it was nicer to just use "instructions" instead of
|
||
|
||
def initialize(task, params) | ||
@task = task | ||
@params = params | ||
@disposition = @params[:disposition] | ||
@instructions = @params[:instructions] | ||
end | ||
|
||
delegate :appeal, to: :task | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat. I can see how |
||
|
||
def process | ||
ActiveRecord::Base.transaction do | ||
motion = create_motion | ||
return unless motion | ||
return unless post_decision_motion | ||
|
||
handle_denial_or_dismissal | ||
handle_grant | ||
|
||
create_new_tasks | ||
return if errors.messages.any? | ||
|
||
task.update(status: Constants.TASK_STATUSES.completed) | ||
end | ||
end | ||
|
||
private | ||
|
||
def post_decision_motion | ||
@post_decision_motion ||= create_motion | ||
end | ||
|
||
def create_motion | ||
motion = PostDecisionMotion.new( | ||
task: task, | ||
|
@@ -32,7 +48,7 @@ def create_motion | |
motion.vacated_decision_issue_ids = params[:vacated_decision_issue_ids] | ||
elsif disposition == "granted" | ||
# For full grant, auto populate all decision issue IDs | ||
motion.vacated_decision_issue_ids = task.appeal.decision_issues.map(&:id) | ||
motion.vacated_decision_issue_ids = appeal.decision_issues.map(&:id) | ||
end | ||
|
||
unless motion.valid? | ||
|
@@ -43,96 +59,97 @@ def create_motion | |
motion.save | ||
end | ||
|
||
def create_new_tasks | ||
# We create an AbstractMotionToVacateTask as sibling to the judge task | ||
# to serve as parent for all successive tasks. It is created when associated with | ||
# the new task in order to pass responsibility for validation to child task | ||
# We create an AbstractMotionToVacateTask as sibling to the JudgeAddressMotionToVacateTask | ||
# to serve as parent for successive Denied or Dismissed tasks. It is created when associated with | ||
# the new task in order to pass responsibility for validation to child task | ||
def handle_denial_or_dismissal | ||
return unless denied_or_dismissed? | ||
|
||
abstract_task = create_abstract_task | ||
unless abstract_task.valid? | ||
errors.messages.merge!(abstract_task.errors.messages) | ||
return | ||
end | ||
|
||
if grant_type? | ||
judge_sign_task = create_judge_sign_task(abstract_task) | ||
end | ||
|
||
new_task = create_new_task((judge_sign_task || abstract_task)) | ||
new_task = create_new_task(abstract_task) | ||
|
||
unless new_task.valid? | ||
errors.messages.merge!(new_task.errors.messages) | ||
return | ||
end | ||
new_task.save | ||
end | ||
|
||
def handle_grant | ||
return unless grant_type? | ||
|
||
task.update(status: Constants.TASK_STATUSES.completed) | ||
vacate_stream = appeal.create_stream(:vacate) | ||
create_new_stream_tasks(vacate_stream) | ||
end | ||
|
||
def create_abstract_task | ||
AbstractMotionToVacateTask.new( | ||
appeal: task.appeal, | ||
appeal: appeal, | ||
parent: task.parent, | ||
assigned_to: task.assigned_to | ||
assigned_to: judge_user | ||
) | ||
end | ||
|
||
def create_new_task(parent) | ||
task_class.new( | ||
appeal: task.appeal, | ||
appeal: appeal, | ||
parent: parent, | ||
assigned_by: task.assigned_to, | ||
assigned_to: assigned_to, | ||
instructions: [params[:instructions]] | ||
assigned_by: judge_user, | ||
assigned_to: attorney_user, | ||
instructions: [instructions] | ||
) | ||
end | ||
|
||
def create_judge_sign_task(parent) | ||
JudgeSignMotionToVacateTask.new( | ||
appeal: task.appeal, | ||
parent: parent, | ||
assigned_to: task.assigned_to | ||
def create_new_stream_tasks(stream) | ||
InitialTasksFactory.new(stream).create_root_and_sub_tasks! | ||
|
||
jdrt = JudgeDecisionReviewTask.create!(appeal: stream, parent: stream.root_task, assigned_to: judge_user) | ||
attorney_task = AttorneyTask.new( | ||
appeal: stream, parent: jdrt, assigned_by: judge_user, assigned_to: attorney_user, instructions: [instructions] | ||
) | ||
end | ||
|
||
def disposition | ||
case params[:disposition] | ||
when "partial" | ||
"partially_granted" | ||
else | ||
params[:disposition] | ||
unless attorney_task.valid? | ||
errors.messages.merge!(attorney_task.errors.messages) | ||
return | ||
end | ||
|
||
attorney_task.save | ||
end | ||
|
||
def task_class | ||
@task_class ||= (task_type + "_task").classify.constantize | ||
end | ||
|
||
def task_type | ||
grant_type? ? params[:vacate_type] : "#{params[:disposition]}_motion_to_vacate" | ||
"#{disposition}_motion_to_vacate" | ||
end | ||
|
||
def grant_type? | ||
%w[granted partial].include? params[:disposition] | ||
%w[granted partially_granted].include? disposition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to make the front-end version of the disposition consistent with the backend, partial -> partially_granted |
||
end | ||
|
||
def denied_or_dismissed? | ||
%w[denied dismissed].include? disposition | ||
end | ||
|
||
def assigned_to | ||
@assigned_to ||= (denied_or_dismissed? ? prev_motions_attorney : User.find_by(id: params[:assigned_to_id])) | ||
def judge_user | ||
task.assigned_to | ||
end | ||
|
||
def attorney_user | ||
@attorney_user ||= denied_or_dismissed? ? prev_motions_attorney : User.find_by(id: params[:assigned_to_id]) | ||
end | ||
|
||
def prev_motions_attorney | ||
mtv_mail_task.assigned_to | ||
task.parent.assigned_to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is clear enough without making a method for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok newbie question but why are we changing it from mtv_mail_task to task.parent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Sjones352 Not a newbie question! This was a completely unnecessary change, I just thought that task.parent.assigned_to was just as clear and the mtv_mail_task method was unneeded. If you think it's harder to read now, I can put it back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this works. My original inclination was to keep |
||
end | ||
|
||
def prev_motions_attorney_or_org | ||
prev_motions_attorney.inactive? ? LitigationSupport.singleton : prev_motions_attorney | ||
end | ||
|
||
def mtv_mail_task | ||
task.parent | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small rename to be more accurate