Skip to content

Commit

Permalink
🔧 Prevent users from seeing their own OG submissions
Browse files Browse the repository at this point in the history
If their email address matches the one on the request, don't show
it to them.

Fixes #6.
  • Loading branch information
drewbrew committed May 17, 2023
1 parent f03b3cb commit d2ae196
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions grants/views/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import collections

from django import forms
from django.db.models import Q
from django.http import Http404
from django.shortcuts import redirect, render
from django.utils import timezone
Expand Down Expand Up @@ -176,8 +177,11 @@ def get_queryset(self):
else:
self.sort = "applied"
# Fetch applicants
# but don't let a user see their own request
applicants = list(
self.program.applicants.prefetch_related("scores").order_by("-applied")
self.program.applicants.exclude(email=self.request.user.email)
.prefetch_related("scores")
.order_by("-applied")
)
for applicant in applicants:
applicant.has_scored = applicant.scores.filter(
Expand Down Expand Up @@ -205,7 +209,9 @@ class ProgramApplicantView(ProgramMixin, TemplateView):
template_name = "applicant-view.html"

def get(self, request, applicant_id):
applicant = self.program.applicants.get(pk=applicant_id)
applicant = self.program.applicants.exclude(
email=self.request.user.email,
).get(pk=applicant_id)
questions = list(self.program.questions.order_by("order"))
for question in questions:
question.answer = question.answers.filter(applicant=applicant).first()
Expand Down Expand Up @@ -261,7 +267,9 @@ class RandomUnscoredApplicant(ProgramMixin, View):

def get(self, request):
applicant = (
self.program.applicants.exclude(scores__user=self.request.user)
self.program.applicants.exclude(
Q(scores__user=self.request.user) | Q(email=self.request.user.email)
)
.order_by("?")
.first()
)
Expand Down

0 comments on commit d2ae196

Please sign in to comment.