From 1a089b8dd560064e798bd626d1f055941a7eadf3 Mon Sep 17 00:00:00 2001 From: Menci Date: Mon, 10 Jul 2017 21:55:57 +0800 Subject: [PATCH] Remove type === 2 submissions --- models/judge_state.js | 21 +++++++-------------- modules/problem.js | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/models/judge_state.js b/models/judge_state.js index 81f4de6..8c429ff 100644 --- a/models/judge_state.js +++ b/models/judge_state.js @@ -48,9 +48,8 @@ let model = db.define('judge_state', { submit_time: { type: Sequelize.INTEGER }, /* * "type" indicate it's contest's submission(type = 1) or normal submission(type = 0) - * type = 2: this is a test submission * if it's contest's submission (type = 1), the type_info is contest_id - * use this way represent because it's easy to expand + * use this way represent because it's easy to expand // Menci:这锅我不背,是 Chenyao 留下来的坑。 */ type: { type: Sequelize.INTEGER }, type_info: { type: Sequelize.INTEGER } @@ -105,7 +104,7 @@ class JudgeState extends Model { await this.loadRelationships(); 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) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem'))); else if (this.type === 1) { let contest = await Contest.fromID(this.type_info); if (await contest.isRunning()) { @@ -120,7 +119,7 @@ class JudgeState extends Model { await this.loadRelationships(); 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) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem'))); else if (this.type === 1) { let contest = await Contest.fromID(this.type_info); if (await contest.isRunning()) { @@ -135,7 +134,7 @@ class JudgeState extends Model { await this.loadRelationships(); 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) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem'))); else if (this.type === 1) { let contest = await Contest.fromID(this.type_info); if (await contest.isRunning()) { @@ -150,7 +149,7 @@ class JudgeState extends Model { await this.loadRelationships(); 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) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem'))); else if (this.type === 1) { let contest = await Contest.fromID(this.type_info); if (await contest.isRunning()) { @@ -174,7 +173,7 @@ class JudgeState extends Model { } async updateRelatedInfo(newSubmission) { - if (this.type === 0 || this.type === 2) { + if (this.type === 0) { if (newSubmission) { await this.loadRelationships(); await this.user.refreshSubmitInfo(); @@ -191,12 +190,6 @@ class JudgeState extends Model { } else if (this.type === 1) { let contest = await Contest.fromID(this.type_info); await contest.newSubmission(this); - } else if (this.type === 2) { - if (newSubmission || this.status === 'Accepted') { - await this.loadRelationships(); - await this.user.refreshSubmitInfo(); - await this.user.save(); - } } } @@ -230,7 +223,7 @@ class JudgeState extends Model { await this.user.save(); } - if (this.type === 0 || this.type === 2) { + if (this.type === 0) { if (oldStatus === 'Accepted') { this.problem.ac_num--; await this.problem.save(); diff --git a/modules/problem.js b/modules/problem.js index e450ce5..e637a72 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -631,7 +631,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('您没有权限进行此操作。'); - judge_state.type = problem.is_public ? 0 : 2; + judge_state.type = 0; await judge_state.save(); } await judge_state.updateRelatedInfo(true);