Skip to content

Commit

Permalink
welcome to Json pushing untested code to prod!
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Dec 19, 2023
1 parent 11e1df8 commit cf71086
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions core/views/qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf71086

Please sign in to comment.