ctfy.sdk.admin_resources.competition_admins

client.admin.competition_admins — per-competition admin grants (admin).

 1"""``client.admin.competition_admins`` — per-competition admin grants (admin)."""
 2
 3from __future__ import annotations
 4
 5from ctfy.sdk._helpers import PagedList, _extract_items, _raise_for_status
 6from ctfy.sdk.base import BaseHttpClient
 7from ctfy.server.models import CompetitionAdminInfo
 8
 9
10class AdminCompetitionAdminsResource:
11    """Grant / revoke the per-competition admin role."""
12
13    def __init__(self, http: BaseHttpClient) -> None:
14        self._http = http
15
16    def list(
17        self, competition_id: str, offset: int = 0, limit: int = 50
18    ) -> PagedList[CompetitionAdminInfo]:
19        """Users granted admin on one competition."""
20        resp = self._http.request(
21            "GET",
22            f"/admin/competitions/{competition_id}/admins",
23            params={"offset": offset, "limit": limit},
24        )
25        _raise_for_status(resp)
26        return _extract_items(resp.json(), CompetitionAdminInfo)
27
28    def grant(
29        self, competition_id: str, *, user_id: str = "", email: str = ""
30    ) -> CompetitionAdminInfo:
31        """Grant per-competition admin. Identify the target by
32        ``user_id`` or ``email`` (the server accepts either)."""
33        resp = self._http.request(
34            "POST",
35            f"/admin/competitions/{competition_id}/admins",
36            json={"user_id": user_id, "email": email},
37        )
38        _raise_for_status(resp)
39        return CompetitionAdminInfo.model_validate(resp.json())
40
41    def revoke(self, competition_id: str, user_id: str) -> None:
42        """Revoke a user's per-competition admin grant."""
43        resp = self._http.request(
44            "DELETE", f"/admin/competitions/{competition_id}/admins/{user_id}"
45        )
46        _raise_for_status(resp)
class AdminCompetitionAdminsResource:
11class AdminCompetitionAdminsResource:
12    """Grant / revoke the per-competition admin role."""
13
14    def __init__(self, http: BaseHttpClient) -> None:
15        self._http = http
16
17    def list(
18        self, competition_id: str, offset: int = 0, limit: int = 50
19    ) -> PagedList[CompetitionAdminInfo]:
20        """Users granted admin on one competition."""
21        resp = self._http.request(
22            "GET",
23            f"/admin/competitions/{competition_id}/admins",
24            params={"offset": offset, "limit": limit},
25        )
26        _raise_for_status(resp)
27        return _extract_items(resp.json(), CompetitionAdminInfo)
28
29    def grant(
30        self, competition_id: str, *, user_id: str = "", email: str = ""
31    ) -> CompetitionAdminInfo:
32        """Grant per-competition admin. Identify the target by
33        ``user_id`` or ``email`` (the server accepts either)."""
34        resp = self._http.request(
35            "POST",
36            f"/admin/competitions/{competition_id}/admins",
37            json={"user_id": user_id, "email": email},
38        )
39        _raise_for_status(resp)
40        return CompetitionAdminInfo.model_validate(resp.json())
41
42    def revoke(self, competition_id: str, user_id: str) -> None:
43        """Revoke a user's per-competition admin grant."""
44        resp = self._http.request(
45            "DELETE", f"/admin/competitions/{competition_id}/admins/{user_id}"
46        )
47        _raise_for_status(resp)

Grant / revoke the per-competition admin role.

AdminCompetitionAdminsResource(http: ctfy.sdk.base.BaseHttpClient)
14    def __init__(self, http: BaseHttpClient) -> None:
15        self._http = http
def list( self, competition_id: str, offset: int = 0, limit: int = 50) -> ctfy.sdk._helpers.PagedList[ctfy.server.models.CompetitionAdminInfo]:
17    def list(
18        self, competition_id: str, offset: int = 0, limit: int = 50
19    ) -> PagedList[CompetitionAdminInfo]:
20        """Users granted admin on one competition."""
21        resp = self._http.request(
22            "GET",
23            f"/admin/competitions/{competition_id}/admins",
24            params={"offset": offset, "limit": limit},
25        )
26        _raise_for_status(resp)
27        return _extract_items(resp.json(), CompetitionAdminInfo)

Users granted admin on one competition.

def grant( self, competition_id: str, *, user_id: str = '', email: str = '') -> ctfy.server.models.CompetitionAdminInfo:
29    def grant(
30        self, competition_id: str, *, user_id: str = "", email: str = ""
31    ) -> CompetitionAdminInfo:
32        """Grant per-competition admin. Identify the target by
33        ``user_id`` or ``email`` (the server accepts either)."""
34        resp = self._http.request(
35            "POST",
36            f"/admin/competitions/{competition_id}/admins",
37            json={"user_id": user_id, "email": email},
38        )
39        _raise_for_status(resp)
40        return CompetitionAdminInfo.model_validate(resp.json())

Grant per-competition admin. Identify the target by user_id or email (the server accepts either).

def revoke(self, competition_id: str, user_id: str) -> None:
42    def revoke(self, competition_id: str, user_id: str) -> None:
43        """Revoke a user's per-competition admin grant."""
44        resp = self._http.request(
45            "DELETE", f"/admin/competitions/{competition_id}/admins/{user_id}"
46        )
47        _raise_for_status(resp)

Revoke a user's per-competition admin grant.