follow changes to auth api on 2023-05-22.

This commit is contained in:
Yoshihiro OKUMURA 2023-05-22 13:46:19 +09:00
parent 837f035bc1
commit 9d62d3fb6a
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2
2 changed files with 8 additions and 5 deletions

View File

@ -11,8 +11,9 @@ from mdrsclient.models import Token, User
@dataclass(frozen=True) @dataclass(frozen=True)
class UserAuthResponse(Token): class UserAuthResponse(Token):
laboratory: str is_reviewer: bool | None = None
lab_id: int laboratory: str | None = None
lab_id: int | None = None
class UserApi(BaseApi): class UserApi(BaseApi):
@ -28,7 +29,9 @@ class UserApi(BaseApi):
self._raise_response_error(response) self._raise_response_error(response)
obj = parse_obj_as(UserAuthResponse, response.json()) obj = parse_obj_as(UserAuthResponse, response.json())
token = Token(access=obj.access, refresh=obj.refresh) token = Token(access=obj.access, refresh=obj.refresh)
user = User(id=token.user_id, username=username, laboratory_id=obj.lab_id, laboratory=obj.laboratory) laboratory_ids = [obj.lab_id] if obj.lab_id is not None else []
is_reviewer = obj.is_reviewer if obj.is_reviewer is not None else False
user = User(id=token.user_id, username=username, laboratory_ids=laboratory_ids, is_reviewer=is_reviewer)
return (user, token) return (user, token)
def refresh(self, token: Token) -> Token: def refresh(self, token: Token) -> Token:

View File

@ -46,5 +46,5 @@ class Token:
class User: class User:
id: int id: int
username: str username: str
laboratory_id: int laboratory_ids: list[int]
laboratory: str is_reviewer: bool