From cf71086c80b27cab3de2986f52b27e0d26bea330 Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Tue, 19 Dec 2023 17:57:19 -0500 Subject: [PATCH] welcome to Json pushing untested code to prod! --- core/models.py | 13 +++++++++++-- core/views/qr.py | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/models.py b/core/models.py index 1b1d958..bce68d2 100644 --- a/core/models.py +++ b/core/models.py @@ -10,6 +10,7 @@ from django.db.models import Func, F, DurationField, Case, DateTimeField, When from django.db.models.signals import m2m_changed from django.dispatch import receiver +from django.urls import reverse from django.utils import timezone from django.utils.html import format_html @@ -21,7 +22,12 @@ def generate_invite_code(): class User(AbstractUser): metropolis_id = models.IntegerField() refresh_token = models.CharField(max_length=128) - + send_to_admin = models.BooleanField(default=False, null=False, help_text="If when a user scans a QR code, they should be sent to the admin page instead of the hint page. Useful for debugging.") + + @property + def is_debuggable(self): + return self.send_to_admin and self.is_staff + @property def current_team(self) -> Team | None: """Returns the team that the user is currently on for the current or upcoming hunt. @@ -76,7 +82,10 @@ class QrCode(models.Model): help_text="A URL to an image of where the QR code is located (try imgur)", blank=True, ) - + + def get_admin_url(self): + return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), + args=[self.id]) def image_tag(self): from django.utils.html import escape diff --git a/core/views/qr.py b/core/views/qr.py index 03047af..f2327f3 100644 --- a/core/views/qr.py +++ b/core/views/qr.py @@ -124,11 +124,11 @@ def wrapped(*args, **kwargs): @during_hunt def qr(request, key): context = dict(first=False) - context["qr_code"]: QrCode codes = QrCode.code_pks(request.user.current_team) qr_code: QrCode | None = QrCode.objects.filter(key=key).first() - print(f"{codes=}") - print(f"{request.user.current_team.current_qr_i=}") + if request.user.is_debuggable: + return redirect(qr_code.get_admin_url()) + context["qr_code"]: QrCode if qr_code is None: # User just tried brute-forcing keys... lol context["offpath"] = True