diff --git a/models/judge_state.js b/models/judge_state.js index 546123d..a3e33b4 100644 --- a/models/judge_state.js +++ b/models/judge_state.js @@ -105,7 +105,12 @@ class JudgeState extends Model { if (user && user.id === this.problem.user_id) return true; else if (this.type === 0 || this.type == 2) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem'))); else if (this.type === 1) { - return user && (user.is_admin || user.id === this.user_id); + let contest = await Contest.fromID(this.type_info); + if (await contest.isRunning()) { + return (user && this.user_id === user.id) || (user && user.is_admin); + } else { + return true; + } } } diff --git a/modules/contest.js b/modules/contest.js index 1454fcf..35969fd 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -118,6 +118,7 @@ app.get('/contest/:id', async (req, res) => { contest.allowedEdit = await contest.isAllowedEditBy(res.locals.user); contest.running = await contest.isRunning(); + contest.ended = await contest.isEnded(); contest.subtitle = await syzoj.utils.markdown(contest.subtitle); contest.information = await syzoj.utils.markdown(contest.information); diff --git a/modules/submission.js b/modules/submission.js index ffb1bea..56b86bc 100644 --- a/modules/submission.js +++ b/modules/submission.js @@ -97,6 +97,8 @@ app.get('/submissions/:id/ajax', async (req, res) => { let contest; if (judge_state.type === 1) { contest = await Contest.fromID(judge_state.type_info); + contest.ended = await contest.isEnded(); + let problems_id = await contest.getProblems(); judge_state.problem_id = problems_id.indexOf(judge_state.problem_id) + 1; judge_state.problem.title = syzoj.utils.removeTitleTag(judge_state.problem.title); @@ -127,7 +129,10 @@ app.get('/submission/:id', async (req, res) => { if (!judge || !await judge.isAllowedVisitBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); let contest; - if (judge.type === 1) contest = await Contest.fromID(judge.type_info); + if (judge.type === 1) { + contest = await Contest.fromID(judge.type_info); + contest.ended = await contest.isEnded(); + } await judge.loadRelationships(); @@ -169,7 +174,10 @@ app.get('/submission/:id/ajax', async (req, res) => { if (!judge || !await judge.isAllowedVisitBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); let contest; - if (judge.type === 1) contest = await Contest.fromID(judge.type_info); + if (judge.type === 1) { + contest = await Contest.fromID(judge.type_info); + contest.ended = await contest.isEnded(); + } await judge.loadRelationships(); diff --git a/utility.js b/utility.js index bf987ab..94e6839 100644 --- a/utility.js +++ b/utility.js @@ -111,7 +111,9 @@ module.exports = { .split('
').join('
').split('
').join(''); let cheerio = require('cheerio'); - let $ = cheerio.load(s); + let $ = cheerio.load(''); + let body = $('body'); + body.html(s); let a = $('img:only-child'); for (let img of Array.from(a)) { @@ -121,7 +123,7 @@ module.exports = { } } - return $.html(); + return body.html(); }; return new Promise((resolve, reject) => { if (!keys) { diff --git a/views/contest.ejs b/views/contest.ejs index 303acdd..ea21a3d 100644 --- a/views/contest.ejs +++ b/views/contest.ejs @@ -35,6 +35,7 @@ <% } %> + <% if (contest.information) { %>

信息与公告

@@ -43,6 +44,7 @@
+ <% } %> <% if (unveiled) { %>