"""The module that defines the ``CourseUserLimitExceededException`` 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 ..utils import to_dict
from .limit_exceeded_exception import LimitExceededException
[docs]
@dataclass(kw_only=True)
class CourseUserLimitExceededException(LimitExceededException):
"""Exception raised when a course user limit is exceeded."""
#: A unique code identifying the kind of error that occurred.
code: t.Literal["COURSE_USER_LIMIT_EXCEEDED"]
#: The id of the course that has reached its user limit.
course_id: int
#: Whether the limit that was reached applies to students or staff.
user_type: t.Literal["staff", "student"]
#: The number of users of this type currently in the course.
current_count: int
#: The maximum number of users of this type the course allows.
limit: int
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar[t.Any] = rqa.Lazy(
lambda: LimitExceededException.data_parser.parser.combine(
rqa.FixedMapping(
rqa.RequiredArgument(
"code",
rqa.StringEnum("COURSE_USER_LIMIT_EXCEEDED"),
doc="A unique code identifying the kind of error that occurred.",
),
rqa.RequiredArgument(
"course_id",
rqa.SimpleValue.int,
doc="The id of the course that has reached its user limit.",
),
rqa.RequiredArgument(
"user_type",
rqa.StringEnum("staff", "student"),
doc="Whether the limit that was reached applies to students or staff.",
),
rqa.RequiredArgument(
"current_count",
rqa.SimpleValue.int,
doc="The number of users of this type currently in the course.",
),
rqa.RequiredArgument(
"limit",
rqa.SimpleValue.int,
doc="The maximum number of users of this type the course allows.",
),
)
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"code": to_dict(self.code),
"course_id": to_dict(self.course_id),
"user_type": to_dict(self.user_type),
"current_count": to_dict(self.current_count),
"limit": to_dict(self.limit),
"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[CourseUserLimitExceededException],
d: t.Dict[str, t.Any],
response: t.Optional[Response] = None,
) -> CourseUserLimitExceededException:
parsed = cls.data_parser.try_parse(d)
res = cls(
code=parsed.code,
course_id=parsed.course_id,
user_type=parsed.user_type,
current_count=parsed.current_count,
limit=parsed.limit,
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