fix(submissions): default to frontend search to prevent wrong 404 on hard refresh
This commit is contained in:
@@ -368,3 +368,23 @@ class ScopeAdminBroadcastTests(TestCase):
|
||||
self.assertEqual(
|
||||
sent, [{"id": str(self.scope.id), "is_active": False, "assigned": False}]
|
||||
)
|
||||
|
||||
|
||||
class SubmissionHomeViewTests(TestCase):
|
||||
def setUp(self):
|
||||
self.event = Event.objects.create(name="Event", path="event")
|
||||
self.client.force_login(
|
||||
CustomUser.objects.create_user(username="player", password="x")
|
||||
)
|
||||
|
||||
def test_any_game_path_serves_the_app(self):
|
||||
# Unknown game / no scope: the frontend shows its own not-found state
|
||||
response = self.client.get(f"/{self.event.path}/submissions/unknown-game")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, "app.html")
|
||||
|
||||
def test_unknown_event_is_404(self):
|
||||
response = self.client.get("/nope/submissions/unknown-game")
|
||||
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
@@ -1,44 +1,17 @@
|
||||
from uuid import UUID
|
||||
from django.http import HttpRequest, Http404
|
||||
from django.shortcuts import redirect, render, get_object_or_404
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from events.models import Event
|
||||
from games.models import Game
|
||||
from .models import Scope
|
||||
|
||||
|
||||
@login_required
|
||||
def submission_home(request: HttpRequest, event_path: str, game_path: str):
|
||||
event = get_object_or_404(Event, path=event_path)
|
||||
game = get_object_or_404(Game, path=game_path)
|
||||
|
||||
scopes = (
|
||||
Scope.objects.filter(
|
||||
event_game__event=event,
|
||||
event_game__game=game,
|
||||
is_active=True,
|
||||
)
|
||||
if request.user.is_superuser
|
||||
else Scope.objects.filter(
|
||||
event_game__event=event,
|
||||
event_game__game=game,
|
||||
assigned_users=request.user,
|
||||
is_active=True,
|
||||
)
|
||||
)
|
||||
|
||||
if scopes.count() == 1:
|
||||
return redirect(
|
||||
"submissions.view",
|
||||
event_path=event.path,
|
||||
game_path=game.path,
|
||||
scope_id=scopes[0].id,
|
||||
)
|
||||
|
||||
if not scopes:
|
||||
raise Http404
|
||||
|
||||
# Unknown game, no scope assigned, auto-entering the only scope: all
|
||||
# handled by the frontend (SubmissionsSelect.vue)
|
||||
get_object_or_404(Event, path=event_path)
|
||||
return render(request, "app.html")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user