Add more detailed permission for testcases view
This commit is contained in:
parent
b224b015a6
commit
509327b045
2 changed files with 21 additions and 5 deletions
|
@ -167,20 +167,36 @@ def get_cases_data(submission):
|
||||||
class SubmissionStatus(SubmissionDetailBase):
|
class SubmissionStatus(SubmissionDetailBase):
|
||||||
template_name = 'submission/status.html'
|
template_name = 'submission/status.html'
|
||||||
|
|
||||||
|
def access_testcases_in_contest(self):
|
||||||
|
contest = self.object.contest_or_none
|
||||||
|
if contest is None:
|
||||||
|
return False
|
||||||
|
if contest.problem.problem.is_editable_by(self.request.user):
|
||||||
|
return True
|
||||||
|
if contest.problem.contest.is_in_contest(self.request.user):
|
||||||
|
return False
|
||||||
|
if contest.participation.ended:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(SubmissionStatus, self).get_context_data(**kwargs)
|
context = super(SubmissionStatus, self).get_context_data(**kwargs)
|
||||||
submission = self.object
|
submission = self.object
|
||||||
context['last_msg'] = event.last()
|
context['last_msg'] = event.last()
|
||||||
context['batches'] = group_test_cases(submission.test_cases.all())
|
context['batches'] = group_test_cases(submission.test_cases.all())
|
||||||
context['time_limit'] = submission.problem.time_limit
|
context['time_limit'] = submission.problem.time_limit
|
||||||
|
context['can_see_testcases'] = False
|
||||||
|
|
||||||
contest = submission.contest_or_none
|
contest = submission.contest_or_none
|
||||||
prefix_length = 0
|
prefix_length = 0
|
||||||
|
can_see_testcases = self.access_testcases_in_contest()
|
||||||
|
|
||||||
if (contest is not None):
|
if (contest is not None):
|
||||||
prefix_length = contest.problem.output_prefix_override
|
prefix_length = contest.problem.output_prefix_override
|
||||||
if ((contest is None or prefix_length > 0) or self.request.user.is_superuser):
|
|
||||||
context['cases_data'] = get_cases_data(submission)
|
|
||||||
|
|
||||||
|
if contest is None or prefix_length > 0 or can_see_testcases:
|
||||||
|
context['cases_data'] = get_cases_data(submission)
|
||||||
|
context['can_see_testcases'] = True
|
||||||
try:
|
try:
|
||||||
lang_limit = submission.problem.language_limits.get(
|
lang_limit = submission.problem.language_limits.get(
|
||||||
language=submission.language)
|
language=submission.language)
|
||||||
|
|
|
@ -92,7 +92,7 @@
|
||||||
{% for case in batch.cases %}
|
{% for case in batch.cases %}
|
||||||
<tr id="{{ case.id }}" class="case-row toggle closed">
|
<tr id="{{ case.id }}" class="case-row toggle closed">
|
||||||
<td>
|
<td>
|
||||||
{%- if ((prefix_length is none or prefix_length > 0) or (request.user.is_superuser)) -%}
|
{%- if can_see_testcases -%}
|
||||||
<i class="fa fa-chevron-right fa-fw"></i>
|
<i class="fa fa-chevron-right fa-fw"></i>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- if batch.id -%}
|
{%- if batch.id -%}
|
||||||
|
@ -132,7 +132,7 @@
|
||||||
<td>{% if case.status != 'SC' %}<span class="col-title">{{_('Memory')}}: </span> {{ case.memory|kbdetailformat }}{% endif %}</td>
|
<td>{% if case.status != 'SC' %}<span class="col-title">{{_('Memory')}}: </span> {{ case.memory|kbdetailformat }}{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{% if ((prefix_length is none or prefix_length > 0) or (request.user.is_superuser)) %}
|
{% if can_see_testcases %}
|
||||||
<tr id="{{ case.id }}-output" style="display:none" class="case-feedback toggled">
|
<tr id="{{ case.id }}-output" style="display:none" class="case-feedback toggled">
|
||||||
<td colspan="5">
|
<td colspan="5">
|
||||||
<div class="case-info">
|
<div class="case-info">
|
||||||
|
|
Loading…
Add table
Reference in a new issue