followup recent updates around auth api.

This commit is contained in:
Yoshihiro OKUMURA 2023-10-04 11:30:16 +09:00
parent 905577fe74
commit 79f1b708cb
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2

View File

@ -1,3 +1,4 @@
from dataclasses import field
from typing import Final from typing import Final
import requests import requests
@ -6,14 +7,13 @@ from pydantic.dataclasses import dataclass
from mdrsclient.api.base import BaseApi from mdrsclient.api.base import BaseApi
from mdrsclient.exceptions import UnauthorizedException from mdrsclient.exceptions import UnauthorizedException
from mdrsclient.models import Token, User from mdrsclient.models import Laboratory, Token, User
@dataclass(frozen=True) @dataclass(frozen=True)
class UserAuthResponse(Token): class UserAuthResponse(Token):
is_reviewer: bool | None = None is_reviewer: bool | None = None
laboratory: str | None = None laboratories: list[Laboratory] = field(default_factory=list)
lab_id: int | None = None
class UserApi(BaseApi): class UserApi(BaseApi):
@ -29,7 +29,7 @@ class UserApi(BaseApi):
self._raise_response_error(response) self._raise_response_error(response)
obj = TypeAdapter(UserAuthResponse).validate_python(response.json()) obj = TypeAdapter(UserAuthResponse).validate_python(response.json())
token = Token(access=obj.access, refresh=obj.refresh) token = Token(access=obj.access, refresh=obj.refresh)
laboratory_ids = [obj.lab_id] if obj.lab_id is not None else [] laboratory_ids = list(map(lambda x: x.id, obj.laboratories))
is_reviewer = obj.is_reviewer if obj.is_reviewer is not None else False 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) user = User(id=token.user_id, username=username, laboratory_ids=laboratory_ids, is_reviewer=is_reviewer)
return (user, token) return (user, token)