Browse Source

Remove type === 2 submissions

pull/6/head
Menci 7 years ago
parent
commit
1a089b8dd5
  1. 21
      models/judge_state.js
  2. 2
      modules/problem.js

21
models/judge_state.js

@ -48,9 +48,8 @@ let model = db.define('judge_state', {
submit_time: { type: Sequelize.INTEGER }, submit_time: { type: Sequelize.INTEGER },
/* /*
* "type" indicate it's contest's submission(type = 1) or normal submission(type = 0) * "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 * 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: { type: Sequelize.INTEGER },
type_info: { type: Sequelize.INTEGER } type_info: { type: Sequelize.INTEGER }
@ -105,7 +104,7 @@ class JudgeState extends Model {
await this.loadRelationships(); await this.loadRelationships();
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) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem')));
else if (this.type === 1) { else if (this.type === 1) {
let contest = await Contest.fromID(this.type_info); let contest = await Contest.fromID(this.type_info);
if (await contest.isRunning()) { if (await contest.isRunning()) {
@ -120,7 +119,7 @@ class JudgeState extends Model {
await this.loadRelationships(); await this.loadRelationships();
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) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem')));
else if (this.type === 1) { else if (this.type === 1) {
let contest = await Contest.fromID(this.type_info); let contest = await Contest.fromID(this.type_info);
if (await contest.isRunning()) { if (await contest.isRunning()) {
@ -135,7 +134,7 @@ class JudgeState extends Model {
await this.loadRelationships(); await this.loadRelationships();
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) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem')));
else if (this.type === 1) { else if (this.type === 1) {
let contest = await Contest.fromID(this.type_info); let contest = await Contest.fromID(this.type_info);
if (await contest.isRunning()) { if (await contest.isRunning()) {
@ -150,7 +149,7 @@ class JudgeState extends Model {
await this.loadRelationships(); await this.loadRelationships();
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) return this.problem.is_public || (user && (await user.hasPrivilege('manage_problem')));
else if (this.type === 1) { else if (this.type === 1) {
let contest = await Contest.fromID(this.type_info); let contest = await Contest.fromID(this.type_info);
if (await contest.isRunning()) { if (await contest.isRunning()) {
@ -174,7 +173,7 @@ class JudgeState extends Model {
} }
async updateRelatedInfo(newSubmission) { async updateRelatedInfo(newSubmission) {
if (this.type === 0 || this.type === 2) { if (this.type === 0) {
if (newSubmission) { if (newSubmission) {
await this.loadRelationships(); await this.loadRelationships();
await this.user.refreshSubmitInfo(); await this.user.refreshSubmitInfo();
@ -191,12 +190,6 @@ class JudgeState extends Model {
} else if (this.type === 1) { } else if (this.type === 1) {
let contest = await Contest.fromID(this.type_info); let contest = await Contest.fromID(this.type_info);
await contest.newSubmission(this); 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(); await this.user.save();
} }
if (this.type === 0 || this.type === 2) { if (this.type === 0) {
if (oldStatus === 'Accepted') { if (oldStatus === 'Accepted') {
this.problem.ac_num--; this.problem.ac_num--;
await this.problem.save(); await this.problem.save();

2
modules/problem.js

@ -631,7 +631,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1
await judge_state.save(); await judge_state.save();
} else { } else {
if (!await problem.isAllowedUseBy(res.locals.user)) throw new ErrorMessage('您没有权限进行此操作。'); 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.save();
} }
await judge_state.updateRelatedInfo(true); await judge_state.updateRelatedInfo(true);

Loading…
Cancel
Save