Skip to content

Commit

Permalink
Allow organization admins to see all organization-private problems
Browse files Browse the repository at this point in the history
Fixes DMOJ#1440
  • Loading branch information
kiritofeng authored and Xyene committed Aug 10, 2020
1 parent 758b689 commit 6619af2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion judge/models/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ 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 user.profile.id in self.editor_ids
return user.has_perm('judge.edit_own_problem') and \
(user.profile.id in self.editor_ids or
self.is_organization_private and self.organizations.filter(admins=user.profile).exists())

def is_accessible_by(self, user, skip_contest_problem_check=False):
# Problem is public.
Expand Down Expand Up @@ -237,6 +239,7 @@ def get_visible_problems(cls, user):
# - otherwise
# - not is_public problems
# - author or curator or tester
# - is_organization_private and admin of organization
# - is_public problems
# - not is_organization_private or in organization or `judge.see_organization_problem`
# - author or curator or tester
Expand All @@ -251,6 +254,9 @@ def get_visible_problems(cls, user):
Q(is_organization_private=True, organizations__in=user.profile.organizations.all())
)

if user.has_perm('judge.edit_own_problem'):
q |= Q(is_organization_private=True, organizations__in=user.profile.admin_of.all())

# Authors, curators, and testers should always have access, so OR at the very end.
q |= Q(authors=user.profile)
q |= Q(curators=user.profile)
Expand All @@ -271,6 +277,7 @@ def get_editable_problems(cls, user):
return cls.objects.all()

q = Q(authors=user.profile) | Q(curators=user.profile)
q |= Q(is_organization_private=True, organizations__in=user.profile.admin_of.all())

if user.has_perm('judge.edit_public_problem'):
q |= Q(is_public=True)
Expand Down

0 comments on commit 6619af2

Please sign in to comment.