Source code for codegrade.models.provider_description

"""The module that defines the ``ProviderDescription`` 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(kw_only=True) class ProviderDescription: """The management-facing description of an exam environment provider. Everything here is a pure attribute read off a cheaply-constructed provider instance (see :func:`_describe_provider`), so the description cannot drift from what the provider actually implements. """ #: The provider's config tag; the value the panel submits back as #: `proctoring.tag` on save. tag: t.Literal["schoolyear"] #: The provider's human-readable name; the dropdown option label, never #: hardcoded in the SPA. display_name: str #: Whether the provider exposes a deep link to an external dashboard. has_teacher_ui_dashboard: bool #: Whether the provider exposes a deep link to external exam settings. has_teacher_ui_exam_settings: bool #: Whether the provider requires an entry window to be configured. requires_entry_window: bool #: Whether the provider requires idle session detection to be enabled. requires_idle_session_detection: bool #: Whether per-student entry-window overrides may be used while this #: provider is attached. has_student_entry_window_override: bool 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( "tag", rqa.StringEnum("schoolyear"), doc="The provider's config tag; the value the panel submits back as `proctoring.tag` on save.", ), rqa.RequiredArgument( "display_name", rqa.SimpleValue.str, doc="The provider's human-readable name; the dropdown option label, never hardcoded in the SPA.", ), rqa.RequiredArgument( "has_teacher_ui_dashboard", rqa.SimpleValue.bool, doc="Whether the provider exposes a deep link to an external dashboard.", ), rqa.RequiredArgument( "has_teacher_ui_exam_settings", rqa.SimpleValue.bool, doc="Whether the provider exposes a deep link to external exam settings.", ), rqa.RequiredArgument( "requires_entry_window", rqa.SimpleValue.bool, doc="Whether the provider requires an entry window to be configured.", ), rqa.RequiredArgument( "requires_idle_session_detection", rqa.SimpleValue.bool, doc="Whether the provider requires idle session detection to be enabled.", ), rqa.RequiredArgument( "has_student_entry_window_override", rqa.SimpleValue.bool, doc="Whether per-student entry-window overrides may be used while this provider is attached.", ), ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "tag": to_dict(self.tag), "display_name": to_dict(self.display_name), "has_teacher_ui_dashboard": to_dict(self.has_teacher_ui_dashboard), "has_teacher_ui_exam_settings": to_dict( self.has_teacher_ui_exam_settings ), "requires_entry_window": to_dict(self.requires_entry_window), "requires_idle_session_detection": to_dict( self.requires_idle_session_detection ), "has_student_entry_window_override": to_dict( self.has_student_entry_window_override ), } return res @classmethod def from_dict( cls: t.Type[ProviderDescription], d: t.Dict[str, t.Any] ) -> ProviderDescription: parsed = cls.data_parser.try_parse(d) res = cls( tag=parsed.tag, display_name=parsed.display_name, has_teacher_ui_dashboard=parsed.has_teacher_ui_dashboard, has_teacher_ui_exam_settings=parsed.has_teacher_ui_exam_settings, requires_entry_window=parsed.requires_entry_window, requires_idle_session_detection=parsed.requires_idle_session_detection, has_student_entry_window_override=parsed.has_student_entry_window_override, ) res.raw_data = d return res