diff --git a/app/utils/data_access.py b/app/utils/data_access.py index c4ffc3f4..4051284a 100644 --- a/app/utils/data_access.py +++ b/app/utils/data_access.py @@ -829,8 +829,12 @@ def add_herd(form, user_uuid): user = fetch_user_info(user_uuid) if user is None: return {"status": "error", "message": "Not logged in"} - if not (user.is_admin or (user.is_manager and form["genebank"] in user.is_manager)): - return {"status": "error", "message": "Forbidden"} + try: + genebank_id = int(form["genebank"]) + if not (user.is_admin or (user.is_manager and genebank_id in user.is_manager)): + return {"status": "error", "message": "Forbidden"} + except (ValueError, KeyError): + return {"status": "error", "message": "Invalid genebank ID"} with DATABASE.atomic(): try: diff --git a/frontend/src/breeding_context.tsx b/frontend/src/breeding_context.tsx index 5510cd6a..2081346b 100644 --- a/frontend/src/breeding_context.tsx +++ b/frontend/src/breeding_context.tsx @@ -244,7 +244,9 @@ export const WithBreedingContext = (props: { children: React.ReactNode }) => { if (!breeding.litter_size6w) { return Math.min(breedingUpdates.litter_size6w, 9); } - if (breeding.litter_size6w < breedingUpdates.litter_size6w) { + if ( + Number(breeding.litter_size6w) < Number(breedingUpdates.litter_size6w) + ) { return ( Math.min(breedingUpdates.litter_size6w, 9) - Math.min(breeding.litter_size6w, 9) diff --git a/frontend/src/breeding_form.tsx b/frontend/src/breeding_form.tsx index 5160cf00..9d3fb416 100644 --- a/frontend/src/breeding_form.tsx +++ b/frontend/src/breeding_form.tsx @@ -294,7 +294,7 @@ export function BreedingForm({ return false; } - if (userInput?.litter_size6w > userInput?.litter_size) { + if (Number(userInput?.litter_size6w) > Number(userInput?.litter_size)) { userMessage( "Kullstorleken efter 6 veckor får inte vara större än kullstorleken vid födseln.", "warning" diff --git a/frontend/src/individual_add.tsx b/frontend/src/individual_add.tsx index 60707237..fb0f1ee7 100644 --- a/frontend/src/individual_add.tsx +++ b/frontend/src/individual_add.tsx @@ -416,7 +416,7 @@ export function IndividualAdd({ ); return false; } - if (individual.litter_size6w > individual.litter_size) { + if (Number(individual.litter_size6w) > Number(individual.litter_size)) { userMessage( "Kullstorleken efter 6 veckor får inte vara större än kullstorleken vid födseln.", "warning" diff --git a/frontend/src/individual_breeding_form.tsx b/frontend/src/individual_breeding_form.tsx index a4cf95fb..5f5f5dde 100644 --- a/frontend/src/individual_breeding_form.tsx +++ b/frontend/src/individual_breeding_form.tsx @@ -267,7 +267,7 @@ export function IndividualBreedingForm({ if ( (userInput.birth_date, userInput.litter_size) !== null && - !(userInput.litter_size > 0) + !(Number(userInput.litter_size) > 0) ) { userMessage("Ange en kullstorlek större än 0", "warning"); return false; @@ -365,7 +365,7 @@ export function IndividualBreedingForm({ const newBirthData: Birth = { date: breeding.birth_date, litter_size: breeding.litter_size, - litter_size6w: breeding.litter_size, + litter_size6w: breeding.litter_size6w, notes: breeding.birth_notes !== "" ? breeding.birth_notes : undefined, id: newBreeding.breeding_id, };