mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09: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);
|
||||
|
||||
Reference in new issue
Block a user