From 09b2047f963b791e082209d9318ff50d3466c449 Mon Sep 17 00:00:00 2001 From: Pisces000221 <1786762946@qq.com> Date: Thu, 6 Jul 2017 22:24:54 +0800 Subject: [PATCH] Fix link to additional files during contests --- modules/contest.js | 1 + modules/problem.js | 13 ++++++++++++- views/problem.ejs | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/contest.js b/modules/contest.js index 9c7b042..d291552 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -337,6 +337,7 @@ app.get('/contest/:id/:pid', async (req, res) => { let problem_id = problems_id[pid - 1]; let problem = await Problem.fromID(problem_id); + await problem.loadRelationships(); contest.ended = await contest.isEnded(); if (!(await contest.isRunning() || contest.ended)) { diff --git a/modules/problem.js b/modules/problem.js index 9961334..873e29f 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -749,7 +749,18 @@ app.get('/problem/:id/download/additional_file', async (req, res) => { let problem = await Problem.fromID(id); if (!problem) throw new ErrorMessage('无此题目。'); - if (!await problem.isAllowedUseBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); + + // XXX: Reduce duplication (see the '/problem/:id/submit' handler) + let contest_id = parseInt(req.query.contest_id); + if (contest_id) { + let contest = await Contest.fromID(contest_id); + if (!contest) throw new ErrorMessage('无此比赛。'); + if (!await contest.isRunning()) throw new ErrorMessage('比赛未开始或已结束。'); + let problems_id = await contest.getProblems(); + if (!problems_id.includes(id)) throw new ErrorMessage('无此题目。'); + } else { + if (!await problem.isAllowedUseBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); + } await problem.loadRelationships(); diff --git a/views/problem.ejs b/views/problem.ejs index c85bd62..62b8191 100644 --- a/views/problem.ejs +++ b/views/problem.ejs @@ -91,7 +91,7 @@ div[class*=ace_br] { 统计 测试数据 <% } %> - <% if (problem.additional_file) { %>附加文件<% } %> + <% if (problem.additional_file) { %>附加文件<% } %> <% if (!contest) { %>