Browse Source

Let contest administrator submit before contest starts.

pull/6/head
t123yh 7 years ago
parent
commit
44d16765c8
  1. 3
      models/contest.js
  2. 8
      modules/contest.js
  3. 11
      modules/problem.js

3
models/contest.js

@ -139,6 +139,9 @@ class Contest extends Model {
}
async newSubmission(judge_state) {
if (!(judge_state.submit_time >= this.start_time && judge_state.submit_time <= this.end_time)) {
return;
}
let problems = await this.getProblems();
if (!problems.includes(judge_state.problem_id)) throw new ErrorMessage('当前比赛中无此题目。');

8
modules/contest.js

@ -104,6 +104,7 @@ app.post('/contest/:id/edit', async (req, res) => {
contest.title = req.body.title;
contest.subtitle = req.body.subtitle;
if (!Array.isArray(req.body.problems)) req.body.problems = [req.body.problems];
if (!Array.isArray(req.body.admins)) req.body.admins = [req.body.admins];
contest.problems = req.body.problems.join('|');
contest.admins = req.body.admins.join('|');
contest.information = req.body.information;
@ -301,7 +302,9 @@ app.get('/contest/:id/submissions', async (req, res) => {
const curUser = res.locals.user;
let user = req.query.submitter && await User.fromName(req.query.submitter);
let where = {};
let where = {
submit_time: { $gte: contest.start_time, $lte: contest.end_time }
};
if (displayConfig.showOthers) {
if (user) {
where.user_id = user.id;
@ -433,6 +436,7 @@ app.get('/contest/:id/problem/:pid', async (req, res) => {
let contest_id = parseInt(req.params.id);
let contest = await Contest.fromID(contest_id);
if (!contest) throw new ErrorMessage('无此比赛。');
const curUser = res.locals.user;
let problems_id = await contest.getProblems();
@ -444,7 +448,7 @@ app.get('/contest/:id/problem/:pid', async (req, res) => {
await problem.loadRelationships();
contest.ended = contest.isEnded();
if (!(contest.isRunning() || contest.isEnded())) {
if (!await contest.isSupervisior(curUser) && !(contest.isRunning() || contest.isEnded())) {
if (await problem.isAllowedUseBy(res.locals.user)) {
return res.redirect(syzoj.utils.makeUrl(['problem', problem_id]));
}

11
modules/problem.js

@ -566,10 +566,11 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
try {
let id = parseInt(req.params.id);
let problem = await Problem.fromID(id);
const curUser = res.locals.user;
if (!problem) throw new ErrorMessage('无此题目。');
if (problem.type !== 'submit-answer' && !syzoj.config.languages[req.body.language]) throw new ErrorMessage('不支持该语言。');
if (!res.locals.user) throw new ErrorMessage('请登录后继续。', { '登录': syzoj.utils.makeUrl(['login'], { 'url': syzoj.utils.makeUrl(['problem', id]) }) });
if (!curUser) throw new ErrorMessage('请登录后继续。', { '登录': syzoj.utils.makeUrl(['login'], { 'url': syzoj.utils.makeUrl(['problem', id]) }) });
let judge_state;
if (problem.type === 'submit-answer') {
@ -596,7 +597,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
code: file.md5,
code_length: size,
language: null,
user_id: res.locals.user.id,
user_id: curUser.id,
problem_id: req.params.id
});
} else {
@ -614,7 +615,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
code: code,
code_length: code.length,
language: req.body.language,
user_id: res.locals.user.id,
user_id: curUser.id,
problem_id: req.params.id
});
}
@ -623,7 +624,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
if (contest_id) {
let contest = await Contest.fromID(contest_id);
if (!contest) throw new ErrorMessage('无此比赛。');
if (!contest.isRunning()) throw new ErrorMessage('比赛未开始或已结束。');
if ((!contest.isRunning()) && (!await contest.isSupervisior(curUser))) throw new ErrorMessage('比赛未开始或已结束。');
let problems_id = await contest.getProblems();
if (!problems_id.includes(id)) throw new ErrorMessage('无此题目。');
@ -632,7 +633,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
await judge_state.save();
} else {
if (!await problem.isAllowedUseBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。');
if (!await problem.isAllowedUseBy(curUser)) throw new ErrorMessage('您没有权限进行此操作。');
judge_state.type = 0;
await judge_state.save();
}

Loading…
Cancel
Save