Browse Source

Disallow user with manage_problem privilege to see contest status

pull/6/head
Menci 8 years ago
parent
commit
18c90bb1d3
  1. 24
      models/judge_state.js

24
models/judge_state.js

@ -102,12 +102,12 @@ class JudgeState extends Model {
async isAllowedSeeResultBy(user) { async isAllowedSeeResultBy(user) {
await this.loadRelationships(); await this.loadRelationships();
if (user && (await user.hasPrivilege('manage_problem') || user.id === this.problem.user_id)) return true; if (user && user.id === this.problem.user_id) return true;
else if (this.type === 0) return true; else if (this.type === 0) return true;
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()) {
return contest.type === 'acm' || contest.type === 'ioi'; return (contest.type === 'acm' || contest.type === 'ioi') || (user && user.is_admin);
} else { } else {
return true; return true;
} }
@ -117,27 +117,27 @@ class JudgeState extends Model {
async isAllowedSeeCodeBy(user) { async isAllowedSeeCodeBy(user) {
await this.loadRelationships(); await this.loadRelationships();
if (user && (await user.hasPrivilege('manage_problem') || user.id === this.problem.user_id)) return true; if (user && user.id === this.problem.user_id) return true;
else if (this.type === 0) return this.problem.is_public; 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()) {
return user && this.user_id === user.id; return (user && this.user_id === user.id) || (user && user.is_admin);
} else { } else {
return true; return true;
} }
} else if (this.type === 2) return false; } else if (this.type === 2) return user && (await user.hasPrivilege('manage_problem'));
} }
async isAllowedSeeCaseBy(user) { async isAllowedSeeCaseBy(user) {
await this.loadRelationships(); await this.loadRelationships();
if (user && (await user.hasPrivilege('manage_problem') || user.id === this.problem.user_id)) return true; if (user && user.id === this.problem.user_id) return true;
else if (this.type === 0) return this.problem.is_public; 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()) {
return contest.type === 'ioi'; return contest.type === 'ioi' || (user && user.is_admin);
} else { } else {
return true; return true;
} }
@ -147,12 +147,12 @@ class JudgeState extends Model {
async isAllowedSeeDataBy(user) { async isAllowedSeeDataBy(user) {
await this.loadRelationships(); await this.loadRelationships();
if (user && (await user.hasPrivilege('manage_problem') || user.id === this.problem.user_id)) return true; if (user && user.id === this.problem.user_id) return true;
else if (this.type === 0) return this.problem.is_public; 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()) {
return false; return user && user.is_admin;
} else { } else {
return true; return true;
} }

Loading…
Cancel
Save