From 6f7ff12e7e1e75bf30f1c312ba0b5e391e8b869b Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Fri, 5 Apr 2024 16:00:49 +0000 Subject: [PATCH 1/4] fix missing closing bracket --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4286f56..b8a9f7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "mCTF" version = "1.0.5" description = "A reusable CTF platform." -authors = ["Jason Cameron "] readme = "README.md" keywords = ["ctf", "jeopardy", "ctf-platform", "django"] From 4e455b83693afd2fa16f3e6adab9a326f8acd2fb Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Fri, 5 Apr 2024 16:11:03 +0000 Subject: [PATCH 2/4] Created contests API closes #10 note: it does need better filtering implemented --- gameserver/api/routes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gameserver/api/routes.py b/gameserver/api/routes.py index 51b9a18..5d8fa8e 100644 --- a/gameserver/api/routes.py +++ b/gameserver/api/routes.py @@ -6,6 +6,7 @@ from ninja import NinjaAPI, Schema from typing import List, Any +import datetime def unicode_safe(string): return string.encode("unicode_escape").decode() @@ -14,6 +15,16 @@ def unicode_safe(string): api = NinjaAPI() +class ContestOutSchema(Schema): + name: str + slug: str + start_time: datetime.datetime + end_time: datetime.datetime + max_team_size: int | None + description: str + summary: str + + class CTFSchema(Schema): pos: int team: Any = None @@ -73,3 +84,10 @@ def ctftime_standings(request, contest_name: str): ) return {"standings": standings, "tasks": task_names} + +@api.get("/contests", response=List[ContestOutSchema]) +def contests(request): + return ( + Contest.objects.filter(is_public=True) + .values("name", "slug", "start_time", "end_time", "max_team_size", "description", "summary") + ) From 627c9905cc33d7bd068136a9dd71d504940c1547 Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Fri, 5 Apr 2024 16:12:14 +0000 Subject: [PATCH 3/4] fmting --- gameserver/models/cache.py | 3 +-- gameserver/models/contest.py | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gameserver/models/cache.py b/gameserver/models/cache.py index ba73299..7986785 100644 --- a/gameserver/models/cache.py +++ b/gameserver/models/cache.py @@ -23,8 +23,7 @@ class ResetableCache(Protocol): - def can_reset(cls, request: HttpRequest) -> None: - ... + def can_reset(cls, request: HttpRequest) -> None: ... class CacheMeta(models.Model): diff --git a/gameserver/models/contest.py b/gameserver/models/contest.py index c9f12d1..e6a6166 100644 --- a/gameserver/models/contest.py +++ b/gameserver/models/contest.py @@ -32,7 +32,12 @@ def __init__(self, *args, **kwargs): organizers = models.ManyToManyField("User", related_name="contests_organized", blank=True) curators = models.ManyToManyField("User", related_name="contests_curated", blank=True) - organizations = models.ManyToManyField("Organization", related_name="contests", blank=True, help_text="Only users of these organizations can access the contest") + organizations = models.ManyToManyField( + "Organization", + related_name="contests", + blank=True, + help_text="Only users of these organizations can access the contest", + ) name = models.CharField(max_length=128) slug = models.SlugField(unique=True, db_index=True) From 664b9759a3eb6a7b1f047416494474bae54132a4 Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Fri, 5 Apr 2024 16:27:12 +0000 Subject: [PATCH 4/4] casefold reset --- gameserver/models/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gameserver/models/cache.py b/gameserver/models/cache.py index 7986785..24b026b 100644 --- a/gameserver/models/cache.py +++ b/gameserver/models/cache.py @@ -42,7 +42,7 @@ def _can_reset(cls, request: HttpRequest): [ request.user.is_authenticated, request.user.is_staff, - request.GET.get("reset", "") == "true", + request.GET.get("reset", "").casefold() == "true", ] )