Skip to content
Closed
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
6 changes: 3 additions & 3 deletions tests/test_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,20 @@ def test_get_organization(
assert request_kwargs["method"] == "get"
assert request_kwargs["url"].endswith("/organizations/organization_id")

def test_get_organization_by_lookup_key(
def test_get_organization_by_external_id(
self, mock_organization, capture_and_mock_http_client_request
):
request_kwargs = capture_and_mock_http_client_request(
self.http_client, mock_organization, 200
)

organization = syncify(
self.organizations.get_organization_by_lookup_key(lookup_key="test")
self.organizations.get_organization_by_external_id(external_id="test")
)

assert organization.dict() == mock_organization
assert request_kwargs["method"] == "get"
assert request_kwargs["url"].endswith("/organizations/by_lookup_key/test")
assert request_kwargs["url"].endswith("/organizations/external_id/test")

def test_create_organization_with_domain_data(
self, mock_organization, capture_and_mock_http_client_request
Expand Down
20 changes: 20 additions & 0 deletions tests/test_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,26 @@ def test_get_user(self, mock_user, capture_and_mock_http_client_request):
assert user.profile_picture_url == "https://example.com/profile-picture.jpg"
assert user.last_sign_in_at == "2021-06-25T19:07:33.155Z"

def test_get_user_by_external_id(
self, mock_user, capture_and_mock_http_client_request
):
request_kwargs = capture_and_mock_http_client_request(
self.http_client, mock_user, 200
)

external_id = "external-id"
user = syncify(
self.user_management.get_user_by_external_id(external_id=external_id)
)

assert request_kwargs["url"].endswith(
f"user_management/users/external_id/{external_id}"
)
assert request_kwargs["method"] == "get"
assert user.id == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"
assert user.profile_picture_url == "https://example.com/profile-picture.jpg"
assert user.last_sign_in_at == "2021-06-25T19:07:33.155Z"

def test_list_users_auto_pagination(
self,
mock_users_multiple_pages,
Expand Down
18 changes: 8 additions & 10 deletions workos/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ def get_organization(self, organization_id: str) -> SyncOrAsync[Organization]:
"""
...

def get_organization_by_lookup_key(
self, lookup_key: str
def get_organization_by_external_id(
self, external_id: str
) -> SyncOrAsync[Organization]:
"""Gets details for a single Organization by lookup key
"""Gets details for a single Organization by external id

Args:
lookup_key (str): Organization's lookup key
external_id (str): Organization's external id

Returns:
Organization: Organization response from WorkOS
Expand Down Expand Up @@ -125,7 +125,6 @@ def delete_organization(self, organization_id: str) -> SyncOrAsync[None]:


class Organizations(OrganizationsModule):

_http_client: SyncHTTPClient

def __init__(self, http_client: SyncHTTPClient):
Expand Down Expand Up @@ -167,9 +166,9 @@ def get_organization(self, organization_id: str) -> Organization:

return Organization.model_validate(response)

def get_organization_by_lookup_key(self, lookup_key: str) -> Organization:
def get_organization_by_external_id(self, external_id: str) -> Organization:
response = self._http_client.request(
"organizations/by_lookup_key/{lookup_key}".format(lookup_key=lookup_key),
"organizations/external_id/{external_id}".format(external_id=external_id),
method=REQUEST_METHOD_GET,
)

Expand Down Expand Up @@ -237,7 +236,6 @@ def list_organization_roles(self, organization_id: str) -> RoleList:


class AsyncOrganizations(OrganizationsModule):

_http_client: AsyncHTTPClient

def __init__(self, http_client: AsyncHTTPClient):
Expand Down Expand Up @@ -279,9 +277,9 @@ async def get_organization(self, organization_id: str) -> Organization:

return Organization.model_validate(response)

async def get_organization_by_lookup_key(self, lookup_key: str) -> Organization:
async def get_organization_by_external_id(self, external_id: str) -> Organization:
response = await self._http_client.request(
"organizations/by_lookup_key/{lookup_key}".format(lookup_key=lookup_key),
"organizations/external_id/{external_id}".format(external_id=external_id),
method=REQUEST_METHOD_GET,
)

Expand Down
2 changes: 1 addition & 1 deletion workos/types/organizations/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
class Organization(OrganizationCommon):
allow_profiles_outside_organization: bool
domains: Sequence[OrganizationDomain]
lookup_key: Optional[str] = None
stripe_customer_id: Optional[str] = None
external_id: Optional[str] = None
1 change: 1 addition & 0 deletions workos/types/user_management/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ class User(WorkOSModel):
last_sign_in_at: Optional[str] = None
created_at: str
updated_at: str
external_id: Optional[str] = None
28 changes: 27 additions & 1 deletion workos/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

USER_PATH = "user_management/users"
USER_DETAIL_PATH = "user_management/users/{0}"
USER_DETAIL_BY_EXTERNAL_ID_PATH = "user_management/users/external_id/{0}"
ORGANIZATION_MEMBERSHIP_PATH = "user_management/organization_memberships"
ORGANIZATION_MEMBERSHIP_DETAIL_PATH = "user_management/organization_memberships/{0}"
ORGANIZATION_MEMBERSHIP_DEACTIVATE_PATH = (
Expand Down Expand Up @@ -137,6 +138,16 @@ def get_user(self, user_id: str) -> SyncOrAsync[User]:
"""
...

def get_user_by_external_id(self, external_id: str) -> SyncOrAsync[User]:
"""Get the details of an existing user.

Args:
external_id (str): The user's external id
Returns:
User: User response from WorkOS.
"""
...

def list_users(
self,
*,
Expand Down Expand Up @@ -389,7 +400,6 @@ def get_authorization_url(
)

if connection_id is not None:

params["connection_id"] = connection_id
if organization_id is not None:
params["organization_id"] = organization_id
Expand Down Expand Up @@ -860,6 +870,14 @@ def get_user(self, user_id: str) -> User:

return User.model_validate(response)

def get_user_by_external_id(self, external_id: str) -> User:
response = self._http_client.request(
USER_DETAIL_BY_EXTERNAL_ID_PATH.format(external_id),
method=REQUEST_METHOD_GET,
)

return User.model_validate(response)

def list_users(
self,
*,
Expand Down Expand Up @@ -1464,6 +1482,14 @@ async def get_user(self, user_id: str) -> User:

return User.model_validate(response)

async def get_user_by_external_id(self, external_id: str) -> User:
response = await self._http_client.request(
USER_DETAIL_BY_EXTERNAL_ID_PATH.format(external_id),
method=REQUEST_METHOD_GET,
)

return User.model_validate(response)

async def list_users(
self,
*,
Expand Down