From 13ffb7148d5c8503362bc674a238482843797bfc Mon Sep 17 00:00:00 2001 From: Menci Date: Tue, 4 Jul 2017 14:39:33 +0800 Subject: [PATCH] Redirect to problem page when contest is not started --- modules/contest.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/contest.js b/modules/contest.js index 369fc17..c5c0b59 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -330,9 +330,6 @@ app.get('/contest/:id/:pid', async (req, res) => { let contest_id = parseInt(req.params.id); let contest = await Contest.fromID(contest_id); - contest.ended = await contest.isEnded(); - if (!(await contest.isRunning() || contest.ended)) throw new ErrorMessage('比赛尚未开始或已结束。'); - let problems_id = await contest.getProblems(); let pid = parseInt(req.params.pid); @@ -341,6 +338,14 @@ app.get('/contest/:id/:pid', async (req, res) => { let problem_id = problems_id[pid - 1]; let problem = await Problem.fromID(problem_id); + contest.ended = await contest.isEnded(); + if (!(await contest.isRunning() || contest.ended)) { + if (await problem.isAllowedUseBy(res.locals.user)) { + return res.redirect(syzoj.utils.makeUrl(['problem', problem_id])); + } + throw new ErrorMessage('比赛尚未开始。'); + } + problem.specialJudge = await problem.hasSpecialJudge(); await syzoj.utils.markdown(problem, [ 'description', 'input_format', 'output_format', 'example', 'limit_and_hint' ]);