Skip to content

Entity management#17

Merged
CannonLock merged 6 commits into
mainfrom
entity-management
May 21, 2026
Merged

Entity management#17
CannonLock merged 6 commits into
mainfrom
entity-management

Conversation

@CannonLock
Copy link
Copy Markdown
Member

No description provided.

@CannonLock CannonLock requested a review from Copilot May 21, 2026 15:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EntityManagerEnum plus managed_by/timestamps on user_projects and user_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}/users and /managed/{manager}/groups/{id}/users PUT 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_by defaults to None, but the column is NOT NULL with a server default. With the current create_one_endpoint() behavior (dumping None fields), requests that omit managed_by will still insert NULL and fail. Defaulting this field to EntityManagerEnum.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.

Comment thread userapp/core/schemas/user_project.py
Comment thread userapp/core/models/tables.py Outdated
Comment thread userapp/core/schemas/general.py
Comment thread userapp/api/routes/groups.py
Comment thread userapp/api/routes/users.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@CannonLock CannonLock merged commit 13e0bec into main May 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants