Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/workos/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ def create_organization_role(
self,
organization_id: str,
*,
slug: str,
slug: Optional[str] = None,
name: str,
description: Optional[str] = None,
resource_type_slug: Optional[str] = None,
) -> SyncOrAsync[OrganizationRole]: ...

def list_organization_roles(
Expand Down Expand Up @@ -474,13 +475,18 @@ def create_organization_role(
self,
organization_id: str,
*,
slug: str,
slug: Optional[str] = None,
name: str,
description: Optional[str] = None,
resource_type_slug: Optional[str] = None,
) -> OrganizationRole:
json: Dict[str, Any] = {"slug": slug, "name": name}
json: Dict[str, Any] = {"name": name}
if slug is not None:
json["slug"] = slug
if description is not None:
json["description"] = description
if resource_type_slug is not None:
json["resource_type_slug"] = resource_type_slug

response = self._http_client.request(
f"authorization/organizations/{organization_id}/roles",
Expand Down Expand Up @@ -1152,13 +1158,18 @@ async def create_organization_role(
self,
organization_id: str,
*,
slug: str,
slug: Optional[str] = None,
name: str,
description: Optional[str] = None,
resource_type_slug: Optional[str] = None,
) -> OrganizationRole:
json: Dict[str, Any] = {"slug": slug, "name": name}
json: Dict[str, Any] = {"name": name}
if slug is not None:
json["slug"] = slug
if description is not None:
json["description"] = description
if resource_type_slug is not None:
json["resource_type_slug"] = resource_type_slug

response = await self._http_client.request(
f"authorization/organizations/{organization_id}/roles",
Expand Down
39 changes: 39 additions & 0 deletions tests/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,45 @@ def test_create_organization_role(
)
assert request_kwargs["json"] == {"slug": "admin", "name": "Admin"}

def test_create_organization_role_without_slug(
self, mock_organization_role, capture_and_mock_http_client_request
):
request_kwargs = capture_and_mock_http_client_request(
self.http_client, mock_organization_role, 201
)

role = syncify(
self.authorization.create_organization_role(
"org_01EHT88Z8J8795GZNQ4ZP1J81T",
name="Admin",
)
)

assert role.id == "role_01ABC"
assert request_kwargs["json"] == {"name": "Admin"}

def test_create_organization_role_with_resource_type_slug(
self, mock_organization_role, capture_and_mock_http_client_request
):
request_kwargs = capture_and_mock_http_client_request(
self.http_client, mock_organization_role, 201
)

syncify(
self.authorization.create_organization_role(
"org_01EHT88Z8J8795GZNQ4ZP1J81T",
slug="admin",
name="Admin",
resource_type_slug="project",
)
)

assert request_kwargs["json"] == {
"slug": "admin",
"name": "Admin",
"resource_type_slug": "project",
}

def test_list_organization_roles(
self, mock_organization_roles, capture_and_mock_http_client_request
):
Expand Down
Loading