Browse Source

Fix testcase is visible in ACM contests

pull/6/head
Menci 7 years ago
parent
commit
4598a43a1b
  1. 15
      models/judge_state.js
  2. 24
      modules/contest.js
  3. 6
      modules/submission.js
  4. 22
      views/contest_submissions.ejs
  5. 10
      views/submission_content.ejs
  6. 12
      views/submissions_item.ejs

15
models/judge_state.js

@ -129,6 +129,21 @@ class JudgeState extends Model {
} else if (this.type === 2) return false;
}
async isAllowedSeeCaseBy(user) {
await this.loadRelationships();
if (user && (await user.hasPrivilege('manage_problem') || user.id === this.problem.user_id)) return true;
else if (this.type === 0) return this.problem.is_public;
else if (this.type === 1) {
let contest = await Contest.fromID(this.type_info);
if (await contest.isRunning()) {
return contest.type === 'ioi';
} else {
return true;
}
} else if (this.type === 2) return true;
}
async isAllowedSeeDataBy(user) {
await this.loadRelationships();

24
modules/contest.js

@ -242,17 +242,19 @@ app.get('/contest/:id/submissions', async (req, res) => {
where.type_info = contest_id;
if (contest.ended || contest.type !== 'noi' || (res.locals.user && res.locals.user.is_admin)) {
let minScore = parseInt(req.query.min_score);
if (isNaN(minScore)) minScore = 0;
let maxScore = parseInt(req.query.max_score);
if (isNaN(maxScore)) maxScore = 100;
where.score = {
$and: {
$gte: parseInt(minScore),
$lte: parseInt(maxScore)
}
};
if (!((!res.locals.user || !res.locals.user.is_admin) && !contest.ended && contest.type === 'acm')) {
let minScore = parseInt(req.query.min_score);
if (isNaN(minScore)) minScore = 0;
let maxScore = parseInt(req.query.max_score);
if (isNaN(maxScore)) maxScore = 100;
where.score = {
$and: {
$gte: parseInt(minScore),
$lte: parseInt(maxScore)
}
};
}
if (req.query.language) where.language = req.query.language;
if (req.query.status) where.status = req.query.status;

6
modules/submission.js

@ -80,7 +80,11 @@ app.get('/submissions/:id/ajax', async (req, res) => {
judge_state.allowedSeeCode = await judge_state.isAllowedSeeCodeBy(res.locals.user);
judge_state.allowedSeeData = await judge_state.isAllowedSeeDataBy(res.locals.user);
let contest;
if (judge_state.type === 1) contest = await Contest.fromID(judge_state.type_info);
res.render('submissions_item', {
contest: contest,
judge: judge_state
});
} catch (e) {
@ -105,6 +109,7 @@ app.get('/submission/:id', async (req, res) => {
judge.code = await syzoj.utils.highlight(judge.code, syzoj.config.languages[judge.language].highlight);
judge.allowedSeeResult = await judge.isAllowedSeeResultBy(res.locals.user);
judge.allowedSeeCode = await judge.isAllowedSeeCodeBy(res.locals.user);
judge.allowedSeeCase = await judge.isAllowedSeeCaseBy(res.locals.user);
judge.allowedSeeData = await judge.isAllowedSeeDataBy(res.locals.user);
judge.allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user);
@ -140,6 +145,7 @@ app.get('/submission/:id/ajax', async (req, res) => {
judge.code = await syzoj.utils.highlight(judge.code, syzoj.config.languages[judge.language].highlight);
judge.allowedSeeResult = await judge.isAllowedSeeResultBy(res.locals.user);
judge.allowedSeeCode = await judge.isAllowedSeeCodeBy(res.locals.user);
judge.allowedSeeCase = await judge.isAllowedSeeCaseBy(res.locals.user);
judge.allowedSeeData = await judge.isAllowedSeeDataBy(res.locals.user);
judge.allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user);

22
views/contest_submissions.ejs

@ -8,11 +8,13 @@
<div class="field"><input name="problem_id" style="width: 50px; " type="text" value="<%= form.problem_id %>"></div>
<label style="font-size: 1.2em; margin-right: 3px; ">提交者:</label>
<div class="field"><input name="submitter" style="width: 100px; " type="text" value="<%= form.submitter %>"></div>
<% if (contest.ended || contest.type !== 'noi' || (user && user.is_admin)) { %>
<label style="font-size: 1.2em; margin-right: 3px; ">分数:</label>
<div class="field" style="padding-right: 6px; "><input name="min_score" style="width: 45px; " type="text" value="<%= form.min_score || 0 %>"></div>
<label style="font-size: 1.2em; margin-right: 7px; ">~</label>
<div class="field"><input name="max_score" style="width: 45px; " type="text" value="<%= form.max_score || 100 %>"></div>
<% if ((typeof contest === 'undefined' || !contest) || contest.ended || contest.type !== 'noi' || (user && user.is_admin)) { %>
<% if ((typeof contest === 'undefined' || !contest) || !((!user || !user.is_admin) && !contest.ended && contest.type === 'acm')) { %>
<label style="font-size: 1.2em; margin-right: 3px; ">分数:</label>
<div class="field" style="padding-right: 6px; "><input name="min_score" style="width: 45px; " type="text" value="<%= form.min_score || 0 %>"></div>
<label style="font-size: 1.2em; margin-right: 7px; ">~</label>
<div class="field"><input name="max_score" style="width: 45px; " type="text" value="<%= form.max_score || 100 %>"></div>
<% } %>
<label style="font-size: 1.2em; margin-right: 3px; ">语言:</label>
<div class="field">
<div class="ui fluid selection dropdown" id="select_language" style="width: 110px; ">
@ -68,7 +70,9 @@
<th>编号</th>
<th>题目</th>
<th>状态</th>
<th>分数</th>
<% if ((typeof contest === 'undefined' || !contest) || !((!user || !user.is_admin) && !contest.ended && contest.type === 'acm')) { %>
<th>分数</th>
<% } %>
<th>总时间</th>
<th>内存</th>
<th>代码</th>
@ -85,4 +89,10 @@
<br>
<% include page %>
</div>
<script>
$(function () {
$('#select_language').dropdown();
$('#select_status').dropdown();
});
</script>
<% include footer %>

10
views/submission_content.ejs

@ -35,7 +35,9 @@ else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);
<th>编号</th>
<th>题目名称</th>
<th>状态</th>
<th>分数</th>
<% if ((typeof contest === 'undefined' || !contest) || !((!user || !user.is_admin) && !contest.ended && contest.type === 'acm')) { %>
<th>分数</th>
<% } %>
<th>总时间</th>
<th>内存</th>
<th>代码</th>
@ -52,7 +54,9 @@ else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);
<i class="<%= icon[getStatusMeta(judge.status)] || 'remove' %> icon"></i>
<%= judge.result.status %>
</td>
<td class="score score_<%= parseInt(judge.result.score / 10) || 0 %>"><%= judge.result.score %></td>
<% if ((typeof contest === 'undefined' || !contest) || !((!user || !user.is_admin) && !contest.ended && contest.type === 'acm')) { %>
<td class="score score_<%= parseInt(judge.result.score / 10) || 0 %>"><%= judge.result.score %></td>
<% } %>
<td><%= judge.result.total_time %> ms</td>
<td><%= parseInt(judge.result.max_memory) || 0 %> K</td>
<% if (judge.allowedSeeCode) { %>
@ -106,7 +110,7 @@ else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);
<% } else if (judge.result.spj_compiler_output) { %>
<h3 class="ui header">Special Judge 编译信息</h3>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%- syzoj.utils.ansiToHTML(judge.result.spj_compiler_output) %></code></pre></div>
<% } else if (judge.allowedSeeResult && judge.result.subtasks && (judge.result.subtasks.length !== 1 || judge.result.subtasks[0].case_num)) { %>
<% } else if (judge.allowedSeeResult && judge.allowedSeeCase && judge.result.subtasks && (judge.result.subtasks.length !== 1 || judge.result.subtasks[0].case_num)) { %>
<div class="ui styled fluid accordion" id="subtasks_list">
<% let subtask_count = 0; %>
<% for (let subtask_cases of (judge.result.subtasks || [])) { %>

12
views/submissions_item.ejs

@ -17,7 +17,9 @@ textFit(e, { maxFontSize: 14 });
<%= judge.status %>
</span>
</a></td>
<td><a href="<%= syzoj.utils.makeUrl(['submission', judge.id]) %>"><span class="score score_<%= parseInt(judge.result.score / 10) || 0 %>"><%= judge.result.score %></span></a></td>
<% if ((typeof contest === 'undefined' || !contest) || !((!user || !user.is_admin) && !contest.ended && contest.type === 'acm')) { %>
<td><a href="<%= syzoj.utils.makeUrl(['submission', judge.id]) %>"><span class="score score_<%= parseInt(judge.result.score / 10) || 0 %>"><%= judge.result.score %></span></a></td>
<% } %>
<td><%= judge.result.total_time %> ms</td>
<td><%= parseInt(judge.result.max_memory) || 0 %> K</td>
<% if (judge.allowedSeeCode) { %>
@ -27,7 +29,9 @@ textFit(e, { maxFontSize: 14 });
<% } %>
<% } else { %>
<td>隐藏</td>
<td>隐藏</td>
<% if ((typeof contest === 'undefined' || !contest) || !((!user || !user.is_admin) && !contest.ended && contest.type === 'acm')) { %>
<td>隐藏</td>
<% } %>
<td>隐藏</td>
<td>隐藏</td>
<td>隐藏</td>
@ -39,9 +43,7 @@ textFit(e, { maxFontSize: 14 });
function update_judge_<%= judge.id %>() {
setTimeout(function () {
<%
let url;
if (typeof contest !== 'undefined' && contest) url = syzoj.utils.makeUrl(['contest', contest.id, 'submissions', judge.id, 'ajax']);
else url = syzoj.utils.makeUrl(['submissions', judge.id, 'ajax']);
let url = syzoj.utils.makeUrl(['submissions', judge.id, 'ajax']);
%>
$.get('<%= url %>', function (data) {
var e = $('#submissions_<%= judge.id %>');

Loading…
Cancel
Save