|
1 | 1 | from __future__ import annotations |
2 | | -from typing import List, Optional |
| 2 | +from typing import List, overload |
3 | 3 |
|
4 | 4 |
|
5 | 5 | import requests |
@@ -91,41 +91,60 @@ def unlock(self): |
91 | 91 | self.session.post(url, json=body) |
92 | 92 | super().update(locked=False) |
93 | 93 |
|
94 | | - def _update(self, body): |
95 | | - if len(body) == 0: |
96 | | - return |
| 94 | + @overload |
| 95 | + def update( |
| 96 | + self, |
| 97 | + email: str = ..., |
| 98 | + username: str = ..., |
| 99 | + first_name: str = ..., |
| 100 | + last_name: str = ..., |
| 101 | + user_role: str = ..., |
| 102 | + ) -> None: |
| 103 | + """ |
| 104 | + Update the user. |
| 105 | +
|
| 106 | + Args: |
| 107 | + email (str): The email address for the user. |
| 108 | + username (str): The username for the user. |
| 109 | + first_name (str): The first name for the user. |
| 110 | + last_name (str): The last name for the user. |
| 111 | + user_role (str): The role for the user. |
| 112 | +
|
| 113 | + Returns: |
| 114 | + None |
| 115 | + """ |
| 116 | + ... |
| 117 | + |
| 118 | + @overload |
| 119 | + def update(self, *args, **kwargs) -> None: |
| 120 | + """ |
| 121 | + Update the user. |
| 122 | +
|
| 123 | + Args: |
| 124 | + *args |
| 125 | + **kwargs |
| 126 | +
|
| 127 | + Returns: |
| 128 | + None |
| 129 | + """ |
| 130 | + ... |
| 131 | + |
| 132 | + def update(self, *args, **kwargs) -> None: |
| 133 | + """ |
| 134 | + Update the user. |
| 135 | +
|
| 136 | + Args: |
| 137 | + *args |
| 138 | + **kwargs |
| 139 | +
|
| 140 | + Returns: |
| 141 | + None |
| 142 | + """ |
| 143 | + body = dict(*args, **kwargs) |
97 | 144 | url = urls.append_path(self.config.url, f"v1/users/{self.guid}") |
98 | 145 | response = self.session.put(url, json=body) |
99 | 146 | super().update(**response.json()) |
100 | 147 |
|
101 | | - def update( # type: ignore |
102 | | - self, |
103 | | - # Not all properties are settable, so we enumerate them here |
104 | | - # (also for type-hinting purposes) |
105 | | - email: Optional[str] = None, |
106 | | - username: Optional[str] = None, |
107 | | - first_name: Optional[str] = None, |
108 | | - last_name: Optional[str] = None, |
109 | | - user_role: Optional[str] = None, |
110 | | - # TODO(#100): in the API, this goes via POST /v1/users/{guid}/lock |
111 | | - # accept it here and make that request? Or add a .lock() method? |
112 | | - # locked: Optional[bool] = None, |
113 | | - ) -> None: |
114 | | - kwargs = {} |
115 | | - if email is not None: |
116 | | - kwargs["email"] = email |
117 | | - if username is not None: |
118 | | - kwargs["username"] = username |
119 | | - if first_name is not None: |
120 | | - kwargs["first_name"] = first_name |
121 | | - if last_name is not None: |
122 | | - kwargs["last_name"] = last_name |
123 | | - if user_role is not None: |
124 | | - kwargs["user_role"] = user_role |
125 | | - # if locked is not None: |
126 | | - # kwargs["locked"] = locked |
127 | | - self._update(kwargs) |
128 | | - |
129 | 148 |
|
130 | 149 | class Users(Resources[User]): |
131 | 150 | def __init__(self, config: Config, session: requests.Session) -> None: |
|
0 commit comments