|
1 | | -from typing import List, Optional, Union |
| 1 | +from typing import Any, List, Optional, Union |
2 | 2 |
|
3 | 3 | from descope._auth_base import AuthBase |
4 | 4 | from descope.auth import Auth |
@@ -327,12 +327,16 @@ def update( |
327 | 327 | """ |
328 | 328 | Update an existing user with the given various fields. IMPORTANT: All parameters are used as overrides |
329 | 329 | to the existing user. Empty fields will override populated fields. Use carefully. |
| 330 | + Use `patch` for partial updates instead. |
330 | 331 |
|
331 | 332 | Args: |
332 | 333 | login_id (str): The login ID of the user to update. |
333 | 334 | email (str): Optional user email address. |
334 | 335 | phone (str): Optional user phone number. |
335 | 336 | display_name (str): Optional user display name. |
| 337 | + given_name (str): Optional user given name. |
| 338 | + middle_name (str): Optional user middle name. |
| 339 | + family_name (str): Optional user family name. |
336 | 340 | role_names (List[str]): An optional list of the user's roles without tenant association. These roles are |
337 | 341 | mutually exclusive with the `user_tenant` roles. |
338 | 342 | user_tenants (List[AssociatedTenant]): An optional list of the user's tenants, and optionally, their roles per tenant. These roles are |
@@ -371,6 +375,66 @@ def update( |
371 | 375 | pswd=self._auth.management_key, |
372 | 376 | ) |
373 | 377 |
|
| 378 | + def patch( |
| 379 | + self, |
| 380 | + login_id: str, |
| 381 | + email: Optional[str] = None, |
| 382 | + phone: Optional[str] = None, |
| 383 | + display_name: Optional[str] = None, |
| 384 | + given_name: Optional[str] = None, |
| 385 | + middle_name: Optional[str] = None, |
| 386 | + family_name: Optional[str] = None, |
| 387 | + role_names: Optional[List[str]] = None, |
| 388 | + user_tenants: Optional[List[AssociatedTenant]] = None, |
| 389 | + picture: Optional[str] = None, |
| 390 | + custom_attributes: Optional[dict] = None, |
| 391 | + verified_email: Optional[bool] = None, |
| 392 | + verified_phone: Optional[bool] = None, |
| 393 | + sso_app_ids: Optional[List[str]] = None, |
| 394 | + ): |
| 395 | + """ |
| 396 | + Patches an existing user with the given various fields. Only the given fields will be used to update the user. |
| 397 | +
|
| 398 | + Args: |
| 399 | + login_id (str): The login ID of the user to update. |
| 400 | + email (str): Optional user email address. |
| 401 | + phone (str): Optional user phone number. |
| 402 | + display_name (str): Optional user display name. |
| 403 | + given_name (str): Optional user given name. |
| 404 | + middle_name (str): Optional user middle name. |
| 405 | + family_name (str): Optional user family name. |
| 406 | + role_names (List[str]): An optional list of the user's roles without tenant association. These roles are |
| 407 | + mutually exclusive with the `user_tenant` roles. |
| 408 | + user_tenants (List[AssociatedTenant]): An optional list of the user's tenants, and optionally, their roles per tenant. These roles are |
| 409 | + mutually exclusive with the general `role_names`. |
| 410 | + picture (str): Optional url for user picture |
| 411 | + custom_attributes (dict): Optional, set the different custom attributes values of the keys that were previously configured in Descope console app |
| 412 | + sso_app_ids (List[str]): Optional, list of SSO applications IDs to be associated with the user. |
| 413 | +
|
| 414 | + Raise: |
| 415 | + AuthException: raised if patch operation fails |
| 416 | + """ |
| 417 | + self._auth.do_patch( |
| 418 | + MgmtV1.user_patch_path, |
| 419 | + User._compose_patch_body( |
| 420 | + login_id, |
| 421 | + email, |
| 422 | + phone, |
| 423 | + display_name, |
| 424 | + given_name, |
| 425 | + middle_name, |
| 426 | + family_name, |
| 427 | + role_names, |
| 428 | + user_tenants, |
| 429 | + picture, |
| 430 | + custom_attributes, |
| 431 | + verified_email, |
| 432 | + verified_phone, |
| 433 | + sso_app_ids, |
| 434 | + ), |
| 435 | + pswd=self._auth.management_key, |
| 436 | + ) |
| 437 | + |
374 | 438 | def delete( |
375 | 439 | self, |
376 | 440 | login_id: str, |
@@ -1616,3 +1680,51 @@ def _compose_update_body( |
1616 | 1680 | if seed is not None: |
1617 | 1681 | res["seed"] = seed |
1618 | 1682 | return res |
| 1683 | + |
| 1684 | + @staticmethod |
| 1685 | + def _compose_patch_body( |
| 1686 | + login_id: str, |
| 1687 | + email: Optional[str], |
| 1688 | + phone: Optional[str], |
| 1689 | + display_name: Optional[str], |
| 1690 | + given_name: Optional[str], |
| 1691 | + middle_name: Optional[str], |
| 1692 | + family_name: Optional[str], |
| 1693 | + role_names: Optional[List[str]], |
| 1694 | + user_tenants: Optional[List[AssociatedTenant]], |
| 1695 | + picture: Optional[str], |
| 1696 | + custom_attributes: Optional[dict], |
| 1697 | + verified_email: Optional[bool], |
| 1698 | + verified_phone: Optional[bool], |
| 1699 | + sso_app_ids: Optional[List[str]], |
| 1700 | + ) -> dict: |
| 1701 | + res: dict[str, Any] = { |
| 1702 | + "loginId": login_id, |
| 1703 | + } |
| 1704 | + if email is not None: |
| 1705 | + res["email"] = email |
| 1706 | + if phone is not None: |
| 1707 | + res["phone"] = phone |
| 1708 | + if display_name is not None: |
| 1709 | + res["displayName"] = display_name |
| 1710 | + if given_name is not None: |
| 1711 | + res["givenName"] = given_name |
| 1712 | + if middle_name is not None: |
| 1713 | + res["middleName"] = middle_name |
| 1714 | + if family_name is not None: |
| 1715 | + res["familyName"] = family_name |
| 1716 | + if role_names is not None: |
| 1717 | + res["roleNames"] = role_names |
| 1718 | + if user_tenants is not None: |
| 1719 | + res["userTenants"] = associated_tenants_to_dict(user_tenants) |
| 1720 | + if picture is not None: |
| 1721 | + res["picture"] = picture |
| 1722 | + if custom_attributes is not None: |
| 1723 | + res["customAttributes"] = custom_attributes |
| 1724 | + if verified_email is not None: |
| 1725 | + res["verifiedEmail"] = verified_email |
| 1726 | + if verified_phone is not None: |
| 1727 | + res["verifiedPhone"] = verified_phone |
| 1728 | + if sso_app_ids is not None: |
| 1729 | + res["ssoAppIds"] = sso_app_ids |
| 1730 | + return res |
0 commit comments