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

Fix get_queryset() on Problem admin #448

Merged
merged 2 commits into from
Jan 13, 2025
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
4 changes: 3 additions & 1 deletion oioioi/problems/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,10 @@ def get_queryset(self, request):
combined = queryset.none()
else:
combined = request.user.problem_set.all()
if request.user.is_superuser:
return queryset
if request.user.has_perm('problems.problems_db_admin'):
combined |= queryset.filter(contest__isnull=True)
combined |= queryset.filter(visibility=Problem.VISIBILITY_PUBLIC)
if is_contest_basicadmin(request):
combined |= queryset.filter(contest=request.contest)
return combined
Expand Down
6 changes: 6 additions & 0 deletions oioioi/problems/tests/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def test_admin_changelist_view(self):
self.assertContains(response, 'Sum')

self.assertTrue(self.client.login(username='test_user'))

# Users with problem.problems_db_admin can only see problems with visibility set to public.
problem = Problem.objects.get()
problem.visibility = Problem.VISIBILITY_PUBLIC
problem.save()

check_not_accessible(self, url)

user = User.objects.get(username='test_user')
Expand Down
Loading