Source code for codegrade.models.restriction_with_effective_window
"""The module that defines the ``RestrictionWithEffectiveWindow`` 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 .. import parsers
from ..utils import to_dict
from .entry_window import EntryWindow
from .restriction import Restriction
[docs]
@dataclass(kw_only=True)
class RestrictionWithEffectiveWindow(Restriction):
"""A restriction plus the requesting user's effective entry window.
`session_lockdown.entry_window` (inherited) is always the global configured
window; `effective_entry_window` is this user's override-resolved window,
`None` when the feature is off, there is no session lockdown, or no
complete window resolves.
"""
#: The requesting user's override-resolved entry window, or `None` when the
#: feature is off, there is no session lockdown, or no complete window
#: resolves.
effective_entry_window: t.Optional[EntryWindow]
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar[t.Any] = rqa.Lazy(
lambda: Restriction.data_parser.parser.combine(
rqa.FixedMapping(
rqa.RequiredArgument(
"effective_entry_window",
rqa.Nullable(parsers.ParserFor.make(EntryWindow)),
doc="The requesting user's override-resolved entry window, or `None` when the feature is off, there is no session lockdown, or no complete window resolves.",
),
)
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"effective_entry_window": to_dict(self.effective_entry_window),
"id": to_dict(self.id),
"session_lockdown": to_dict(self.session_lockdown),
"password": to_dict(self.password),
}
return res
@classmethod
def from_dict(
cls: t.Type[RestrictionWithEffectiveWindow], d: t.Dict[str, t.Any]
) -> RestrictionWithEffectiveWindow:
parsed = cls.data_parser.try_parse(d)
res = cls(
effective_entry_window=parsed.effective_entry_window,
id=parsed.id,
session_lockdown=parsed.session_lockdown,
password=parsed.password,
)
res.raw_data = d
return res
import os
if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"):
from .restriction_mixin import RestrictionMixin
from .restriction_mixin_not_set_password import (
RestrictionMixinNotSetPassword,
)
from .restriction_mixin_set_password import RestrictionMixinSetPassword
from .restriction_not_set_session_lockdown import (
RestrictionNotSetSessionLockdown,
)
from .restriction_set_session_lockdown_with_entry_window import (
RestrictionSetSessionLockdownWithEntryWindow,
)