From 48adf7e6b851360aaecbc8ee6268f29a74e03b44 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 4 Jan 2023 15:21:03 -0600 Subject: [PATCH] Refactor contest views --- judge/views/contests.py | 22 +++++++++++++--------- judge/views/submission.py | 2 +- templates/contest/contest-tabs.html | 8 +++++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/judge/views/contests.py b/judge/views/contests.py index 56580b9..65a8b36 100644 --- a/judge/views/contests.py +++ b/judge/views/contests.py @@ -295,7 +295,12 @@ class ContestMixin(object): context["meta_description"] = self.object.summary or metadata[0] context["og_image"] = self.object.og_image or metadata[1] context["has_moss_api_key"] = settings.MOSS_API_KEY is not None - context["can_use_resolver"] = self.object.format.has_hidden_subtasks + context["contest_has_hidden_subtasks"] = self.object.format.has_hidden_subtasks + context[ + "show_final_ranking" + ] = self.object.format.has_hidden_subtasks and self.object.is_editable_by( + self.request.user + ) context["logo_override_image"] = self.object.logo_override_image if ( not context["logo_override_image"] @@ -989,7 +994,10 @@ def contest_ranking_ajax(request, contest, participation=None): raise Http404() if show_final: - if not request.user.is_superuser or not contest.format.has_hidden_subtasks: + if ( + not contest.is_editable_by(request.user) + or not contest.format.has_hidden_subtasks + ): raise Http404() queryset = contest.users.filter(virtual__gte=0) @@ -1075,9 +1083,9 @@ class ContestFinalRanking(LoginRequiredMixin, ContestRanking): page_type = "final_ranking" def get_ranking_list(self): - if not self.request.user.is_superuser: + if not self.object.is_editable_by(self.request.user): raise Http404() - if self.object.format_name != "ioi16": + if self.object.format.has_hidden_subtasks: raise Http404() return get_contest_ranking_list(self.request, self.object, show_final=True) @@ -1264,11 +1272,7 @@ class NewContestClarificationView(ContestMixin, TitleMixin, SingleObjectFormView return False if not self.request.participation.contest == self.get_object(): return False - return ( - self.request.user.is_superuser - or self.request.profile in self.request.participation.contest.authors.all() - or self.request.profile in self.request.participation.contest.curators.all() - ) + return self.get_object().is_editable_by(self.request.user) def get(self, request, *args, **kwargs): if not self.is_accessible(): diff --git a/judge/views/submission.py b/judge/views/submission.py index 6032dfc..2912bed 100644 --- a/judge/views/submission.py +++ b/judge/views/submission.py @@ -516,7 +516,7 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView): self.selected_languages = set(request.GET.getlist("language")) self.selected_statuses = set(request.GET.getlist("status")) - if self.contest and self.contest.is_editable_by(self.request.user): + if self.in_contest and self.contest.is_editable_by(self.request.user): self.include_frozen = True if "results" in request.GET: diff --git a/templates/contest/contest-tabs.html b/templates/contest/contest-tabs.html index 3ef2141..2da2fee 100644 --- a/templates/contest/contest-tabs.html +++ b/templates/contest/contest-tabs.html @@ -22,9 +22,11 @@ {{ make_tab_item('ranking', 'fa fa-bar-chart', None, _('Hidden Rankings')) }} {% endif %} {% endif %} - {% if request.user.is_superuser and can_use_resolver %} - {{ make_tab_item('resolver', 'fa fa-check', url('resolver', contest.key), _('Resolver')) }} - {{ make_tab_item('final_ranking', 'fa fa-bar-chart', url('contest_final_ranking', contest.key), _('Final rankings')) }} + {% if request.user.is_superuser and contest_has_hidden_subtasks %} + {{ make_tab_item('resolver', 'fa fa-check', url('resolver', contest.key), _('Resolver')) }} + {% endif %} + {% if show_final_ranking %} + {{ make_tab_item('final_ranking', 'fa fa-bar-chart', url('contest_final_ranking', contest.key), _('Final rankings')) }} {% endif %} {% if can_edit %} {% if perms.judge.moss_contest and has_moss_api_key %}