|
@@ -161,6 +161,38 @@ class Person(NamedTuple):
|
161
|
161
|
LOG.exception(e)
|
162
|
162
|
return NetworkError.InvalidData
|
163
|
163
|
|
|
164
|
+ def rename(
|
|
165
|
+ self, new_full_name: Optional[str], new_display_name: Optional[str]
|
|
166
|
+ ) -> Optional[Person]:
|
|
167
|
+ person_payload: Dict[str, str] = {}
|
|
168
|
+
|
|
169
|
+ if new_full_name is not None:
|
|
170
|
+ person_payload["full_name"] = new_full_name
|
|
171
|
+
|
|
172
|
+ if new_display_name is not None:
|
|
173
|
+ person_payload["display_name"] = new_display_name
|
|
174
|
+
|
|
175
|
+ req = requests.patch(
|
|
176
|
+ urljoin(SERVER_URL, f"people/{self.person_id}"),
|
|
177
|
+ json={"person": person_payload},
|
|
178
|
+ )
|
|
179
|
+
|
|
180
|
+ try:
|
|
181
|
+ data = req.json()
|
|
182
|
+ except ValueError:
|
|
183
|
+ LOG.error(
|
|
184
|
+ "Did not get JSON on updating Person (%s): %s",
|
|
185
|
+ req.status_code,
|
|
186
|
+ req.content,
|
|
187
|
+ )
|
|
188
|
+ return None
|
|
189
|
+
|
|
190
|
+ if "error" in data or req.status_code != 200:
|
|
191
|
+ LOG.error("Could not update Person (%s): %s", req.status_code, data)
|
|
192
|
+ return None
|
|
193
|
+
|
|
194
|
+ return Person.from_dict(data["person"])
|
|
195
|
+
|
164
|
196
|
def set_active(self, new_state=True) -> Optional[Person]:
|
165
|
197
|
req = requests.patch(
|
166
|
198
|
urljoin(SERVER_URL, f"people/{self.person_id}"),
|
|
@@ -622,7 +654,9 @@ class AardbeiPeopleDiff:
|
622
|
654
|
return cls(**data)
|
623
|
655
|
|
624
|
656
|
@classmethod
|
625
|
|
- def get_diff(cls, token: str, endpoint: str) -> Union[AardbeiPeopleDiff, NetworkError]:
|
|
657
|
+ def get_diff(
|
|
658
|
+ cls, token: str, endpoint: str
|
|
659
|
+ ) -> Union[AardbeiPeopleDiff, NetworkError]:
|
626
|
660
|
try:
|
627
|
661
|
req = requests.post(
|
628
|
662
|
urljoin(SERVER_URL, "/aardbei/diff_people"),
|