From 78b818901ea66247e51d3331553dc2c147c7749b Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 1 Jun 2022 14:31:20 -0500 Subject: [PATCH] Relax contest submission view --- judge/models/problem.py | 4 ++-- judge/views/submission.py | 19 +++++++++++++++---- templates/submission/user-ajax.html | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/judge/models/problem.py b/judge/models/problem.py index 7211a69..4562775 100644 --- a/judge/models/problem.py +++ b/judge/models/problem.py @@ -333,7 +333,7 @@ class Problem(models.Model): return True return user.has_perm("judge.edit_own_problem") and self.is_editor(user.profile) - def is_accessible_by(self, user): + def is_accessible_by(self, user, in_contest_mode=True): # Problem is public. if self.is_public: # Problem is not private to an organization. @@ -367,7 +367,7 @@ class Problem(models.Model): # If user is currently in a contest containing that problem. current = user.profile.current_contest_id - if current is None: + if not in_contest_mode or current is None: return False from judge.models import ContestProblem diff --git a/judge/views/submission.py b/judge/views/submission.py index c196445..df3c898 100644 --- a/judge/views/submission.py +++ b/judge/views/submission.py @@ -506,7 +506,7 @@ class AllUserSubmissions(ConditionalUserTabMixin, UserMixin, SubmissionsListBase class ProblemSubmissionsBase(SubmissionsListBase): show_problem = False dynamic_update = True - check_contest_in_access_check = True + check_contest_in_access_check = False def get_queryset(self): if ( @@ -535,13 +535,16 @@ class ProblemSubmissionsBase(SubmissionsListBase): def access_check_contest(self, request): if self.in_contest and not self.contest.can_see_own_scoreboard(request.user): raise Http404() - - def access_check(self, request): - if not self.problem.is_accessible_by(request.user): + if not self.contest.is_accessible_by(request.user): raise Http404() + def access_check(self, request): if self.check_contest_in_access_check: self.access_check_contest(request) + else: + is_own = hasattr(self, 'is_own') and self.is_own + if not is_own and not self.problem.is_accessible_by(request.user, request.in_contest_mode): + raise Http404() def get(self, request, *args, **kwargs): if "problem" not in kwargs: @@ -740,6 +743,8 @@ class ForceContestMixin(object): class UserContestSubmissions(ForceContestMixin, UserProblemSubmissions): + check_contest_in_access_check = True + def get_title(self): if self.problem.is_accessible_by(self.request.user): return "%s's submissions for %s in %s" % ( @@ -812,3 +817,9 @@ class UserContestSubmissionsAjax(UserContestSubmissions): total = floatformat(contest_problem.points, -self.contest.points_precision) s.display_point = f"{points} / {total}" return context + + def get(self, request, *args, **kwargs): + try: + return super(UserContestSubmissionsAjax, self).get(request, *args, **kwargs) + except Http404: + return HttpResponse(_("You don't have permission to access.")) \ No newline at end of file diff --git a/templates/submission/user-ajax.html b/templates/submission/user-ajax.html index c612e43..91a6e29 100644 --- a/templates/submission/user-ajax.html +++ b/templates/submission/user-ajax.html @@ -6,7 +6,7 @@ {% for submission in submissions %} {% set can_view = submission_layout(submission, profile_id, request.user, editable_problem_ids, completed_problem_ids) %} - + {% if submission.contest_time %} {{submission.contest_time}} {% else %}