feat(submissions): scoped submissions per user/matchs, sync from polylan

This commit is contained in:
2026-09-16 13:12:22 +02:00
parent 85e67599af
commit fabf06e6d4
35 changed files with 1008 additions and 92 deletions
+45 -20
View File
@@ -6,8 +6,8 @@ from ninja.files import UploadedFile
from django.shortcuts import get_object_or_404
from games.models import Game
from .models import Submission, SubmissionFile, ImageCrop, OCRStatus
from .schemas import SubmissionOut, ImageCropIn, ImageCropOut
from .models import Submission, SubmissionFile, ImageCrop, OCRStatus, Scope
from .schemas import SubmissionOut, ImageCropIn, ImageCropOut, ScopeOut
from .tasks import process_submission_file, process_crop
router = Router()
@@ -15,22 +15,47 @@ router = Router()
PREFIX = "/events/{event_path}/submissions"
@router.post(f"{PREFIX}/submission/create", response=SubmissionOut)
def create_submission(
request: HttpRequest,
event_path: str,
game_path: str,
files: List[UploadedFile] = File(...),
notes: Optional[str] = Form(None),
):
@router.get(f"{PREFIX}/scopes/mine", response={200: list[ScopeOut], 403: dict})
def list_my_scopes(request: HttpRequest, event_path: str, game_path: str):
if not request.user.is_authenticated:
return 403, {"detail": "Authentication required"}
game = get_object_or_404(
Game.objects.enabled_for_event(request.event), path=game_path
)
return Scope.objects.filter(
event_game__event=request.event,
event_game__game=game,
assigned_users=request.user,
)
@router.post(f"{PREFIX}/submission/create", response={200: SubmissionOut, 403: dict})
def create_submission(
request: HttpRequest,
event_path: str,
scope_id: UUID,
files: List[UploadedFile] = File(...),
notes: Optional[str] = Form(None),
):
if not request.user.is_authenticated:
return 403, {"detail": "Authentication required"}
scope = get_object_or_404(
Scope, id=scope_id, event_game__event=request.event, is_active=True
)
if (
not request.user.is_staff
and not scope.assigned_users.filter(pk=request.user.pk).exists()
):
return 403, {"detail": "You are not assigned to this scope"}
submission = Submission.objects.create(
event=request.event,
game=game,
user=request.user if request.user.is_authenticated else None,
scope=scope,
user=request.user,
notes=notes or None,
)
@@ -45,16 +70,16 @@ def create_submission(
return submission
@router.get(f"{PREFIX}/submission/by/user", response=list[SubmissionOut])
def list_user_submissions(request: HttpRequest, event_path: str, game_path: str):
game = get_object_or_404(Game, path=game_path)
@router.get(
f"{PREFIX}/submission/by/user", response={200: list[SubmissionOut], 403: dict}
)
def list_user_submissions(request: HttpRequest, event_path: str, scope_id: UUID):
if not request.user.is_authenticated:
return 403, {"detail": "Authentication required"}
submissions = Submission.for_event.filter(game=game, user=request.user).order_by(
"-created_at"
)
submissions = Submission.for_event.filter(
scope_id=scope_id, user=request.user
).order_by("-created_at")
return submissions
@@ -65,7 +90,7 @@ def list_submissions_by_game(request: HttpRequest, event_path: str, game_path: s
if not request.user.is_staff:
return 403, {"detail": "Admin access required"}
return Submission.for_event.filter(game=game)
return Submission.for_event.filter(scope__event_game__game=game)
@router.get(f"{PREFIX}/submission/{{submission_id}}", response=SubmissionOut)