Source code for codegrade.models.email_change_pending_old_confirm

"""The module that defines the ``EmailChangePendingOldConfirm`` 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 EmailChangePendingOldConfirm: """An email change awaiting old-email verification. The user does not have a password, so ownership of the old email must be proven first. Call `confirm_old` with the code sent to the old email address. """ #: The email change session identifier. id: str #: Always `'pending_old_confirm'`. status: t.Literal["pending_old_confirm"] 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( "id", rqa.SimpleValue.str, doc="The email change session identifier.", ), rqa.RequiredArgument( "status", rqa.StringEnum("pending_old_confirm"), doc="Always `'pending_old_confirm'`.", ), ).use_readable_describe(True) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "id": to_dict(self.id), "status": to_dict(self.status), } return res @classmethod def from_dict( cls: t.Type[EmailChangePendingOldConfirm], d: t.Dict[str, t.Any] ) -> EmailChangePendingOldConfirm: parsed = cls.data_parser.try_parse(d) res = cls( id=parsed.id, status=parsed.status, ) res.raw_data = d return res