Skip to content

feat(org-scope): add helper to resolve organizations managed by a user#21

Open
levigtri wants to merge 7 commits intomainfrom
levigft/obt-220-us-111-a-reusable-helper-that-resolves-which-organizations-a
Open

feat(org-scope): add helper to resolve organizations managed by a user#21
levigtri wants to merge 7 commits intomainfrom
levigft/obt-220-us-111-a-reusable-helper-that-resolves-which-organizations-a

Conversation

@levigtri
Copy link
Collaborator

This PR introduces a reusable helper to resolve which organizations a user manages.

A new module org_scope.py was added with the function get_managed_org_ids,
which queries both OrganizationMember.role="manager" and
Organization.manager_id.

The results are merged and returned as a deduplicated list of organization IDs.
An optional FastAPI dependency was also added along with tests to validate
the organization scope resolution logic.

Add  helper that returns the organization IDs
a user manages. The helper checks both OrganizationMember.role=manager
and Organization.manager_id and returns a deduplicated list of IDs.

Also exposes an optional FastAPI dependency and adds tests for org scope resolution.
@levigtri levigtri requested a review from joaocarvoli March 17, 2026 03:20
@levigtri levigtri self-assigned this Mar 17, 2026


async def get_managed_org_ids(db: AsyncSession, user_id: str) -> list[str]:
"""Return deduplicated org IDs that *user_id* manages.
Copy link
Member

Choose a reason for hiding this comment

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

you should not add comments on the code

db: AsyncSession = Depends(get_db),
user: User = Depends(get_current_user),
) -> list[str]:
"""FastAPI dependency - resolves managed org IDs for the authenticated user."""
Copy link
Member

Choose a reason for hiding this comment

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

comments again


from_members = select(OrganizationMember.organization_id.label("org_id")).where(
OrganizationMember.user_id == user_id,
OrganizationMember.role == "manager",
Copy link
Member

Choose a reason for hiding this comment

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

instead of use a pure string for a static comparison, consider to create an enum like this:

class Roles(Enum):
    MANAGER = "manager"

and in the code you should do something like this: OrganizationMember.role == Roles.MANAGER

Copy link
Member

@joaocarvoli joaocarvoli left a comment

Choose a reason for hiding this comment

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

Try to understand why you did change many files and its previous and current version are the same like the access_control, auth_cache, auth_middleware, config, database and so on... Maybe the reason is the ruff but does not make too much sense because the previous deployed actions were working successfully without issues.

levigtri and others added 3 commits March 17, 2026 15:22
- Introduce Roles enum with MANAGER value
- Replace static string comparison with Roles.MANAGER
- Remove unnecessary comments
* organize imports in org model to satisfy Ruff (I001)
* replace Enum inheritance with StrEnum for MemberRole (UP042)
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.

2 participants