Browse Source

Add is_public field to judge_state table

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

8
modules/problem.js

@ -583,6 +583,8 @@ async function setPublic(req, res, is_public) {
problem.publicizer_id = res.locals.user.id; problem.publicizer_id = res.locals.user.id;
await problem.save(); 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])); res.redirect(syzoj.utils.makeUrl(['problem', id]));
} catch (e) { } catch (e) {
syzoj.log(e); syzoj.log(e);
@ -636,7 +638,8 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
code_length: size, code_length: size,
language: null, language: null,
user_id: curUser.id, user_id: curUser.id,
problem_id: req.params.id problem_id: req.params.id,
is_public: problem.is_public
}); });
} else { } else {
let code; let code;
@ -654,7 +657,8 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
code_length: code.length, code_length: code.length,
language: req.body.language, language: req.body.language,
user_id: curUser.id, 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("您没有权限进行此操作。"); throw new ErrorMessage("您没有权限进行此操作。");
} }
} else { } else {
where.problem_id = { where.is_public = {
$in: syzoj.db.literal('(SELECT `id` FROM `problem` WHERE `is_public` = 1)'), $eq: true,
}; };
} }
} else { } else {

Loading…
Cancel
Save