Source code for codegrade.models.confirm_pending_registration_data

"""The module that defines the ``ConfirmPendingRegistrationData`` 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 cg_maybe import Maybe, Nothing
from cg_maybe.utils import maybe_from_nullable

from ..utils import to_dict


[docs] @dataclass class ConfirmPendingRegistrationData: """Input data required for the `Pending Registration::Confirm` operation.""" #: The verification code. code: str #: Username to register. username: str #: Full name of the new user. name: str #: Password (omit for passwordless registration). password: Maybe[str] = Nothing 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( "code", rqa.SimpleValue.str, doc="The verification code.", ), rqa.RequiredArgument( "username", rqa.SimpleValue.str, doc="Username to register.", ), rqa.RequiredArgument( "name", rqa.SimpleValue.str, doc="Full name of the new user.", ), rqa.OptionalArgument( "password", rqa.SimpleValue.str, doc="Password (omit for passwordless registration).", ), ).use_readable_describe(True) ) def __post_init__(self) -> None: getattr(super(), "__post_init__", lambda: None)() self.password = maybe_from_nullable(self.password) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "code": to_dict(self.code), "username": to_dict(self.username), "name": to_dict(self.name), } if self.password.is_just: res["password"] = to_dict(self.password.value) return res @classmethod def from_dict( cls: t.Type[ConfirmPendingRegistrationData], d: t.Dict[str, t.Any] ) -> ConfirmPendingRegistrationData: parsed = cls.data_parser.try_parse(d) res = cls( code=parsed.code, username=parsed.username, name=parsed.name, password=parsed.password, ) res.raw_data = d return res