Skip to content

Commit

Permalink
Make Problem.is_accessible_by consistent with `Problem.get_visible_…
Browse files Browse the repository at this point in the history
…problems`
  • Loading branch information
Ninjaclasher authored and Xyene committed Jun 3, 2020
1 parent 2105b60 commit d8e3ca5
Showing 1 changed file with 8 additions and 7 deletions.
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

0 comments on commit d8e3ca5

Please sign in to comment.