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

Make Problem.is_accessible_by consistent with Problem.get_visible_problems #1420

Merged
merged 1 commit into from
Jun 3, 2020
Merged
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
15 changes: 8 additions & 7 deletions judge/models/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def is_editable_by(self, user):
return False
if user.has_perm('judge.edit_all_problem') or user.has_perm('judge.edit_public_problem') and self.is_public:
return True
return user.has_perm('judge.edit_own_problem') and self.is_editor(user.profile)
return user.has_perm('judge.edit_own_problem') and user.profile.id in self.editor_ids

def is_accessible_by(self, user, skip_contest_problem_check=False):
# Problem is public.
Expand All @@ -194,15 +194,16 @@ def is_accessible_by(self, user, skip_contest_problem_check=False):
self.organizations.filter(id__in=user.profile.organizations.all()):
return True

if not user.is_authenticated:
return False

# If the user can view all problems.
if user.has_perm('judge.see_private_problem'):
return True

if not user.is_authenticated:
return False

# If the user authored the problem or is a curator.
if user.has_perm('judge.edit_own_problem') and self.is_editor(user.profile):
# If the user can edit the problem.
# We are using self.editor_ids to take advantage of caching.
if self.is_editable_by(user) or user.profile.id in self.editor_ids:
return True

# If user is a tester.
Expand Down Expand Up @@ -241,7 +242,7 @@ def get_visible_problems(cls, user):

if not (user.has_perm('judge.see_private_problem') or user.has_perm('judge.edit_all_problem')):
q = Q(is_public=True)
if not user.has_perm('judge.see_organization_problem'):
if not (user.has_perm('judge.see_organization_problem') or user.has_perm('judge.edit_public_problem')):
# Either not organization private or in the organization.
q &= (
Q(is_organization_private=False) |
Expand Down