From c9cd84c54cd4b664e75ef637a556511ecd9d0335 Mon Sep 17 00:00:00 2001 From: Menci Date: Wed, 21 Jun 2017 23:06:25 +0800 Subject: [PATCH 1/4] Fix can't see submission after contest --- models/judge_state.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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; + } } } From 54a3ff560bc4a981c9c3edd542f25a76f08f1f57 Mon Sep 17 00:00:00 2001 From: Menci Date: Wed, 21 Jun 2017 23:12:07 +0800 Subject: [PATCH 2/4] Fix 'Compiled' after contest --- modules/contest.js | 1 + modules/submission.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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(); From 2e510e9bb94428483e3c394084dae498e2919ade Mon Sep 17 00:00:00 2001 From: Menci Date: Wed, 21 Jun 2017 23:19:27 +0800 Subject: [PATCH 3/4] Fix markdown rendering return tag --- utility.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) { From b88f3d9d9f35a1f7568ee9973779a36b6457d255 Mon Sep 17 00:00:00 2001 From: Menci Date: Wed, 21 Jun 2017 23:21:00 +0800 Subject: [PATCH 4/4] Auto hide empty contest infomation --- views/contest.ejs | 2 ++ 1 file changed, 2 insertions(+) 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) { %>