Browse Source

Merge branch 'master' of https://github.com/syzoj/syzoj

pull/6/head
Pisces000221 8 years ago
parent
commit
181615ecf8
  1. 7
      models/judge_state.js
  2. 1
      modules/contest.js
  3. 12
      modules/submission.js
  4. 6
      utility.js
  5. 2
      views/contest.ejs

7
models/judge_state.js

@ -105,7 +105,12 @@ class JudgeState extends Model {
if (user && user.id === this.problem.user_id) return true; 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 === 0 || this.type == 2) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem')));
else if (this.type === 1) { 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;
}
} }
} }

1
modules/contest.js

@ -118,6 +118,7 @@ app.get('/contest/:id', async (req, res) => {
contest.allowedEdit = await contest.isAllowedEditBy(res.locals.user); contest.allowedEdit = await contest.isAllowedEditBy(res.locals.user);
contest.running = await contest.isRunning(); contest.running = await contest.isRunning();
contest.ended = await contest.isEnded();
contest.subtitle = await syzoj.utils.markdown(contest.subtitle); contest.subtitle = await syzoj.utils.markdown(contest.subtitle);
contest.information = await syzoj.utils.markdown(contest.information); contest.information = await syzoj.utils.markdown(contest.information);

12
modules/submission.js

@ -97,6 +97,8 @@ app.get('/submissions/:id/ajax', async (req, res) => {
let contest; let contest;
if (judge_state.type === 1) { if (judge_state.type === 1) {
contest = await Contest.fromID(judge_state.type_info); contest = await Contest.fromID(judge_state.type_info);
contest.ended = await contest.isEnded();
let problems_id = await contest.getProblems(); let problems_id = await contest.getProblems();
judge_state.problem_id = problems_id.indexOf(judge_state.problem_id) + 1; judge_state.problem_id = problems_id.indexOf(judge_state.problem_id) + 1;
judge_state.problem.title = syzoj.utils.removeTitleTag(judge_state.problem.title); 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('您没有权限进行此操作。'); if (!judge || !await judge.isAllowedVisitBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。');
let contest; 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(); 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('您没有权限进行此操作。'); if (!judge || !await judge.isAllowedVisitBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。');
let contest; 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(); await judge.loadRelationships();

6
utility.js

@ -111,7 +111,9 @@ module.exports = {
.split('<blockquote>').join('<div class="ui message">').split('</blockquote>').join('</div>'); .split('<blockquote>').join('<div class="ui message">').split('</blockquote>').join('</div>');
let cheerio = require('cheerio'); let cheerio = require('cheerio');
let $ = cheerio.load(s); let $ = cheerio.load('<html><head></head><body></body></html>');
let body = $('body');
body.html(s);
let a = $('img:only-child'); let a = $('img:only-child');
for (let img of Array.from(a)) { for (let img of Array.from(a)) {
@ -121,7 +123,7 @@ module.exports = {
} }
} }
return $.html(); return body.html();
}; };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!keys) { if (!keys) {

2
views/contest.ejs

@ -35,6 +35,7 @@
</div> </div>
</div> </div>
<% } %> <% } %>
<% if (contest.information) { %>
<div class="row"> <div class="row">
<div class="column"> <div class="column">
<h4 class="ui top attached block header">信息与公告</h4> <h4 class="ui top attached block header">信息与公告</h4>
@ -43,6 +44,7 @@
</div> </div>
</div> </div>
</div> </div>
<% } %>
<% if (unveiled) { %> <% if (unveiled) { %>
<div class="row"> <div class="row">
<div class="column"> <div class="column">

Loading…
Cancel
Save