Skip to content

Commit

Permalink
Allow admins to see unpublished test packages (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
otargowski authored Jul 22, 2023
1 parent 6518a0e commit 20c3aec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion oioioi/problems/templates/problems/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</thead>
<tbody>
{% for file in files %}
<tr>
<tr {% if not file.pub_date or file.pub_date > request.timestamp %} class="text-muted" {% endif %}>
{% if add_category_field %}
<td>{{ file.category }}</td>
{% endif %}
Expand Down
15 changes: 15 additions & 0 deletions oioioi/testspackages/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,18 @@ def test_packages_visibility(self):
with fake_time(datetime(2012, 8, 5, 0, 12, tzinfo=timezone.utc)):
response = self.client.get(url)
self.assertEqual(200, response.status_code)

self.assertTrue(self.client.login(username='test_admin'))
url = reverse('contest_files', kwargs={'contest_id': contest.id})
# Admins should see even unpublished test packages
with fake_time(datetime(2012, 8, 5, 0, 10, tzinfo=timezone.utc)):
response = self.client.get(url)
self.assertContains(response, 'some_name.zip')
self.assertContains(response, 'some_name2.zip')
self.assertEqual(200, response.status_code)

with fake_time(datetime(2012, 8, 5, 1, 12, tzinfo=timezone.utc)):
response = self.client.get(url)
self.assertContains(response, 'some_name.zip')
self.assertContains(response, 'some_name2.zip')
self.assertEqual(200, response.status_code)
6 changes: 5 additions & 1 deletion oioioi/testspackages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
can_enter_contest,
contest_exists,
is_contest_admin,
is_contest_basicadmin,
visible_problem_instances,
)
from oioioi.contests.models import ProblemInstance
Expand All @@ -30,7 +31,10 @@ def visible_tests_packages(request):
return [
tp
for tp in tests_packages
if tp.is_visible(request.timestamp) and tp.package is not None
if tp.package is not None and (
is_contest_basicadmin(request) or
tp.is_visible(request.timestamp)
)
]


Expand Down

0 comments on commit 20c3aec

Please sign in to comment.