Skip to content

Commit

Permalink
show code, hide status
Browse files Browse the repository at this point in the history
  • Loading branch information
twd2 committed Sep 16, 2016
1 parent 5115433 commit 4f9783d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions vj4/handler/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,31 @@ async def get(self, *, rid: objectid.ObjectId):
rdoc = await record.get(rid)
if not rdoc:
raise error.RecordNotFoundError(rid)
# TODO(iceboy): Check domain permission in place.
# TODO(iceboy): Check domain permission, permission for visibility in place.
if rdoc['domain_id'] != self.domain_id:
self.redirect(self.reverse_url('record_detail', rid=rid, domain_id=rdoc['domain_id']))
return
# check permission for visibility: contest
show_status = True
if rdoc['tid']:
now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
tdoc = await contest.get(rdoc['domain_id'], rdoc['tid'])
if not contest.RULES[tdoc['rule']].show_func(tdoc, now):
self.check_perm(builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS)
show_status = contest.RULES[tdoc['rule']].show_func(tdoc, now) \
or self.has_perm(builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS)
# TODO(twd2): futher check permission for visibility.
if (not self.own(rdoc, field='uid')
and not self.has_perm(builtin.PERM_READ_RECORD_CODE)
and not self.has_priv(builtin.PRIV_READ_RECORD_CODE)):
del rdoc['code']
if not show_status and 'code' not in rdoc:
raise error.PermissionError(builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS)
udoc, dudoc, pdoc = await asyncio.gather(user.get_by_uid(rdoc['uid']),
domain.get_user(self.domain_id, rdoc['uid']),
problem.get(rdoc['domain_id'], rdoc['pid']))
if pdoc.get('hidden', False) and not self.has_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN):
pdoc = None
self.render('record_detail.html', rdoc=rdoc, udoc=udoc, dudoc=dudoc, pdoc=pdoc)
self.render('record_detail.html', rdoc=rdoc, udoc=udoc, dudoc=dudoc, pdoc=pdoc,
show_status=show_status)


@app.route('/records/{rid}/rejudge', 'record_rejudge')
Expand Down
4 changes: 4 additions & 0 deletions vj4/ui/templates/record_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% block content %}
<div class="row">
<div class="medium-9 columns">
{% if show_status %}
<div class="section">
<div class="section__header">
<h1 class="section__title">
Expand Down Expand Up @@ -58,6 +59,7 @@ <h1 class="section__title">
</div>
{% endif %}
</div>
{% endif %}
{% if rdoc['code'] %}
<div class="section">
<div class="section__header">
Expand Down Expand Up @@ -111,6 +113,7 @@ <h1 class="section__title">{{ _('Information') }}</h1>
{% endif %}
<p>{{ _('Language') }}: {{ vj4.constant.language.LANG_TEXTS[rdoc['lang']] }}</p>
<p>{{ _('Submit At') }}: {{ datetime_span(rdoc['_id'].generation_time) }}</p>
{% if show_status %}
{% if rdoc['judge_at'] %}
<p>{{ _('Judged At') }}: {{ datetime_span(rdoc['judge_at']) }}</p>
{% endif %}
Expand All @@ -119,6 +122,7 @@ <h1 class="section__title">{{ _('Information') }}</h1>
{% endif %}
<p>{{ _('Total Time') }}: {{ rdoc['time_ms'] }}ms</p>
<p>{{ _('Peak Memory') }}: {{ rdoc['memory_kb'] / 1000 }}MiB</p>
{% endif %}
</div>
</div>
<div class="section side">
Expand Down

0 comments on commit 4f9783d

Please sign in to comment.