mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: allow view solution & others code after accept
This commit is contained in:
1 parent
c0ac4302a2
commit
489327cc0d
7 files changed
+41
-25
No files matched your search
@@ -16,7 +16,7 @@ import {
|
||||
} from '../interface';
|
||||
import paginate from '../lib/paginate';
|
||||
import { isPid, parsePid as convertPid } from '../lib/validator';
|
||||
import { PERM, PRIV } from '../model/builtin';
|
||||
import { PERM, PRIV, STATUS } from '../model/builtin';
|
||||
import * as contest from '../model/contest';
|
||||
import * as discussion from '../model/discussion';
|
||||
import domain from '../model/domain';
|
||||
@@ -650,7 +650,10 @@ export class ProblemSolutionHandler extends ProblemDetailHandler {
|
||||
async get(domainId: string, page = 1, tid?: ObjectID) {
|
||||
if (tid) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_SOLUTION);
|
||||
this.response.template = 'problem_solution.html';
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION);
|
||||
const accepted = this.tsdoc?.status === STATUS.STATUS_ACCEPTED;
|
||||
if (!accepted || !this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION_ACCEPT)) {
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION);
|
||||
}
|
||||
const [psdocs, pcount, pscount] = await paginate(
|
||||
solution.getMulti(domainId, this.pdoc.docId),
|
||||
page,
|
||||
@@ -754,7 +757,10 @@ export class ProblemSolutionRawHandler extends ProblemDetailHandler {
|
||||
@param('tid', Types.ObjectID, true)
|
||||
async get(domainId: string, psid: ObjectID, psrid?: ObjectID, tid?: ObjectID) {
|
||||
if (tid) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_SOLUTION);
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION);
|
||||
const accepted = this.tsdoc?.status === STATUS.STATUS_ACCEPTED;
|
||||
if (!accepted || !this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION_ACCEPT)) {
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION);
|
||||
}
|
||||
if (psrid) {
|
||||
const [psdoc, psrdoc] = await solution.getReply(domainId, psid, psrid);
|
||||
if ((!psdoc) || psdoc.parentId !== this.pdoc.docId) throw new SolutionNotFoundError(psid, psrid);
|
||||
|
||||
@@ -115,11 +115,15 @@ class RecordDetailHandler extends Handler {
|
||||
canView ||= contest.canShowSelfRecord.call(this, tdoc, true) && rdoc.uid === this.user._id;
|
||||
if (!canView) throw new PermissionError(rid);
|
||||
}
|
||||
if (rdoc.uid !== this.user._id && !this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE)) {
|
||||
if (!this.user.hasPerm(PERM.PERM_READ_RECORD_CODE)) {
|
||||
rdoc.code = '';
|
||||
rdoc.compilerTexts = [];
|
||||
}
|
||||
let canViewCode = rdoc.uid === this.user._id;
|
||||
canViewCode ||= this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE);
|
||||
if (!canViewCode && this.user.hasPerm(PERM.PERM_READ_RECORD_CODE_ACCEPT)) {
|
||||
const self = await problem.getStatus(domainId, rdoc.pid, this.user._id);
|
||||
canViewCode ||= self.status === STATUS.STATUS_ACCEPTED;
|
||||
}
|
||||
if (!canViewCode) {
|
||||
rdoc.code = '';
|
||||
rdoc.compilerTexts = [];
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [pdoc, udoc] = await Promise.all([
|
||||
@@ -277,11 +281,15 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
||||
canView ||= this.user._id === rdoc.uid && contest.canShowSelfRecord.call(this, tdoc);
|
||||
if (!canView) throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
|
||||
}
|
||||
if (rdoc.uid !== this.user._id && !this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE)) {
|
||||
if (!this.user.hasPerm(PERM.PERM_READ_RECORD_CODE)) {
|
||||
rdoc.code = '';
|
||||
rdoc.compilerTexts = [];
|
||||
}
|
||||
let canViewCode = rdoc.uid === this.user._id;
|
||||
canViewCode ||= this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE);
|
||||
if (!canViewCode && this.user.hasPerm(PERM.PERM_READ_RECORD_CODE_ACCEPT)) {
|
||||
const self = await problem.getStatus(domainId, rdoc.pid, this.user._id);
|
||||
canViewCode ||= self.status === STATUS.STATUS_ACCEPTED;
|
||||
}
|
||||
if (!canViewCode) {
|
||||
rdoc.code = '';
|
||||
rdoc.compilerTexts = [];
|
||||
}
|
||||
const pdoc = await problem.get(rdoc.domainId, rdoc.pid);
|
||||
let canView = pdoc && this.user.own(pdoc);
|
||||
|
||||
@@ -14,7 +14,7 @@ export const PERM = {
|
||||
PERM_EDIT_DOMAIN: 1n << 1n,
|
||||
PERM_MOD_BADGE: 1n << 2n,
|
||||
|
||||
// Problem and Record
|
||||
// Problem
|
||||
PERM_CREATE_PROBLEM: 1n << 4n,
|
||||
PERM_EDIT_PROBLEM: 1n << 5n,
|
||||
PERM_EDIT_PROBLEM_SELF: 1n << 6n,
|
||||
@@ -22,12 +22,16 @@ export const PERM = {
|
||||
PERM_VIEW_PROBLEM_HIDDEN: 1n << 8n,
|
||||
PERM_SUBMIT_PROBLEM: 1n << 9n,
|
||||
PERM_READ_PROBLEM_DATA: 1n << 10n,
|
||||
|
||||
// Record
|
||||
PERM_READ_RECORD_CODE: 1n << 12n,
|
||||
PERM_READ_RECORD_CODE_ACCEPT: 1n << 64n,
|
||||
PERM_REJUDGE_PROBLEM: 1n << 13n,
|
||||
PERM_REJUDGE: 1n << 14n,
|
||||
|
||||
// Problem Solution
|
||||
PERM_VIEW_PROBLEM_SOLUTION: 1n << 15n,
|
||||
PERM_VIEW_PROBLEM_SOLUTION_ACCEPT: 1n << 65n,
|
||||
PERM_CREATE_PROBLEM_SOLUTION: 1n << 16n,
|
||||
PERM_VOTE_PROBLEM_SOLUTION: 1n << 17n,
|
||||
PERM_EDIT_PROBLEM_SOLUTION: 1n << 18n,
|
||||
@@ -106,9 +110,11 @@ export const PERMS = [
|
||||
Permission('perm_problem', PERM.PERM_SUBMIT_PROBLEM, 'Submit problem'),
|
||||
Permission('perm_problem', PERM.PERM_READ_PROBLEM_DATA, 'Read data of problem'),
|
||||
Permission('perm_record', PERM.PERM_READ_RECORD_CODE, 'Read record codes'),
|
||||
Permission('perm_record', PERM.PERM_READ_RECORD_CODE_ACCEPT, 'Read record codes after accept'),
|
||||
Permission('perm_record', PERM.PERM_REJUDGE_PROBLEM, 'Rejudge problems'),
|
||||
Permission('perm_record', PERM.PERM_REJUDGE, 'Rejudge records'),
|
||||
Permission('perm_problem_solution', PERM.PERM_VIEW_PROBLEM_SOLUTION, 'View problem solutions'),
|
||||
Permission('perm_problem_solution', PERM.PERM_VIEW_PROBLEM_SOLUTION_ACCEPT, 'View problem solutions after accept'),
|
||||
Permission('perm_problem_solution', PERM.PERM_CREATE_PROBLEM_SOLUTION, 'Create problem solutions'),
|
||||
Permission('perm_problem_solution', PERM.PERM_VOTE_PROBLEM_SOLUTION, 'Vote problem solutions'),
|
||||
Permission('perm_problem_solution', PERM.PERM_EDIT_PROBLEM_SOLUTION, 'Edit problem solutions'),
|
||||
@@ -164,6 +170,7 @@ for (const p of PERMS) {
|
||||
PERM.PERM_BASIC = PERM.PERM_VIEW
|
||||
| PERM.PERM_VIEW_PROBLEM
|
||||
| PERM.PERM_VIEW_PROBLEM_SOLUTION
|
||||
| PERM.PERM_VIEW_PROBLEM_SOLUTION_ACCEPT
|
||||
| PERM.PERM_VIEW_DISCUSSION
|
||||
| PERM.PERM_VIEW_CONTEST
|
||||
| PERM.PERM_VIEW_CONTEST_SCOREBOARD
|
||||
@@ -177,6 +184,7 @@ PERM.PERM_DEFAULT = PERM.PERM_VIEW
|
||||
| PERM.PERM_EDIT_PROBLEM_SELF
|
||||
| PERM.PERM_SUBMIT_PROBLEM
|
||||
| PERM.PERM_VIEW_PROBLEM_SOLUTION
|
||||
| PERM.PERM_VIEW_PROBLEM_SOLUTION_ACCEPT
|
||||
| PERM.PERM_CREATE_PROBLEM_SOLUTION
|
||||
| PERM.PERM_VOTE_PROBLEM_SOLUTION
|
||||
| PERM.PERM_EDIT_PROBLEM_SOLUTION_SELF
|
||||
|
||||
Reference in new issue
Block a user