Repository navigation
fix(api): require a usual place of residence for cases and contacts - #20
Open
lbrunofidelis wants to merge 3 commits into
Open
lbrunofidelis wants to merge 3 commits into
lbrunofidelis wants to merge 3 commits into
Conversation
An empty or missing address list skipped validation entirely, so cases, contacts and contacts of contacts could be saved without any address even when the outbreak did not allow it. The requirement is enforced on create and whenever a request changes the addresses.
When enabled the address delete button is hidden for cases, contacts and contacts of contacts. Defaults to disabled so existing outbreaks keep the current behaviour.
lbrunofidelis
force-pushed
the
fix/#36-address-required-and-deletion-lock
branch
from
October 18, 2026 19:58
b220675 to
308acdd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With the outbreak option "Permitir cadastro de casos e contatos sem Endereço Atual preenchido" disabled, a case, contact or contact of contact could still be saved with no address at all. Deleting the address block on the create screen was enough.
Root cause
validatePersonAddressesinserver/models/person.jsruns every check insideif (Array.isArray(addresses) && addresses.length). An empty or missing list produces no error, soADDRESS_MUST_HAVE_USUAL_PLACE_OF_RESIDENCEis never raised and the outbreak option is never read. The guard is original Go.Data code from 2018 and was never touched here; the new outbreak option only made the gap visible, because disabling it now carries an explicit promise.The same request with a single notification address returns 422, which shows the validation itself works and only skips empty lists.
Fix
A missing usual place of residence is now reported for empty and absent lists as well. The requirement applies to cases, contacts and contacts of contacts, is enforced on create and whenever a request changes
addresses, and is still relaxed when the outbreak allows saving without an address. Deletions, system triggered updates and sync keep their existing short circuits, so records saved before this rule can still be edited and replicated.Events are unaffected: they do not carry an
addressesproperty.A second commit adds the
preventAddressDeletionoutbreak option and its language tokens. The flag is read by the frontend to hide the address delete button; the api does not enforce it, since the address requirement is what actually protects the data. It defaults tofalseso existing outbreaks keep their current behaviour.Verification
Against a local instance, outbreak with the option disabled:
"addresses": []ADDRESS_MUST_HAVE_USUAL_PLACE_OF_RESIDENCEaddresseskey"addresses": []"addresses": []"addresses": []Outbreak with the option enabled: creating a case with an empty list and with no
addresseskey both return 200, unchanged.The new outbreak flag round trips through
GET /api/outbreaks/{id}, and the language tokens are created by the migration in every language, translated in Portuguese.npm run lintpasses on the changed files.