Fix reporting org validation and improve audit logs#62
Merged
Conversation
Before creating a reporting org, the code checked that there wasn't already a reporting org with the same short_name, as they have to be unique - but the check didn't filter out soft deleting orgs on SuiteCRM so users were blocked from creating orgs with short_names belonging to deleted orgs. This commit fixes that, and so resolves #61.
This commit refactors the exception registration, separating the handlers from the registration, as the registration function was being marked as too complex. It also adds a custom generic handler for all exceptions post-user authentication, and switches assert_precondition_met to use that.
Updates route handlers to use the new assert_precondition_met which includes better audit logging.
chrisarridge
approved these changes
Jan 26, 2026
Contributor
chrisarridge
left a comment
There was a problem hiding this comment.
Looks good. I only have one comment about whether we lose a bit of useful information from the audit log in one place, otherwise looks great!
| audit_log_msg=( | ||
| f"Request to create reporting org by user id: {user.user_id_crm} " | ||
| f"with non-unique short name: {reporting_org.short_name}" | ||
| f"Request to create reporting org failed because the specified short name '{reporting_org.short_name}' " |
Contributor
There was a problem hiding this comment.
With this change, are we going to lose the ability to know which user attempted to do this? Or will the custom exception handler now inject that information automatically?
Contributor
Author
There was a problem hiding this comment.
Yep, the custom exception handler prefixes the log entry with client_id and user_id so that they are always in the same format. RYDUserException is only used downstream of a successful authentication and the user object will always be populated.
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.
This PR:
assert_precondition_metto use the improved exception handling