From 6d01298e2408c148976fa56125c2babc0ccdf8c8 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 25 May 2020 22:12:05 +0200 Subject: [PATCH] Authenticated juries get access with the extra token access --- tfjm/middlewares.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tfjm/middlewares.py b/tfjm/middlewares.py index e19731f..b20051c 100644 --- a/tfjm/middlewares.py +++ b/tfjm/middlewares.py @@ -6,6 +6,7 @@ from threading import local from django.contrib.sessions.backends.db import SessionStore from member.models import TFJMUser +from tournament.models import Pool USER_ATTR_NAME = getattr(settings, 'LOCAL_USER_ATTR_NAME', '_current_user') SESSION_ATTR_NAME = getattr(settings, 'LOCAL_SESSION_ATTR_NAME', '_current_session') @@ -75,6 +76,11 @@ class ExtraAccessMiddleware(object): def __call__(self, request): if "extra_access_token" in request.GET: request.session["extra_access_token"] = request.GET["extra_access_token"] + if request.user.is_authenticated: + pool = Pool.objects.filter(extra_access_token=request.GET["extra_access_token"]) + if pool.exists(): + pool.juries.add(request.user) + pool.save() else: request.session.setdefault("extra_access_token", "") return self.get_response(request)