Browse Source

Fix testcase is visible in ACM contests

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

15
models/judge_state.js

@ -129,6 +129,21 @@ class JudgeState extends Model {
} else if (this.type === 2) return false; } 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) { async isAllowedSeeDataBy(user) {
await this.loadRelationships(); await this.loadRelationships();

2
modules/contest.js

@ -242,6 +242,7 @@ app.get('/contest/:id/submissions', async (req, res) => {
where.type_info = contest_id; where.type_info = contest_id;
if (contest.ended || contest.type !== 'noi' || (res.locals.user && res.locals.user.is_admin)) { if (contest.ended || contest.type !== 'noi' || (res.locals.user && res.locals.user.is_admin)) {
if (!((!res.locals.user || !res.locals.user.is_admin) && !contest.ended && contest.type === 'acm')) {
let minScore = parseInt(req.query.min_score); let minScore = parseInt(req.query.min_score);
if (isNaN(minScore)) minScore = 0; if (isNaN(minScore)) minScore = 0;
let maxScore = parseInt(req.query.max_score); let maxScore = parseInt(req.query.max_score);
@ -253,6 +254,7 @@ app.get('/contest/:id/submissions', async (req, res) => {
$lte: parseInt(maxScore) $lte: parseInt(maxScore)
} }
}; };
}
if (req.query.language) where.language = req.query.language; if (req.query.language) where.language = req.query.language;
if (req.query.status) where.status = req.query.status; 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.allowedSeeCode = await judge_state.isAllowedSeeCodeBy(res.locals.user);
judge_state.allowedSeeData = await judge_state.isAllowedSeeDataBy(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', { res.render('submissions_item', {
contest: contest,
judge: judge_state judge: judge_state
}); });
} catch (e) { } 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.code = await syzoj.utils.highlight(judge.code, syzoj.config.languages[judge.language].highlight);
judge.allowedSeeResult = await judge.isAllowedSeeResultBy(res.locals.user); judge.allowedSeeResult = await judge.isAllowedSeeResultBy(res.locals.user);
judge.allowedSeeCode = await judge.isAllowedSeeCodeBy(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.allowedSeeData = await judge.isAllowedSeeDataBy(res.locals.user);
judge.allowedRejudge = await judge.problem.isAllowedEditBy(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.code = await syzoj.utils.highlight(judge.code, syzoj.config.languages[judge.language].highlight);
judge.allowedSeeResult = await judge.isAllowedSeeResultBy(res.locals.user); judge.allowedSeeResult = await judge.isAllowedSeeResultBy(res.locals.user);
judge.allowedSeeCode = await judge.isAllowedSeeCodeBy(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.allowedSeeData = await judge.isAllowedSeeDataBy(res.locals.user);
judge.allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user); judge.allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user);

12
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> <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> <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> <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)) { %> <% 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> <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> <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> <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> <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> <label style="font-size: 1.2em; margin-right: 3px; ">语言:</label>
<div class="field"> <div class="field">
<div class="ui fluid selection dropdown" id="select_language" style="width: 110px; "> <div class="ui fluid selection dropdown" id="select_language" style="width: 110px; ">
@ -68,7 +70,9 @@
<th>编号</th> <th>编号</th>
<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>
<th>内存</th> <th>内存</th>
<th>代码</th> <th>代码</th>
@ -85,4 +89,10 @@
<br> <br>
<% include page %> <% include page %>
</div> </div>
<script>
$(function () {
$('#select_language').dropdown();
$('#select_status').dropdown();
});
</script>
<% include footer %> <% include footer %>

6
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>
<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>
<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> <i class="<%= icon[getStatusMeta(judge.status)] || 'remove' %> icon"></i>
<%= judge.result.status %> <%= judge.result.status %>
</td> </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 class="score score_<%= parseInt(judge.result.score / 10) || 0 %>"><%= judge.result.score %></td>
<% } %>
<td><%= judge.result.total_time %> ms</td> <td><%= judge.result.total_time %> ms</td>
<td><%= parseInt(judge.result.max_memory) || 0 %> K</td> <td><%= parseInt(judge.result.max_memory) || 0 %> K</td>
<% if (judge.allowedSeeCode) { %> <% if (judge.allowedSeeCode) { %>
@ -106,7 +110,7 @@ else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);
<% } else if (judge.result.spj_compiler_output) { %> <% } else if (judge.result.spj_compiler_output) { %>
<h3 class="ui header">Special Judge 编译信息</h3> <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> <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"> <div class="ui styled fluid accordion" id="subtasks_list">
<% let subtask_count = 0; %> <% let subtask_count = 0; %>
<% for (let subtask_cases of (judge.result.subtasks || [])) { %> <% for (let subtask_cases of (judge.result.subtasks || [])) { %>

10
views/submissions_item.ejs

@ -17,7 +17,9 @@ textFit(e, { maxFontSize: 14 });
<%= judge.status %> <%= judge.status %>
</span> </span>
</a></td> </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><%= judge.result.total_time %> ms</td>
<td><%= parseInt(judge.result.max_memory) || 0 %> K</td> <td><%= parseInt(judge.result.max_memory) || 0 %> K</td>
<% if (judge.allowedSeeCode) { %> <% if (judge.allowedSeeCode) { %>
@ -27,7 +29,9 @@ textFit(e, { maxFontSize: 14 });
<% } %> <% } %>
<% } else { %> <% } 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>
<td>隐藏</td> <td>隐藏</td>
<td>隐藏</td> <td>隐藏</td>
@ -39,9 +43,7 @@ textFit(e, { maxFontSize: 14 });
function update_judge_<%= judge.id %>() { function update_judge_<%= judge.id %>() {
setTimeout(function () { setTimeout(function () {
<% <%
let url; let url = syzoj.utils.makeUrl(['submissions', judge.id, 'ajax']);
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']);
%> %>
$.get('<%= url %>', function (data) { $.get('<%= url %>', function (data) {
var e = $('#submissions_<%= judge.id %>'); var e = $('#submissions_<%= judge.id %>');

Loading…
Cancel
Save