Browse Source

Add is_public field to judge_state table

master
hewenyang 7 years ago
parent
commit
d5bcbe8fb7
  1. 9
      models/judge_state.js
  2. 8
      modules/problem.js
  3. 4
      modules/submission.js

9
models/judge_state.js

@ -60,7 +60,8 @@ let model = db.define('judge_state', {
* use this way represent because it's easy to expand // Menci:这锅我不背,是 Chenyao 留下来的坑。
*/
type: { type: Sequelize.INTEGER },
type_info: { type: Sequelize.INTEGER }
type_info: { type: Sequelize.INTEGER },
is_public: { type: Sequelize.BOOLEAN }
}, {
timestamps: false,
tableName: 'judge_state',
@ -79,6 +80,9 @@ let model = db.define('judge_state', {
},
{
fields: ['task_id'],
},
{
fields: ['is_public', 'id']
}
]
});
@ -104,7 +108,8 @@ class JudgeState extends Model {
max_memory: null,
status: 'Unknown',
result: null,
task_id: randomstring.generate(10)
task_id: randomstring.generate(10),
is_public: false
}, val)));
}

8
modules/problem.js

@ -583,6 +583,8 @@ async function setPublic(req, res, is_public) {
problem.publicizer_id = res.locals.user.id;
await problem.save();
await syzoj.db.query("UPDATE `judge_state` JOIN `problem` ON `problem`.`id` = `judge_state`.`problem_id` SET `judge_state`.`is_public` = `problem`.`is_public` WHERE `problem`.`id` = " + id);
res.redirect(syzoj.utils.makeUrl(['problem', id]));
} catch (e) {
syzoj.log(e);
@ -636,7 +638,8 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
code_length: size,
language: null,
user_id: curUser.id,
problem_id: req.params.id
problem_id: req.params.id,
is_public: problem.is_public
});
} else {
let code;
@ -654,7 +657,8 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
code_length: code.length,
language: req.body.language,
user_id: curUser.id,
problem_id: req.params.id
problem_id: req.params.id,
is_public: problem.is_public
});
}

4
modules/submission.js

@ -104,8 +104,8 @@ app.get('/submissions', async (req, res) => {
throw new ErrorMessage("您没有权限进行此操作。");
}
} else {
where.problem_id = {
$in: syzoj.db.literal('(SELECT `id` FROM `problem` WHERE `is_public` = 1)'),
where.is_public = {
$eq: true,
};
}
} else {

Loading…
Cancel
Save