Source code for codegrade.models.logout_user_data

"""The module that defines the ``LogoutUserData`` model.

SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""

from __future__ import annotations

import typing as t
from dataclasses import dataclass, field

import cg_request_args as rqa

from ..utils import to_dict


[docs] @dataclass class LogoutUserData: """Input data required for the `User::Logout` operation.""" #: The token you want to invalidate token: str #: Set to "true" to revoke even when an active isolated session exists, #: which will terminate all sessions. confirm_session_termination: t.Literal["false", "true"] = "false" raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: rqa.FixedMapping( rqa.RequiredArgument( "token", rqa.SimpleValue.str, doc="The token you want to invalidate", ), rqa.DefaultArgument( "confirm_session_termination", rqa.StringEnum("false", "true"), doc='Set to "true" to revoke even when an active isolated session exists, which will terminate all sessions.', default=lambda: "false", ), ).use_readable_describe(True) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "token": to_dict(self.token), "confirm_session_termination": to_dict( self.confirm_session_termination ), } return res @classmethod def from_dict( cls: t.Type[LogoutUserData], d: t.Dict[str, t.Any] ) -> LogoutUserData: parsed = cls.data_parser.try_parse(d) res = cls( token=parsed.token, confirm_session_termination=parsed.confirm_session_termination, ) res.raw_data = d return res