Task Reassignment Taxonomies - department-of-veterans-affairs/caseflow GitHub Wiki

Prechecks

Here are a few easy rails console commands to check various attributes that may help with troubleshooting

Set old_user and new_user variables with CSS IDs

old_user = User.find_by_css_id("<inactive user id>")
new_user = User.find_by_css_id("<active user id>")

Check that the old_user is indeed inactive and the new_user is active

old_user.active?
new_user.active?

check that the users are either attorneys or judges for cases where the tasks need to be sent back to judge assign

old_user.attorney?
new_user.judge?

check the count of tasks associated with the old_user that are inactive

old_user.tasks.where.not(status: ["completed", "cancelled"]).count

Checks for tasks associated with legacy appeals

old_user.tasks.where(appeal_type: "LegacyAppeal").count

Taxonomy: Reassign all active and inactive tasks(legacy or ama)

This is primarily done when a user changes their CSS ID. Please ensure that the ask is for all inactive tasks to be reassigned and not just those that are active.

  1. Set old_user and new_user variables with CSS IDs
old_user = User.find_by_css_id("<inactive user id>")
new_user = User.find_by_css_id("<active user id>")
  1. take note of current user task counts
old_user.tasks.count
new_user.tasks.count
  1. Check the count of all tasks that are inactive
old_user.tasks.where.not(status: ["completed", "cancelled", "on_hold"]).count
  1. Set counter variable to track number of jobs reassigned
counter = 0
  1. find the tasks that need to be reassigned based on the tasks assigned to the old user
assigned_tasks = old_user.tasks
  1. update the tasks and increment the counter
assigned_tasks.each{|task| task.update!(assigned_to_id: new_user.id, assigned_by_id: task.assigned_by_id) && counter += 1}
  1. If you encounter the error "ActiveRecord::RecordInvalid (Validation failed: Assigned to has to be an attorney)" reload the task or tasks and try running the update again
assigned_tasks.reload
  1. check the counts of the counter and both user task counts to ensure they have incremented and decremented as expected
counter
old_user.tasks.count
new_user.tasks.count

Taxonomy: Reassignment of Specific Tasks given user CSS IDs and Appeal ID

  1. Set the user variables
old_user = User.find_by_css_id("<inactive user css id>")
new_user = User.find_by_css_id("<active user css id>")
  1. instantiate array with appeal ids given. it's ok if it's just one
appeal_ids = ["<ID>","<ID>","<ID>"]
  1. take note of current user task counts
old_user.tasks.count
new_user.tasks.count
  1. set counter variable to track number of jobs reassigned
counter = 0
  1. find the tasks requested for reassignment by cross referencing appeal_ids and the old_user.id
assigned_tasks = Task.where(appeal_id: appeal_ids, assigned_to: old_user)
  1. ensure that the count of the assigned_tasks array matches the expected amount of tasks to be reassigned
assigned_tasks.count
  1. update the tasks and increment the counter
assigned_tasks.each{|task| task.update!(assigned_to_id: new_user.id, assigned_by_id: task.assigned_by_id) && counter += 1}
  1. if you encounter the error "ActiveRecord::RecordInvalid (Validation failed: Assigned to has to be an attorney)" reload the task or tasks and try running the update again if not proceed to check counts
assigned_tasks.reload
  1. check the counts of the counter and both user task counts to ensure they have incremented and decremented as expected
counter
old_user.tasks.count
new_user.tasks.count

Taxonomy: Active Task Reassignment AMA and Legacy

  1. Assign old user to a variable
old_user = User.find_by_css_id("<inactive user id>")
  1. Assign new user to a variable
new_user = User.find_by_css_id("<active user id>")
  1. Take note of current user task counts
old_user.tasks.count
new_user.tasks.count
  1. Check the count of all tasks that are inactive
old_user.tasks.where.not(status: ["completed", "cancelled"]).count
  1. Set counter variable to track number of jobs reassigned
counter = 0
  1. Find the tasks that need to be reassigned based on the tasks assigned to the old user
