Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Prevent users from seeing their own OG submissions #7

Merged
merged 1 commit into from
May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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