TRUNK-6298: Validate required fields (person, username) during user creation#6132
Open
RohithVangalla1 wants to merge 1 commit into
Open
Conversation
The createUser method had a TODO to check required fields before persisting a new User. Without these checks, a User could be created without an associated Person or without a username/systemId, leading to NullPointerExceptions or data integrity issues downstream. This change adds validation that: - User must have an associated Person (required for name, demographics) - User must have either a username or systemId (required for login) Both checks throw APIException with internationalized message keys, consistent with the existing password validation pattern. Added message keys: - User.creating.person.required - User.creating.username.required Addresses the TODO: 'Check required fields for user!!'
|
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.



Description of what I changed
Adds missing required field validation to
UserServiceImpl.createUser()as indicated by the existing TODO comment.The
createUsermethod had a TODO: "Check required fields for user!!" Without these checks, a User could be created without an associated Person or without a username/systemId, leading to NullPointerExceptions or data integrity issues in downstream operations (e.g., displaying user names, login attempts).Added validation before password validation and persistence:
user.getPerson() == null→ throwsAPIExceptionwith keyUser.creating.person.requiredAPIExceptionwith keyUser.creating.username.requiredBoth follow the same pattern as the existing password validation (
User.creating.password.required).Message keys added to messages.properties:
User.creating.person.required=A person must be associated with the user when creating a userUser.creating.username.required=A username or system id is required when creating a userAddresses the TODO in UserServiceImpl.java line 123: "Check required fields for user!!"
Issue I worked on
No existing JIRA issue — this addresses a long-standing TODO in the codebase. Happy to create a ticket if needed.
Checklist: I completed these to help reviewers :)
mvn clean packageright before creating this pull request and added all formatting changes to my commit.