assigned_tasks = old_user.tasks.where.not(status: ["completed", "cancelled"]))
  1. Update the tasks and increment the counter
assigned_tasks.each{|task| task.update!(assigned_to_id: new_user.id, assigned_by_id: task.assigned_by_id) && counter += 1}
  1. If you encounter the error "ActiveRecord::RecordInvalid (Validation failed: Assigned to has to be an attorney)" reload the task or tasks and try running the update again
assigned_tasks.reload
  1. Check the counts of the counter and both user task counts to ensure they have incremented and decremented as expected
counter
old_user.tasks.count
new_user.tasks.count

Reassign Task(s) from one user to another by Task ID(s)

  1. Set the new_user variable with CSS ID
new_user = User.find_by_css_id("<active user css id>")
  1. Set the old_user variable with CSS ID
old_user = User.find_by_css_id("<active user css id>")
  1. List all tasks that need to be reassigned
task_ids = ["<ID>","<ID>","<ID>"]
  1. Set a variable with all assigned tasks
assigned_tasks = Task.where(id: task_ids)
  1. Check task count for the new_user and old_user
new_user.tasks.count
old_user.tasks.count
  1. If old user not included, utilize the assigned tasks to find the user and their task count
old_users = assigned_tasks.map(&:assigned_to).uniq
old_users.map { |user| user.tasks.count }
  1. Count the number of tasks and ensure it matches the length of the array
assigned_tasks.count
  1. Set a counter to be incremented based on how many tasks are reassigned
counter = 0
  1. Reassign each task into the new_user provided and update the counter
assigned_tasks.each{|task| task.update!(assigned_to_id: new_user.id, assigned_by_id: task.assigned_by_id) && counter += 1}
  1. If you encounter the error "ActiveRecord::RecordInvalid (Validation failed: Assigned to has to be an attorney)" reload the task or tasks and try running the update again
assigned_tasks.reload
  1. Verify the counter aligns with the length of the task array
counter   
  1. Verify the count of the users tasks increased
new_user.tasks.count
old_user.tasks.count
  1. If old user not included verify count using this approach
old_users.map { |user| user.tasks.count }

Reassign Active Tasks from one user to another by appeal UUID(s) and CSS IDs

  1. Set the user variables
old_user = User.find_by_css_id("inactive user css id")
new_user = User.find_by_css_id("<active user css id>")
  1. Instantiate array with appeal ids given by appeal uuid(s)
appeal_uuids = ["<UUID>","<UUID>","<UUID>"]
appeal_ids = Appeal.where(uuid: appeal_uuids).pluck(:id)
  1. Set counter variable to track number of jobs reassigned and check both user task counts for self-auditing
counter = 0
old_user.tasks.count
new_user.tasks.count
  1. Find the tasks requested for reassignment by cross referencing appeal_ids and the old_user.id
assigned_tasks = Task.where(appeal_id: appeal_ids, assigned_to: old_user)
  1. Ensure that the count of the assigned_tasks array matches the expected amount of tasks to be reassigned
assigned_tasks.count == old_user.tasks.where(appeal_id: appeal_ids).count
  1. Update the tasks to new user and increment the counter
assigned_tasks.each{|task| task.update!(assigned_to_id: new_user.id, assigned_by_id: task.assigned_by_id) && counter += 1}
  1. If you encounter the error "ActiveRecord::RecordInvalid (Validation failed: Assigned to has to be an attorney)" reload the task or tasks and try running the update again if not proceed to check counts
assigned_tasks.reload
  1. Check the counts of the counter and both user task counts to ensure they have incremented and decremented as expected. Check both user tasks to ensure reassignment
counter
old_user.tasks.count
new_user.tasks.count
assigned_task_ids = assigned_tasks.pluck(:appeal_id)
new_user_task_ids = new_user.tasks.where(appeal_id: assigned_task_ids)
assigned_task_ids.count == new_user_task_ids.count
⚠️ **GitHub.com Fallback** ⚠️