Entity management#17
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces “entity management” for user↔project and user↔group memberships by tracking which system (application vs external sync sources) owns each relationship, and adds managed-sync endpoints to fully replace externally managed memberships.
Changes:
- Add
EntityManagerEnumplusmanaged_by/timestamps onuser_projectsanduser_groups, update SQL views, and expose the new fields in schemas. - Switch group/user membership listing endpoints to read from new view-backed models that include relationship metadata.
- Add
/managed/{manager}/projects/{id}/usersand/managed/{manager}/groups/{id}/usersPUT sync endpoints with test coverage and an Alembic migration.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| userapp/core/schemas/users.py | Update user “full” schema to return group membership view objects instead of plain groups. |
| userapp/core/schemas/user_project.py | Add managed_by and timestamps to user↔project association schemas and add managed PUT payload schema. |
| userapp/core/schemas/user_group.py | Add managed_by and timestamps to user↔group association schemas and add managed PUT payload schema. |
| userapp/core/schemas/groups.py | Minor formatting-only change. |
| userapp/core/schemas/general.py | Extend project/group view schemas to include relationship metadata; add group/user membership view schemas. |
| userapp/core/models/views.py | Add SQLAlchemy view models for group-user and user-group memberships; extend joined project view columns. |
| userapp/core/models/tables.py | Add managed_by/timestamps columns and new indexes; switch User.groups relationship to view-backed model. |
| userapp/core/models/enum.py | Introduce EntityManagerEnum. |
| userapp/api/tests/test_projects.py | Add tests asserting managed_by defaulting/persistence on project membership creation. |
| userapp/api/tests/test_managed.py | Add full managed-sync endpoint test suite for both managers. |
| userapp/api/tests/test_groups.py | Update group membership request payload key (user_id) and add managed_by default/persistence tests. |
| userapp/api/tests/conftest.py | Update fixture to use user_id when adding a user to a group. |
| userapp/api/routes/users.py | Change /users/{id}/groups to return membership view rows instead of groups via join. |
| userapp/api/routes/managed/morgridge_ad.py | Add Morgridge AD managed-sync router. |
| userapp/api/routes/managed/manifest.py | Add Manifest managed-sync router. |
| userapp/api/routes/managed/_factory.py | Implement managed-sync router factory with PUT “full replace” logic for projects/groups. |
| userapp/api/routes/managed/init.py | Compose managed routers under /managed. |
| userapp/api/routes/groups.py | Change group user listing to view; change add-user payload schema to include managed_by. |
| userapp/api/routes/init.py | Register managed routes with the API router list. |
| userapp/api/load_options.py | Update eager-loading options to follow the new view-backed User.groups relationship. |
| alembic/versions/f2ec55925c4c_external_management_update.py | Migration: create enum type, add columns/indexes, recreate views, backfill users.created_at. |
Comments suppressed due to low confidence (1)
userapp/core/schemas/user_project.py:55
- Same issue for the create schema:
managed_bydefaults toNone, but the column is NOT NULL with a server default. With the currentcreate_one_endpoint()behavior (dumpingNonefields), requests that omitmanaged_bywill still insert NULL and fail. Defaulting this field toEntityManagerEnum.APPLICATION(or omitting it from dumps when unset) would preserve the intended defaulting behavior.
class UserProjectPost(BaseModel):
user_id: int
role: Optional[RoleEnum] = None
is_primary: bool = False
managed_by: Optional[EntityManagerEnum] = None
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
No description provided.