Relax contest submission view

This commit is contained in:
cuom1999 2022-06-01 14:31:20 -05:00
parent 1e35ba864f
commit 78b818901e
3 changed files with 18 additions and 7 deletions

View file

@ -333,7 +333,7 @@ class Problem(models.Model):
return True return True
return user.has_perm("judge.edit_own_problem") and self.is_editor(user.profile) 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. # Problem is public.
if self.is_public: if self.is_public:
# Problem is not private to an organization. # 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. # If user is currently in a contest containing that problem.
current = user.profile.current_contest_id current = user.profile.current_contest_id
if current is None: if not in_contest_mode or current is None:
return False return False
from judge.models import ContestProblem from judge.models import ContestProblem

View file

@ -506,7 +506,7 @@ class AllUserSubmissions(ConditionalUserTabMixin, UserMixin, SubmissionsListBase
class ProblemSubmissionsBase(SubmissionsListBase): class ProblemSubmissionsBase(SubmissionsListBase):
show_problem = False show_problem = False
dynamic_update = True dynamic_update = True
check_contest_in_access_check = True check_contest_in_access_check = False
def get_queryset(self): def get_queryset(self):
if ( if (
@ -535,13 +535,16 @@ class ProblemSubmissionsBase(SubmissionsListBase):
def access_check_contest(self, request): def access_check_contest(self, request):
if self.in_contest and not self.contest.can_see_own_scoreboard(request.user): if self.in_contest and not self.contest.can_see_own_scoreboard(request.user):
raise Http404() raise Http404()
if not self.contest.is_accessible_by(request.user):
def access_check(self, request):
if not self.problem.is_accessible_by(request.user):
raise Http404() raise Http404()
def access_check(self, request):
if self.check_contest_in_access_check: if self.check_contest_in_access_check:
self.access_check_contest(request) 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): def get(self, request, *args, **kwargs):
if "problem" not in kwargs: if "problem" not in kwargs:
@ -740,6 +743,8 @@ class ForceContestMixin(object):
class UserContestSubmissions(ForceContestMixin, UserProblemSubmissions): class UserContestSubmissions(ForceContestMixin, UserProblemSubmissions):
check_contest_in_access_check = True
def get_title(self): def get_title(self):
if self.problem.is_accessible_by(self.request.user): if self.problem.is_accessible_by(self.request.user):
return "%s's submissions for %s in %s" % ( return "%s's submissions for %s in %s" % (
@ -812,3 +817,9 @@ class UserContestSubmissionsAjax(UserContestSubmissions):
total = floatformat(contest_problem.points, -self.contest.points_precision) total = floatformat(contest_problem.points, -self.contest.points_precision)
s.display_point = f"{points} / {total}" s.display_point = f"{points} / {total}"
return context 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."))

View file

@ -6,7 +6,7 @@
{% for submission in submissions %} {% for submission in submissions %}
<tr> <tr>
{% set can_view = submission_layout(submission, profile_id, request.user, editable_problem_ids, completed_problem_ids) %} {% set can_view = submission_layout(submission, profile_id, request.user, editable_problem_ids, completed_problem_ids) %}
<td> <td style="padding-right: 1em">
{% if submission.contest_time %} {% if submission.contest_time %}
{{submission.contest_time}} {{submission.contest_time}}
{% else %} {% else %}