Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Implements backend audit/history tracking for BiocommonsUser changes (email/username/deletion/restoration) and uses that history to prevent username reuse, with corresponding route updates and tests.
Changes:
- Added
BiocommonsUserHistorymodel + relationship onBiocommonsUser, and methods to record history on updates/deletes/restores. - Updated user/admin routes to use the new model methods when changing email/username.
- Added tests covering history creation and username-reuse prevention behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
db/models.py |
Adds BiocommonsUserHistory, wires relationship, and introduces save_history/update_email/update_username helpers. |
migrations/versions/44d8dc065b59_user_history.py |
Creates the new biocommonsuserhistory table. |
routers/user.py |
Updates username/email update flows to record history and enforce username reuse rule. |
routers/admin.py |
Records history for admin-triggered email updates with correct “updated_by”. |
tests/test_user.py |
Updates email-change test to assert DB history entry instead of Auth0 metadata updates. |
tests/db/test_models.py |
Adds unit tests for history creation, username update history, and username reuse blocking. |
Contributor
|
Thanks @marius-mather - a few questions:
|
Collaborator
Author
|
uwwint
requested changes
Feb 10, 2026
| field_errors=field_errors | ||
| ) | ||
|
|
||
| # Update in Auth0 (need to include connection when updating username) |
Collaborator
There was a problem hiding this comment.
This is a race condition... two threads can pass existing user, cause an Auth0 update, but fail on the local database. I would recommend doing the auth0 change after commit to local db to avoid this.
Collaborator
There was a problem hiding this comment.
and if auth0 fails cleanup local db, rollback.
uwwint
approved these changes
Feb 20, 2026
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
AAI-698: track history of changes to the user in the backend database (e.g. username, email changes). Use this to enforce no reuse of previously-used usernames
Changes
BiocommonsUserHistorymodel to track changes that need to be recordedBiocommonsUserHistoryvisible in DB admin viewChecklist
How to Test Manually (if necessary)
Run
uv run pytestScreenshots
User history in DB admin view: