Source code for codegrade.models.disabled_setting_exception

"""The module that defines the ``DisabledSettingException`` 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 httpx import Response

from .. import parsers
from ..utils import to_dict
from .feature_unavailable_exception import FeatureUnavailableException
from .setting import Setting


[docs] @dataclass(kw_only=True) class DisabledSettingException(FeatureUnavailableException): """Exception raised when a required setting is not enabled.""" #: A unique code identifying the kind of error that occurred. code: t.Literal["DISABLED_SETTING"] #: The setting that is disabled and caused this exception, including its #: current and default value. disabled_setting: Setting raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: FeatureUnavailableException.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "code", rqa.StringEnum("DISABLED_SETTING"), doc="A unique code identifying the kind of error that occurred.", ), rqa.RequiredArgument( "disabled_setting", parsers.ParserFor.make(Setting), doc="The setting that is disabled and caused this exception, including its current and default value.", ), ) ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "code": to_dict(self.code), "disabled_setting": to_dict(self.disabled_setting), "missing_permissions": to_dict(self.missing_permissions), "user_id": to_dict(self.user_id), "message": to_dict(self.message), "description": to_dict(self.description), "request_id": to_dict(self.request_id), } return res @classmethod def from_dict( cls: t.Type[DisabledSettingException], d: t.Dict[str, t.Any], response: t.Optional[Response] = None, ) -> DisabledSettingException: parsed = cls.data_parser.try_parse(d) res = cls( code=parsed.code, disabled_setting=parsed.disabled_setting, missing_permissions=parsed.missing_permissions, user_id=parsed.user_id, message=parsed.message, description=parsed.description, request_id=parsed.request_id, response=response, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): from .base_error import BaseError from .course_permission import CoursePermission from .global_permission import GlobalPermission from .permission_exception import PermissionException from .tenant_permission import TenantPermission