Split the platform user from the Person contributor agent. - #686
Split the platform user from the Person contributor agent.#686GianlucaFicarelli wants to merge 13 commits into
Person contributor agent.#686Conversation
Introduce a dedicated User table (keyed by Keycloak sub_id) separate from the Person agent. created_by_id/updated_by_id on all entities now point to user.id instead of agent.id. Person remains an Agent subclass for use as a contributor (Contribution.agent_id) but no longer carries sub_id.
Person contributor agent.Person contributor agent.
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
Person contributor agent.Person contributor agent.
Person contributor agent.Person contributor agent.
Person contributor agent.Person contributor agent.
| given_name: Mapped[str | None] | ||
| family_name: Mapped[str | None] |
There was a problem hiding this comment.
Do we need these for the platform users? I suppose with service accounts etc. it might be harder to conform to this schema.
There was a problem hiding this comment.
given_name and family_name aren't strictly needed for entitycore, but they are populated from the existing records, that in turn come from keycloak.
If we remove them, and keep only pref_label, then they are removed also from created_by and updated_by in the returned payloads.
Maybe @bilalesi can confirm if the UI expects those fields or not?
There was a problem hiding this comment.
Gianluca, for created_by/updated_by we only read pref_label - given_name and family_name aren't used anywhere in core-web-app, so dropping them from PlatformUser is fine on our side.
One thing worth keeping separate though: for contributions we do rely on Person.given_name/family_name. We build the contributor display name from the given/family pair and fall back to pref_label, and we sort contributors by family name:
So as long as they stay on Person as the contributor agent, removing them from PlatformUser doesn't affect us.
* origin/main: Move agent rules source to AGENTS.md and sync to Amazon Q and Claude. (#691)
|
Gianluca, I went through the breaking changes against core-web-app and none of them affect us, so no need to hold the merge for the frontend. Concretely, the only ownership constraint we send is On the facet Btw, one thing this unlocks for us. Filtering by display name is fragile in both directions: two different users sharing a I've prepared the type-side adaptation on our end already: openbraininstitute/core-web-app#1847. |
Introduce a dedicated PlatformUser table (keyed by Keycloak sub_id) separate from the Person agent.
created_by_id/updated_by_id on all entities now point to platform_user.id instead of agent.id.
Person remains an Agent subclass for use as a contributor (Contribution.agent_id) but no longer carries sub_id.
Previously
Personserved a dual role: contributor inContributionrecords and platform user identified bysub_id.Changes
Model
PlatformUsertable withid = Keycloak sub_id(UUID PK),given_name,family_name,pref_labelIdentifiable.created_by_id/updated_by_idnow FK toplatform_user.idinstead ofagent.idsub_idremoved fromPersonApp
app/schemas/platform_user.py: newPlatformUserRead,NestedPlatformUserReadschemasapp/schemas/identifiable.py:created_by/updated_bytyped asNestedPlatformUserReadapp/queries/utils.py:get_or_create_userreturns aPlatformUser(no longer aPerson)app/filters/person.py:CreatorFilterMixinuses a newNestedPlatformUserFilter(model=PlatformUser)created_by/updated_byaliases switched fromPersontoPlatformUserMigration
platform_usertable, populates from existingpersonrows, remaps allcreated_by_id/updated_by_idFKs across 26 tables fromagent.idtoperson.sub_idTests
test_get_or_create_userandtest_get_usertests intest_db_utils.pyBreaking changes
For backward compatibility, the old keys can still be used to allow the clients to adapt for the change, but they are deprecated and will be removed later.
sub_idis now inid. In some cases sub_id was null, and it was replaced by an existing subject id when possible, or a randomly generated id when not possible (for reference, see the migration file in the PR for the mapping).Before:
After:
The change on the type can be discussed further if needed, depending on how it's used by the client.
Note that the facets for contribution are unchanged.
Before:
After:
Fix #685