-
Notifications
You must be signed in to change notification settings - Fork 78
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
LF-4531: Set up new task abandonment reason for tasks with removed animals #3533
base: integration
Are you sure you want to change the base?
LF-4531: Set up new task abandonment reason for tasks with removed animals #3533
Conversation
b04061c
to
7f797f2
Compare
* update middleware to avoid the reason to be added from the client * add test
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.
Sorry could you elaborate on why you wanted to add the database restriction at this particular stage? I understand it's definitely ideal to restrict at multiple levels, but I'm thinking about that "Crop management plan abandoned" translation ticket coming up, which I think will also require creating a new key, and so that migration would end up deleting and re-creating this check too, then, correct?
Only to restrict the number of database migrations, I wonder if continuing to let the model validation enforce for now would be okay? Or is there a particular danger the model isn't catching?
Similarly to how we do this now for other entities, I think the best way to solve the problem of disallowing wrong keys at the database level would be to have an enum table for the abandonment keys, and have the reason column have a foreign key to that table. Would be similar to what's happening now with animal movement purposes, or animal uses. I'm not sure if that migration would be trickier though due to us already having existing data, so we don't need to do this now! But just proposing that as a longer term solution |
Description
This PR adds support for the new abandonment reason when all animals are removed from a task. The key will be added as part of delete/remove animals/batches APIs.
abandonment_reason
in thetask
table. (This wasn't necessary, but I added it to avoid adding a wrong key. Wrong keys don't exist in the prod or beta DB, so it should be safe to add this constraint.)TaskModel
checkAbandonTask
middleware not to allow the new key to be added from clientsThis task was simpler than expected since the keys are hard-coded in the webapp, and the read-only page and task creation page don't share the same code.
Creation
LiteFarm/packages/webapp/src/components/Task/AbandonTask/index.jsx
Lines 164 to 178 in aa4be4f
Read-only
LiteFarm/packages/webapp/src/components/Task/TaskReadOnly/index.jsx
Lines 350 to 371 in aa4be4f
Jira link: https://lite-farm.atlassian.net/browse/LF-4531
Type of change
How Has This Been Tested?
Replaced abandoned task's
abandonment_reason
withNO_ANIMALS
in the DB and checked the read-only page in the webapp.Checklist: