Skip to content
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

Replicate prod bug: Case Movement user cannot reassign task #16206

Merged
merged 7 commits into from May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/helpers/sanitized_json_configuration.rb
Expand Up @@ -34,20 +34,6 @@ def configuration
sanitize_fields: %w[veteran_file_number],
retrieval: ->(records) { records[Appeal].map(&:intake).compact.sort_by(&:id) }
},
JudgeCaseReview => {
sanitize_fields: %w[comment],
retrieval: lambda do |records|
judge_task_ids = Task.where(type: JudgeTask.descendants.map(&:name), appeal: records[Appeal]).ids
JudgeCaseReview.where(task_id: judge_task_ids).order(:id)
end
},
AttorneyCaseReview => {
sanitize_fields: %w[comment],
retrieval: lambda do |records|
atty_task_ids = Task.where(type: AttorneyTask.descendants.map(&:name), appeal: records[Appeal]).ids
AttorneyCaseReview.where(task_id: atty_task_ids).order(:id)
end
},
DecisionDocument => {
# citation_number must be unique and doesn't reference anything else in Caseflow,
# so transform the number so we can import into the same DB as the original record
Expand All @@ -64,6 +50,20 @@ def configuration
TaskTimer => {
retrieval: ->(records) { TaskTimer.where(task_id: records[Task].map(&:id)).order(:id) }
},
JudgeCaseReview => {
sanitize_fields: %w[comment],
retrieval: lambda do |records|
judge_task_ids = Task.where(type: JudgeTask.descendants.map(&:name), appeal: records[Appeal]).ids
JudgeCaseReview.where(task_id: judge_task_ids).order(:id)
end
},
AttorneyCaseReview => {
sanitize_fields: %w[comment],
retrieval: lambda do |records|
atty_task_ids = Task.where(type: AttorneyTask.descendants.map(&:name), appeal: records[Appeal]).ids
AttorneyCaseReview.where(task_id: atty_task_ids).order(:id)
end
},
Comment on lines +53 to +66
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reordering so that these CaseReviews are exported after Tasks because they rely on tasks.

RequestIssue => {
sanitize_fields: ["notes", "contested_issue_description", /_(notes|text|description)/],
retrieval: ->(records) { records[Appeal].map(&:request_issues).flatten.sort_by(&:id) }
Expand Down Expand Up @@ -276,7 +276,7 @@ def id_offset
# Start with important types that other records will reassociate with
def first_types_to_import
# HearingDay is needed by Hearing
@first_types_to_import ||= [Appeal, Organization, User, HearingDay]
@first_types_to_import ||= [Appeal, Organization, User, HearingDay, Task]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure Tasks are one of the types imported before other records, i.e. CaseReviews, because CaseReviews rely on Tasks existing in the DB.

end

# During record creation, types where validation and callbacks should be avoided
Expand Down
2 changes: 2 additions & 0 deletions lib/helpers/sanitized_json_importer.rb
Expand Up @@ -148,6 +148,8 @@ def adjust_ids_by_offset(klass, obj_hash)
offset_id_table_fields[klass.table_name]&.each do |field_name|
if obj_hash[field_name].is_a?(Array)
obj_hash[field_name] = obj_hash[field_name].map { |id| id + @id_offset }
elsif obj_hash[field_name].is_a?(String)
obj_hash[field_name] = (obj_hash[field_name].to_i + @id_offset).to_s
Comment on lines +151 to +152
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CaseReview records use strings for task_id to refer to legacy appeals, so we need to handle strings. This importer currently only supports AMA appeals so these strings can be converted to integers without error.

elsif obj_hash[field_name]
obj_hash[field_name] += @id_offset
end
Expand Down
26 changes: 26 additions & 0 deletions spec/fixes/investigate_scm_cant_reassign_spec.rb
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "helpers/sanitized_json_configuration.rb"
require "helpers/sanitized_json_importer.rb"

describe "CaseMovementTeam task actions" do
# Ticket https://github.com/department-of-veterans-affairs/caseflow/issues/16205#
# https://github.com/department-of-veterans-affairs/dsva-vacols/issues/187
# Target state: TBD -- see tcket
describe "during Quality Review" do
let!(:appeal) do
sji = SanitizedJsonImporter.from_file("spec/records/scm-cant-reassign.json", verbosity: 5)
sji.import
sji.imported_records[Appeal.table_name].first
end

it "produces error and user can't reassign to attorney" do
# To replicate error:
# Clicking on "Assign to attorney" shows the "Assign task" modal.
# Clicking on "Select a user" shows "Other".
# Clicking on "Other" and starting to type "TALAM" shows the attorney.
# Clicking Submit button shows an "Error assigning tasks" error banner in the modal
# (and an error message in the DevTools console).
end
end
end