From 20c3aec68bd6740fc34fb01ce7ec8c4cd59cb7c9 Mon Sep 17 00:00:00 2001 From: Olaf Targowski Date: Sat, 22 Jul 2023 05:38:49 +0000 Subject: [PATCH] Allow admins to see unpublished test packages (#233) --- oioioi/problems/templates/problems/files.html | 2 +- oioioi/testspackages/tests.py | 15 +++++++++++++++ oioioi/testspackages/views.py | 6 +++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/oioioi/problems/templates/problems/files.html b/oioioi/problems/templates/problems/files.html index 1e97b2246..3f679a398 100644 --- a/oioioi/problems/templates/problems/files.html +++ b/oioioi/problems/templates/problems/files.html @@ -20,7 +20,7 @@ {% for file in files %} - + request.timestamp %} class="text-muted" {% endif %}> {% if add_category_field %} {{ file.category }} {% endif %} diff --git a/oioioi/testspackages/tests.py b/oioioi/testspackages/tests.py index 6d48c288d..a357fc15c 100644 --- a/oioioi/testspackages/tests.py +++ b/oioioi/testspackages/tests.py @@ -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) diff --git a/oioioi/testspackages/views.py b/oioioi/testspackages/views.py index 4708c1c48..dcc5512b8 100644 --- a/oioioi/testspackages/views.py +++ b/oioioi/testspackages/views.py @@ -15,6 +15,7 @@ can_enter_contest, contest_exists, is_contest_admin, + is_contest_basicadmin, visible_problem_instances, ) from oioioi.contests.models import ProblemInstance @@ -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) + ) ]