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
Validate that an appeal can have only one JudgeAssignTask active at a time #16072
Conversation
Code Climate has analyzed commit 51873e2 and detected 0 issues on this pull request. View more on Code Climate. |
This comment has been minimized.
This comment has been minimized.
37377f4
to
63861d3
Compare
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.
Woohoo!
@yoomlam Here is the expected error message. |
Generated by 🚫 Danger |
@yoomlam I consulted design about the error message wording after getting the PR approved by Ann-Marie during a demo. Below is the current wording. I will merge this after the build passes. |
@eileen-nava I think that message may be too specific. If the validation fails for other scenarios, this error message (mentioning "closing the window" and "previous window") is confusing. |
Good point. I'll check in with design again. Thank you! |
…eDecisionReviewTask (#16586) Resolves jira ticket [Research and prevent recurrence of bug where one case has multiple JudgeAssignTasks, JudgeDecisionReviewTasks, and AttorneyTasks](https://vajira.max.gov/projects/CASEFLOW/issues/CASEFLOW-2075) . Relates to github PR [Write feature test to replicate scenario with multiple Judge/Attorney tasks](#16582). ### Description A bug occurred in production where a user created multiple Judge and Attorney tasks by doing the same actions in two different tabs, as described in [this comment from Yoom](https://github.com/department-of-veterans-affairs/dsva-vacols/issues/212#issuecomment-889401070). The `JudgeAssignTask` [model already had a validation ](#16072) to ensure that an appeal cannot have more than one `JudgeAssignTask` open at the same time. I expanded this validation to the `JudgeDecisionReviewTask` and `AttorneyTask` models. I also refactored the validation to use instance variables instead of thread-local variables, as suggested in [this StackOverflow post](https://stackoverflow.com/questions/8881712/skip-certain-validation-method-in-model) that Yoom linked in a previous thread. ### Acceptance Criteria - [ ] Code compiles correctly - [ ] All automated tests pass - [ ] Task validations no longer use thread-local variables - [ ] If a user attempts to act on the same `JudgeAssignTask` in two different windows, they will not be able to create multiple `JudgeDecisionReviewTask`s and `AttorneyTask`s. ### Testing Plan [ ] Find an appeal with an open `JudgeAssignTask` ``` jat = JudgeAssignTask.open.last appeal = jat.appeal ``` [ ] On local caseflow, switch users to the judge who has the `JudgeAssignTask` assigned to them [ ] Navigate to the case details page for the relevant appeal. Open the same page in a second tab `/queue/appeals/${appeal.uuid}` [ ] In the first tab, reassign the `JudgeAssignTask` to another judge [ ] In the second tab, attempt to complete the `JudgeAssignTask` by assigning the case to an attorney. You should not be able to complete this action
Bumps #15220
Description
Add a validation that ensures only one
JudgeAssignTask
can be created at a time. This functionality can be extended to other tasks where there should only be one, such asChangeHearingDispositionTask
. I am leaving that work for another PR.Acceptance Criteria
Testing Plan
Find an appeal with a
JudgeAssignTask
. Next, find a user that will beassigned_to
, andassigned_by
.Watch the validation fail after attempting to make a second
JudgeAssignTask
for this appeal.Lessons Learned Along the Way
I wanted to document some of the bumps I hit while working on this PR.
The test initially failed on setup in the let block where it creates the first JudgeAssignTask. While debugging with Pry, I found that the validation was called twice when creating the first
JudgeAssignTask
.While working on it with Yoom, he pointed out that I had written a validation which was called both when the record was inserted in the database and saved to the database.
Relevant documentation quote:
Since my custom validation ran on
update
andcreate
, it also caused unrelated tests to fail on setup. I changed the validation to only be called when theJudgeAssignTask
task is saved to the database. Here's helpful documentation about custom validations.Next, I locally tested reassigning a
JudgeAssignTask
to see if the functionality still works. Initially, it did not work because the reassign flow isThe on create validation made it impossible to do the above. I edited the
reassign
method so that it will allow twoJudgeAssignTask
s to simultaneously exist. I found this StackOverflow post helpful for my approach.Updated approach
After pairing with Yoom and Bar, I revised my original approach in favor of using thread-local variables. You can read more about this approach in the associated hackmd document's Section 5, Thread-local variables. I want to highlight that thread-local variables use the
Thread.current.thread_variable_set("foo", "bar")
syntax, whereas fiber-local variables use theThread.current["foo"] = "bar"
syntax.