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

Full hidden scoreboard & Post-window own scoreboard #1843

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions judge/models/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ class Contest(models.Model):
SCOREBOARD_VISIBLE = 'V'
SCOREBOARD_AFTER_CONTEST = 'C'
SCOREBOARD_AFTER_PARTICIPATION = 'P'
SCOREBOARD_HIDDEN = 'H'
SCOREBOARD_VISIBILITY = (
(SCOREBOARD_VISIBLE, _('Visible')),
(SCOREBOARD_AFTER_CONTEST, _('Hidden for duration of contest')),
(SCOREBOARD_AFTER_PARTICIPATION, _('Hidden for duration of participation')),
(SCOREBOARD_HIDDEN, _('Hidden permanently')),
)
key = models.CharField(max_length=20, verbose_name=_('contest id'), unique=True,
validators=[RegexValidator('^[a-z0-9]+$', _('Contest id must be ^[a-z0-9]+$'))])
Expand Down Expand Up @@ -201,7 +203,7 @@ def can_see_own_scoreboard(self, user):
return True
if not self.can_join:
return False
if not self.show_scoreboard and not self.is_in_contest(user):
if not self.show_scoreboard and not self.is_in_contest(user) and not self.has_completed_contest(user):
return False
return True

Expand Down Expand Up @@ -234,7 +236,7 @@ def show_scoreboard(self):
if (self.scoreboard_visibility in (self.SCOREBOARD_AFTER_CONTEST, self.SCOREBOARD_AFTER_PARTICIPATION) and
not self.ended):
return False
return True
return self.scoreboard_visibility != self.SCOREBOARD_HIDDEN

@property
def contest_window_length(self):
Expand Down
54 changes: 53 additions & 1 deletion judge/models/tests/test_contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ def setUpTestData(self):
testers=('non_staff_tester',),
)

self.full_hidden_scoreboard_contest = create_contest(
key='full_hidden_board',
start_time=_now - timezone.timedelta(days=100),
end_time=_now - timezone.timedelta(days=1),
time_limit=timezone.timedelta(days=1),
is_visible=True,
scoreboard_visibility=Contest.SCOREBOARD_HIDDEN,
authors=('non_staff_author',),
curators=('staff_contest_edit_own',),
testers=('non_staff_tester',),
)

for contest_key in ('contest_scoreboard', 'particip_scoreboard', 'visible_scoreboard'):
create_contest_participation(
contest=contest_key,
Expand Down Expand Up @@ -137,6 +149,13 @@ def setUpTestData(self):
virtual=ContestParticipation.SPECTATE,
)

create_contest_participation(
contest='full_hidden_board',
user='normal_after_window',
real_start=_now - timezone.timedelta(days=5),
virtual=ContestParticipation.LIVE,
)

self.users['normal'].profile.current_contest = create_contest_participation(
contest='hidden_scoreboard',
user='normal',
Expand Down Expand Up @@ -372,7 +391,7 @@ def test_contest_hidden_scoreboard_contest_methods(self):
'has_completed_contest': self.assertFalse,
},
'normal_after_window': {
'can_see_own_scoreboard': self.assertFalse,
'can_see_own_scoreboard': self.assertTrue,
'can_see_full_scoreboard': self.assertFalse,
'has_completed_contest': self.assertTrue,
},
Expand Down Expand Up @@ -439,6 +458,39 @@ def test_visible_scoreboard_contest_methods(self):
}
self._test_object_methods_with_users(self.visible_scoreboard_contest, data)

def test_full_hidden_scoreboard_contest_methods(self):
data = {
'superuser': {
'can_see_own_scoreboard': self.assertTrue,
'can_see_full_scoreboard': self.assertTrue,
},
'non_staff_tester': {
'can_see_own_scoreboard': self.assertFalse,
'can_see_full_scoreboard': self.assertFalse,
},
'non_staff_author': {
'can_see_own_scoreboard': self.assertTrue,
'can_see_full_scoreboard': self.assertTrue,
},
'staff_contest_edit_own': {
'can_see_own_scoreboard': self.assertTrue,
'can_see_full_scoreboard': self.assertTrue,
},
'staff_contest_edit_all': {
'can_see_own_scoreboard': self.assertTrue,
'can_see_full_scoreboard': self.assertTrue,
},
'normal': {
'can_see_own_scoreboard': self.assertFalse,
'can_see_full_scoreboard': self.assertFalse,
},
'normal_after_window': {
'can_see_own_scoreboard': self.assertTrue,
'can_see_full_scoreboard': self.assertFalse,
},
}
self._test_object_methods_with_users(self.full_hidden_scoreboard_contest, data)

def test_private_contest_methods(self):
with self.assertRaises(Contest.PrivateContest):
self.private_contest.access_check(self.users['normal'])
Expand Down
3 changes: 2 additions & 1 deletion judge/views/api/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ def get_object_data(self, contest):
'rating_floor': contest.rating_floor,
'rating_ceiling': contest.rating_ceiling,
'hidden_scoreboard': contest.scoreboard_visibility in (contest.SCOREBOARD_AFTER_CONTEST,
contest.SCOREBOARD_AFTER_PARTICIPATION),
contest.SCOREBOARD_AFTER_PARTICIPATION,
contest.SCOREBOARD_HIDDEN),
'scoreboard_visibility': contest.scoreboard_visibility,
'is_organization_private': contest.is_organization_private,
'organizations': list(
Expand Down
7 changes: 5 additions & 2 deletions judge/views/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,11 @@ def get_context_data(self, **kwargs):
else:
context['hot_problems'] = None
context['point_start'], context['point_end'], context['point_values'] = 0, 0, {}
context['hide_contest_scoreboard'] = self.contest.scoreboard_visibility in \
(self.contest.SCOREBOARD_AFTER_CONTEST, self.contest.SCOREBOARD_AFTER_PARTICIPATION)
context['hide_contest_scoreboard'] = self.contest.scoreboard_visibility in (
self.contest.SCOREBOARD_AFTER_CONTEST,
self.contest.SCOREBOARD_AFTER_PARTICIPATION,
self.contest.SCOREBOARD_HIDDEN,
)
return context

def get_noui_slider_points(self):
Expand Down
6 changes: 5 additions & 1 deletion judge/views/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ def _get_queryset(self):
contest_queryset = Contest.objects.filter(Q(authors=self.request.profile) |
Q(curators=self.request.profile) |
Q(scoreboard_visibility=Contest.SCOREBOARD_VISIBLE) |
Q(end_time__lt=timezone.now())).distinct()
Q(end_time__lt=timezone.now()), scoreboard_visibility__in=(
Contest.SCOREBOARD_AFTER_PARTICIPATION,
Contest.SCOREBOARD_AFTER_CONTEST,
)) \
.distinct()
queryset = queryset.filter(Q(user=self.request.profile) |
Q(contest_object__in=contest_queryset) |
Q(contest_object__isnull=True))
Expand Down
2 changes: 2 additions & 0 deletions templates/contest/contest.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
{{ _('The scoreboard will be **hidden** until your window is over.')|markdown('default') }}
{% elif contest.scoreboard_visibility == contest.SCOREBOARD_AFTER_CONTEST %}
{{ _('The scoreboard will be **hidden** for the entire duration of the contest.')|markdown('default') }}
{% elif contest.scoreboard_visibility == contest.SCOREBOARD_HIDDEN %}
{{ _('The scoreboard will be **hidden**, even after the contest is over.')|markdown('default') }}
{% endif %}
</li>
{% if contest.access_code %}
Expand Down