feat: FGA_5 list_resources_for_membership, list_memberships_for_resource, list_memberships_for_resource_by_external_id#571
Conversation
…list_memberships_for_resource_by_external_id
|
@greptile review |
|
@greptile re-review |
csrbarber
left a comment
There was a problem hiding this comment.
#556 (comment) is relevant to this PR
|
@greptile re-review plz |
Greptile SummaryThis PR adds three new FGA methods to the Key changes:
Minor issues found:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant Authorization
participant HTTPClient
participant WorkOSAPI
Note over Caller,WorkOSAPI: list_resources_for_membership
Caller->>Authorization: list_resources_for_membership(org_membership_id, permission_slug, parent_resource)
Authorization->>HTTPClient: GET /authorization/organization_memberships/{id}/resources?permission_slug=...&parent_resource_id=...
HTTPClient->>WorkOSAPI: HTTP GET
WorkOSAPI-->>HTTPClient: paginated AuthorizationResource list
HTTPClient-->>Authorization: response dict
Authorization-->>Caller: WorkOSListResource[AuthorizationResource]
Note over Caller,WorkOSAPI: list_memberships_for_resource
Caller->>Authorization: list_memberships_for_resource(resource_id, permission_slug, assignment?)
Authorization->>HTTPClient: GET /authorization/resources/{id}/organization_memberships?permission_slug=...
HTTPClient->>WorkOSAPI: HTTP GET
WorkOSAPI-->>HTTPClient: paginated OrganizationMembership list
HTTPClient-->>Authorization: response dict
Authorization-->>Caller: WorkOSListResource[AuthorizationOrganizationMembership]
Note over Caller,WorkOSAPI: list_memberships_for_resource_by_external_id
Caller->>Authorization: list_memberships_for_resource_by_external_id(org_id, resource_type_slug, external_id, permission_slug)
Authorization->>HTTPClient: GET /authorization/organizations/{org_id}/resources/{type}/{ext_id}/organization_memberships
HTTPClient->>WorkOSAPI: HTTP GET
WorkOSAPI-->>HTTPClient: paginated OrganizationMembership list
HTTPClient-->>Authorization: response dict
Authorization-->>Caller: WorkOSListResource[AuthorizationOrganizationMembership]
Last reviewed commit: a973327 |
| def _mock_membership( | ||
| membership_id: str = "om_01ABC", | ||
| user_id: str = "user_123", | ||
| organization_id: str = "org_456", | ||
| organization_name: str = "Acme Inc", | ||
| status: str = "active", | ||
| ) -> dict: | ||
| return { | ||
| "object": "organization_membership", | ||
| "id": membership_id, | ||
| "user_id": user_id, | ||
| "organization_id": organization_id, | ||
| "organization_name": organization_name, | ||
| "status": status, | ||
| "custom_attributes": None, | ||
| "created_at": "2024-01-01T00:00:00Z", | ||
| "updated_at": "2024-01-01T00:00:00Z", | ||
| } |
There was a problem hiding this comment.
Unused helper function
The _mock_membership function is defined but never called anywhere in the test file. The tests instead rely on MockAuthorizationOrganizationMembershipList directly via the mock_memberships_list_two fixture. This dead code should either be removed or used in a test case.
| def _mock_membership( | |
| membership_id: str = "om_01ABC", | |
| user_id: str = "user_123", | |
| organization_id: str = "org_456", | |
| organization_name: str = "Acme Inc", | |
| status: str = "active", | |
| ) -> dict: | |
| return { | |
| "object": "organization_membership", | |
| "id": membership_id, | |
| "user_id": user_id, | |
| "organization_id": organization_id, | |
| "organization_name": organization_name, | |
| "status": status, | |
| "custom_attributes": None, | |
| "created_at": "2024-01-01T00:00:00Z", | |
| "updated_at": "2024-01-01T00:00:00Z", | |
| } |
(Remove lines 16–33 entirely)
There was a problem hiding this comment.
is it expected that this is not used?
There was a problem hiding this comment.
No, it's not expected - this is genuinely unused code. After reviewing the full test file, all tests rely on the mock_memberships_list_two fixture which returns MockAuthorizationOrganizationMembershipList().model_dump(). The _mock_membership helper function is never called anywhere.
Looking at similar test files in the codebase (like test_authorization_resource.py), they follow the same pattern: using fixture-based mock objects from classes like MockAuthorizationResource() rather than helper functions. The _mock_membership function appears to be leftover code that was either never used or replaced by the fixture approach.
You should remove it.
|
|
||
| @pytest.fixture | ||
| def mock_resources_list_two(self): | ||
| return MockAuthorizationResourceList().dict() |
There was a problem hiding this comment.
Deprecated .dict() instead of .model_dump()
.dict() is a Pydantic v1 alias and is deprecated in Pydantic v2. The sibling fixture in TestListMembershipsForResource already uses .model_dump() correctly (line 446). Use .model_dump() here for consistency and to avoid deprecation warnings.
| return MockAuthorizationResourceList().dict() | |
| return MockAuthorizationResourceList().model_dump() |
src/workos/authorization.py
Outdated
| parent_resource_type_slug: str | ||
| class AuthorizationOrganizationMembershipListFilters(ListArgs, total=False): | ||
| permission_slug: str | ||
| assignment: Optional[Literal["direct", "indirect"]] |
There was a problem hiding this comment.
Might be worth making assignment a type since we'll most likely add it to the list resources for membership endpoint soon.
There was a problem hiding this comment.
Also referenced a few places so we won't have to redeclare the literals
| def _mock_membership( | ||
| membership_id: str = "om_01ABC", | ||
| user_id: str = "user_123", | ||
| organization_id: str = "org_456", | ||
| organization_name: str = "Acme Inc", | ||
| status: str = "active", | ||
| ) -> dict: | ||
| return { | ||
| "object": "organization_membership", | ||
| "id": membership_id, | ||
| "user_id": user_id, | ||
| "organization_id": organization_id, | ||
| "organization_name": organization_name, | ||
| "status": status, | ||
| "custom_attributes": None, | ||
| "created_at": "2024-01-01T00:00:00Z", | ||
| "updated_at": "2024-01-01T00:00:00Z", | ||
| } |
There was a problem hiding this comment.
is it expected that this is not used?
|
|
||
| @pytest.fixture | ||
| def mock_resources_list_two(self): | ||
| return MockAuthorizationResourceList().dict() |
|
|
||
| assert response.object == "list" | ||
| assert len(response.data) == 2 | ||
| assert response.data[0].id == "om_01ABC" |
There was a problem hiding this comment.
worth checking all other fields are deserialized on these happy path tests?
08f1c84
into
ENT-5224-python-sdk-for-fga-worktree-fuck-around
…list_memberships_for_resource_by_external_id
Description
Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.