Add view public submissions permission

This commit is contained in:
cuom1999 2022-06-16 14:46:29 +07:00
parent fdb71ba3c4
commit eb44b6510a
4 changed files with 26 additions and 0 deletions

View file

@ -17,6 +17,12 @@ def submission_layout(
if user.has_perm("judge.change_submission"):
can_view = True
if user.has_perm("judge.view_all_submission"):
can_view = True
if user.has_perm("judge.view_public_submission"):
can_view = True
if submission.problem_id in completed_problem_ids:
can_view |= (
submission.problem.is_public or profile_id in submission.problem.tester_ids

View file

@ -0,0 +1,17 @@
# Generated by Django 2.2.25 on 2022-06-16 07:42
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('judge', '0126_languagetemplate'),
]
operations = [
migrations.AlterModelOptions(
name='submission',
options={'permissions': (('abort_any_submission', 'Abort any submission'), ('rejudge_submission', 'Rejudge the submission'), ('rejudge_submission_lot', 'Rejudge a lot of submissions'), ('spam_submission', 'Submit without limit'), ('view_all_submission', 'View all submission'), ('resubmit_other', "Resubmit others' submission"), ('view_public_submission', 'View public submissions')), 'verbose_name': 'submission', 'verbose_name_plural': 'submissions'},
),
]

View file

@ -230,6 +230,7 @@ class Submission(models.Model):
("spam_submission", "Submit without limit"),
("view_all_submission", "View all submission"),
("resubmit_other", "Resubmit others' submission"),
("view_public_submission", "View public submissions"),
)
verbose_name = _("submission")
verbose_name_plural = _("submissions")

View file

@ -88,6 +88,8 @@ class SubmissionDetailBase(LoginRequiredMixin, TitleMixin, SubmissionMixin, Deta
problem = submission.problem
if self.request.user.has_perm("judge.view_all_submission"):
return submission
if problem.is_public and self.request.user.has_perm("judge.view_public_submission"):
return submission
if submission.user_id == profile.id:
return submission
if problem.is_editor(profile):