Skip to content

Схемы, связанные с разрешениями

PermissionResponseItemV1

Bases: BaseModel

Represents a single permission entry in a response, linking a user with their role within a namespace.

Source code in horizon/commons/schemas/v1/permission.py
11
12
13
14
15
class PermissionResponseItemV1(BaseModel):
    """Represents a single permission entry in a response, linking a user with their role within a namespace."""

    username: str
    role: NamespaceUserRole

PermissionsResponseV1

Bases: BaseModel

Wraps a list of permission entries for a namespace, returned by the GET endpoint.

Source code in horizon/commons/schemas/v1/permission.py
18
19
20
21
class PermissionsResponseV1(BaseModel):
    """Wraps a list of permission entries for a namespace, returned by the GET endpoint."""

    permissions: List[PermissionResponseItemV1]

PermissionUpdateRequestItemV1

Bases: BaseModel

Represents a single permission entry in a request, specifying a desired role for a user within a namespace.

Source code in horizon/commons/schemas/v1/permission.py
24
25
26
27
28
29
30
31
32
class PermissionUpdateRequestItemV1(BaseModel):
    """Represents a single permission entry in a request, specifying a desired role for a user within a namespace."""

    username: str
    role: Optional[NamespaceUserRole] = Field(
        default=None,
        description="The role to be assigned to the user within the namespace."
        " A value of `None` indicates that the permission should be removed.",
    )

PermissionsUpdateRequestV1

Bases: BaseModel

Wraps a list of permission modification requests for a namespace, used by the PATCH endpoint.

Source code in horizon/commons/schemas/v1/permission.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class PermissionsUpdateRequestV1(BaseModel):
    """Wraps a list of permission modification requests for a namespace, used by the PATCH endpoint."""

    permissions: List[PermissionUpdateRequestItemV1] = Field(
        description="A list of modifications to the namespace's permissions."
        " Each entry specifies a user and the role they should have or be removed from.",
    )

    @validator("permissions")
    def _ensure_unique_usernames_and_single_owner(
        cls,  # noqa: N805
        permissions: List[PermissionUpdateRequestItemV1],
    ) -> List[PermissionUpdateRequestItemV1]:
        seen: Set[str] = set()
        owner_count = 0
        for perm in permissions:
            username, role = perm.username, perm.role

            if username in seen:
                msg = f"Duplicate username detected: {username}. Each username must appear only once."
                raise ValueError(msg)
            seen.add(username)

            if role == NamespaceUserRole.OWNER:
                owner_count += 1

        if owner_count > 1:
            msg = "Multiple owner role assignments detected. Only one owner can be assigned."
            raise ValueError(msg)

        return permissions