Skip to content

Commit a906ec2

Browse files
moar
2 parents 63f2f60 + a5823c6 commit a906ec2

File tree

7 files changed

+72
-28
lines changed

7 files changed

+72
-28
lines changed

.claude/settings.local.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(uv run mypy:*)"
5+
]
6+
}
7+
}

src/workos/authorization.py

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@
3030

3131
AUTHORIZATION_PERMISSIONS_PATH = "authorization/permissions"
3232
AUTHORIZATION_ORGANIZATIONS_PATH = "authorization/organizations"
33+
AUTHORIZATION_RESOURCES_PATH = "authorization/resources"
3334

3435

3536
class ResourceListFilters(ListArgs, total=False):
36-
organization_id: str
37+
organization_id: Optional[str]
3738
resource_type_slug: Optional[str]
39+
parent_resource_id: Optional[str]
40+
parent_resource_type_slug: Optional[str]
41+
parent_external_id: Optional[str]
42+
search: Optional[str]
3843

3944

4045
ResourcesListResource = WorkOSListResource[Resource, ResourceListFilters, ListMetadata]
@@ -201,9 +206,13 @@ def delete_resource_by_external_id(
201206

202207
def list_resources(
203208
self,
204-
organization_id: str,
205209
*,
210+
organization_id: Optional[str] = None,
206211
resource_type_slug: Optional[str] = None,
212+
parent_resource_id: Optional[str] = None,
213+
parent_resource_type_slug: Optional[str] = None,
214+
parent_external_id: Optional[str] = None,
215+
search: Optional[str] = None,
207216
limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
208217
before: Optional[str] = None,
209218
after: Optional[str] = None,
@@ -545,30 +554,41 @@ def delete_resource_by_external_id(
545554

546555
def list_resources(
547556
self,
548-
organization_id: str,
549557
*,
558+
organization_id: Optional[str] = None,
550559
resource_type_slug: Optional[str] = None,
560+
parent_resource_id: Optional[str] = None,
561+
parent_resource_type_slug: Optional[str] = None,
562+
parent_external_id: Optional[str] = None,
563+
search: Optional[str] = None,
551564
limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
552565
before: Optional[str] = None,
553566
after: Optional[str] = None,
554567
order: PaginationOrder = "desc",
555568
) -> ResourcesListResource:
556569
list_params: ResourceListFilters = {
557-
"organization_id": organization_id,
558570
"limit": limit,
559571
"before": before,
560572
"after": after,
561573
"order": order,
562574
}
575+
if organization_id is not None:
576+
list_params["organization_id"] = organization_id
563577
if resource_type_slug is not None:
564578
list_params["resource_type_slug"] = resource_type_slug
565-
566-
query_params = {k: v for k, v in list_params.items() if k != "organization_id"}
579+
if parent_resource_id is not None:
580+
list_params["parent_resource_id"] = parent_resource_id
581+
if parent_resource_type_slug is not None:
582+
list_params["parent_resource_type_slug"] = parent_resource_type_slug
583+
if parent_external_id is not None:
584+
list_params["parent_external_id"] = parent_external_id
585+
if search is not None:
586+
list_params["search"] = search
567587

568588
response = self._http_client.request(
569-
f"{AUTHORIZATION_ORGANIZATIONS_PATH}/{organization_id}/resources",
589+
AUTHORIZATION_RESOURCES_PATH,
570590
method=REQUEST_METHOD_GET,
571-
params=query_params,
591+
params=list_params,
572592
)
573593

574594
return WorkOSListResource[Resource, ResourceListFilters, ListMetadata](
@@ -912,30 +932,41 @@ async def delete_resource_by_external_id(
912932

913933
async def list_resources(
914934
self,
915-
organization_id: str,
916935
*,
936+
organization_id: Optional[str] = None,
917937
resource_type_slug: Optional[str] = None,
938+
parent_resource_id: Optional[str] = None,
939+
parent_resource_type_slug: Optional[str] = None,
940+
parent_external_id: Optional[str] = None,
941+
search: Optional[str] = None,
918942
limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
919943
before: Optional[str] = None,
920944
after: Optional[str] = None,
921945
order: PaginationOrder = "desc",
922946
) -> ResourcesListResource:
923947
list_params: ResourceListFilters = {
924-
"organization_id": organization_id,
925948
"limit": limit,
926949
"before": before,
927950
"after": after,
928951
"order": order,
929952
}
953+
if organization_id is not None:
954+
list_params["organization_id"] = organization_id
930955
if resource_type_slug is not None:
931956
list_params["resource_type_slug"] = resource_type_slug
932-
933-
query_params = {k: v for k, v in list_params.items() if k != "organization_id"}
957+
if parent_resource_id is not None:
958+
list_params["parent_resource_id"] = parent_resource_id
959+
if parent_resource_type_slug is not None:
960+
list_params["parent_resource_type_slug"] = parent_resource_type_slug
961+
if parent_external_id is not None:
962+
list_params["parent_external_id"] = parent_external_id
963+
if search is not None:
964+
list_params["search"] = search
934965

935966
response = await self._http_client.request(
936-
f"{AUTHORIZATION_ORGANIZATIONS_PATH}/{organization_id}/resources",
967+
AUTHORIZATION_RESOURCES_PATH,
937968
method=REQUEST_METHOD_GET,
938-
params=query_params,
969+
params=list_params,
939970
)
940971

941972
return WorkOSListResource[Resource, ResourceListFilters, ListMetadata](

src/workos/types/authorization/organization_membership.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from typing import Any, Literal, Mapping, Optional
22

3+
from workos.types.user_management.organization_membership_status import (
4+
OrganizationMembershipStatus,
5+
)
36
from workos.types.workos_model import WorkOSModel
47
from workos.typing.literals import LiteralOrUntyped
58

6-
OrganizationMembershipStatus = Literal["active", "inactive", "pending"]
7-
89

910
class AuthorizationOrganizationMembership(WorkOSModel):
1011
"""Representation of an Organization Membership returned by Authorization endpoints.

src/workos/types/user_management/list_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional, Sequence
22
from workos.types.list_resource import ListArgs
3-
from workos.types.user_management.organization_membership import (
3+
from workos.types.user_management.organization_membership_status import (
44
OrganizationMembershipStatus,
55
)
66

src/workos/types/user_management/organization_membership.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Any, Literal, Mapping, Optional, Sequence
22
from typing_extensions import TypedDict
33

4+
from workos.types.user_management.organization_membership_status import (
5+
OrganizationMembershipStatus,
6+
)
47
from workos.types.workos_model import WorkOSModel
58
from workos.typing.literals import LiteralOrUntyped
69

7-
OrganizationMembershipStatus = Literal["active", "inactive", "pending"]
8-
910

1011
class OrganizationMembershipRole(TypedDict):
1112
slug: str
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from typing import Literal
2+
3+
OrganizationMembershipStatus = Literal["active", "inactive", "pending"]

tests/test_authorization_resource_external_id.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ def test_list_resources_with_results(
197197
self.http_client, mock_resources_list, 200
198198
)
199199

200-
resources_response = syncify(self.authorization.list_resources(MOCK_ORG_ID))
200+
resources_response = syncify(
201+
self.authorization.list_resources(organization_id=MOCK_ORG_ID)
202+
)
201203

202204
assert request_kwargs["method"] == "get"
203-
assert request_kwargs["url"].endswith(
204-
f"/authorization/organizations/{MOCK_ORG_ID}/resources"
205-
)
206-
assert "organization_id" not in request_kwargs["params"]
205+
assert request_kwargs["url"].endswith("/authorization/resources")
206+
assert request_kwargs["params"]["organization_id"] == MOCK_ORG_ID
207207
assert len(resources_response.data) == 1
208208
assert resources_response.data[0].id == "res_01ABC"
209209

@@ -214,7 +214,9 @@ def test_list_resources_empty_results(
214214
self.http_client, mock_resources_empty_list, 200
215215
)
216216

217-
resources_response = syncify(self.authorization.list_resources(MOCK_ORG_ID))
217+
resources_response = syncify(
218+
self.authorization.list_resources(organization_id=MOCK_ORG_ID)
219+
)
218220

219221
assert request_kwargs["method"] == "get"
220222
assert len(resources_response.data) == 0
@@ -228,7 +230,7 @@ def test_list_resources_with_resource_type_slug_filter(
228230

229231
syncify(
230232
self.authorization.list_resources(
231-
MOCK_ORG_ID, resource_type_slug="document"
233+
organization_id=MOCK_ORG_ID, resource_type_slug="document"
232234
)
233235
)
234236

@@ -244,7 +246,7 @@ def test_list_resources_with_pagination_params(
244246

245247
syncify(
246248
self.authorization.list_resources(
247-
MOCK_ORG_ID,
249+
organization_id=MOCK_ORG_ID,
248250
limit=5,
249251
after="res_cursor_abc",
250252
before="res_cursor_xyz",
@@ -267,5 +269,4 @@ def test_list_resources_auto_pagination(
267269
list_function=self.authorization.list_resources,
268270
expected_all_page_data=mock_resources_multiple,
269271
list_function_params={"organization_id": MOCK_ORG_ID},
270-
url_path_keys=["organization_id"],
271272
)

0 commit comments

Comments
 (0)