core&ui: only show code on contest record (#457)

This commit is contained in:
panda authored and GitHub committed 2022-11-04 01:24:12 +08:00
1 parent 865f30fe42
commit e92cbeb1ee
2 files changed
+11 -3

No files matched your search

+5 -3
View File
@@ -1,4 +1,4 @@
import { omit, throttle } from 'lodash'; import { omit, pick, throttle } from 'lodash';
import { FilterQuery, ObjectID } from 'mongodb'; import { FilterQuery, ObjectID } from 'mongodb';
import { import {
ContestNotAttendedError, ContestNotFoundError, ForbiddenError, PermissionError, ContestNotAttendedError, ContestNotFoundError, ForbiddenError, PermissionError,
@@ -141,6 +141,7 @@ class RecordDetailHandler extends ContestDetailBaseHandler {
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
async get(domainId: string, rid: ObjectID, download = false) { async get(domainId: string, rid: ObjectID, download = false) {
const rdoc = this.rdoc; const rdoc = this.rdoc;
let canViewDetail = true;
if (rdoc.contest?.toString() === '000000000000000000000000') { if (rdoc.contest?.toString() === '000000000000000000000000') {
if (rdoc.uid !== this.user._id) throw new PermissionError(PERM.PERM_READ_RECORD_CODE); if (rdoc.uid !== this.user._id) throw new PermissionError(PERM.PERM_READ_RECORD_CODE);
} else if (rdoc.contest) { } else if (rdoc.contest) {
@@ -148,7 +149,8 @@ class RecordDetailHandler extends ContestDetailBaseHandler {
let canView = this.user.own(this.tdoc); let canView = this.user.own(this.tdoc);
canView ||= contest.canShowRecord.call(this, this.tdoc); canView ||= contest.canShowRecord.call(this, this.tdoc);
canView ||= contest.canShowSelfRecord.call(this, this.tdoc, true) && rdoc.uid === this.user._id; canView ||= contest.canShowSelfRecord.call(this, this.tdoc, true) && rdoc.uid === this.user._id;
if (!canView) throw new PermissionError(rid); if (!canView && rdoc.uid !== this.user._id) throw new PermissionError(rid);
canViewDetail = canView;
this.args.tid = this.tdoc.docId; this.args.tid = this.tdoc.docId;
} }
@@ -178,7 +180,7 @@ class RecordDetailHandler extends ContestDetailBaseHandler {
this.response.template = 'record_detail.html'; this.response.template = 'record_detail.html';
this.response.body = { this.response.body = {
udoc, rdoc, pdoc, tdoc: this.tdoc, udoc, rdoc: canViewDetail ? rdoc : pick(rdoc, ['_id', 'lang', 'code']), pdoc, tdoc: this.tdoc,
}; };
} }
@@ -1,10 +1,14 @@
{% import "components/problem.html" as problem with context %} {% import "components/problem.html" as problem with context %}
{% extends "layout/basic.html" %} {% extends "layout/basic.html" %}
{% block content %} {% block content %}
{% if typeof(rdoc['status']) === 'number' %}
{{ set(UiContext, 'socketUrl', "record-detail-conn?domainId=" + rdoc.domainId + "&rid=" + rdoc._id) }} {{ set(UiContext, 'socketUrl', "record-detail-conn?domainId=" + rdoc.domainId + "&rid=" + rdoc._id) }}
{% endif %}
<div class="row"> <div class="row">
<div class="medium-9 columns"> <div class="medium-9 columns">
{% if typeof(rdoc['status']) === 'number' %}
{% include 'record_detail_status.html' %} {% include 'record_detail_status.html' %}
{% endif %}
{% if rdoc['code'] or rdoc.files.code %} {% if rdoc['code'] or rdoc.files.code %}
<div class="section"> <div class="section">
<div class="section__header"> <div class="section__header">
@@ -90,7 +94,9 @@
<dd>{{ user.render_inline(judge_udoc, badge=false) }}</dd> <dd>{{ user.render_inline(judge_udoc, badge=false) }}</dd>
{% endif %} {% endif %}
</dl> </dl>
{% if typeof(rdoc['status']) === 'number' %}
{% include 'record_detail_summary.html' %} {% include 'record_detail_summary.html' %}
{% endif %}
</div> </div>
</div> </div>
</div> </div>