|
10 | 10 | import dataclasses |
11 | 11 | import datetime |
12 | 12 | import enum |
| 13 | +import hashlib |
13 | 14 | import os |
14 | 15 | import pathlib |
15 | 16 | from collections.abc import AsyncIterable, Callable, Iterable, Iterator, Mapping, MutableMapping |
@@ -417,7 +418,7 @@ def __init__( |
417 | 418 | super().__init__(_client) |
418 | 419 | self.user_id = user_id |
419 | 420 | self.username = username |
420 | | - self.password = password |
| 421 | + self.password = hashlib.sha256(password.encode()) if password else None |
421 | 422 | self.email = email |
422 | 423 | self.groups = groups or [] |
423 | 424 | self.created_date: datetime.datetime = created_date or datetime.datetime.now( |
@@ -449,9 +450,29 @@ def from_dict( |
449 | 450 | into.metadata = Metadata.from_dict(data.get("metadata"), parent=into, _client=_client) |
450 | 451 | return into |
451 | 452 |
|
| 453 | + def to_dict(self) -> models.User: |
| 454 | + return models.User( |
| 455 | + id=self.user_id, |
| 456 | + username=self.username, |
| 457 | + email=self.email, |
| 458 | + groups=self.groups, |
| 459 | + type=self.user_type, |
| 460 | + is_admin=self.is_admin, |
| 461 | + is_system=self.is_system, |
| 462 | + is_third_party=self.is_third_party, |
| 463 | + deleted=self.deleted, |
| 464 | + metadata=self.metadata.to_dict(), |
| 465 | + password=self.password.hexdigest() if self.password else None |
| 466 | + ) |
| 467 | + |
452 | 468 | def path_prefix(self) -> str: |
453 | 469 | return f"/user/{self.user_id}" |
454 | 470 |
|
| 471 | + async def save(self) -> None: |
| 472 | + """Save this user.""" |
| 473 | + path = "/user" |
| 474 | + result = cast(models.User, await self.client.post(path, body=self.to_dict())) |
| 475 | + self.from_dict(result, into=self, _client=self.client) |
455 | 476 |
|
456 | 477 | class MediaObjectStatus(enum.Enum): |
457 | 478 | """Describes the status of a media object.""" |
|
0 commit comments