mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: bug fix
This commit is contained in:
1 parent
489327cc0d
commit
9a6d737a4b
2 files changed
+29
-29
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "3.2.17",
|
"version": "3.2.18",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { pick } from 'lodash';
|
|
||||||
import { FilterQuery, ObjectID } from 'mongodb';
|
import { FilterQuery, ObjectID } from 'mongodb';
|
||||||
import {
|
import {
|
||||||
ContestNotAttendedError, ContestNotFoundError, PermissionError,
|
ContestNotAttendedError, ContestNotFoundError, PermissionError,
|
||||||
@@ -106,42 +105,40 @@ class RecordDetailHandler extends Handler {
|
|||||||
this.response.template = 'record_detail.html';
|
this.response.template = 'record_detail.html';
|
||||||
const rdoc = await record.get(domainId, rid);
|
const rdoc = await record.get(domainId, rid);
|
||||||
if (!rdoc) throw new RecordNotFoundError(rid);
|
if (!rdoc) throw new RecordNotFoundError(rid);
|
||||||
|
let tdoc;
|
||||||
if (rdoc.contest?.toHexString() === '000000000000000000000000') {
|
if (rdoc.contest?.toHexString() === '000000000000000000000000') {
|
||||||
if (rdoc.uid !== this.user._id) throw new PermissionError(PERM.PERM_READ_RECORD_CODE);
|
if (rdoc.uid !== this.user._id) throw new PermissionError(PERM.PERM_READ_RECORD_CODE);
|
||||||
} else if (rdoc.contest) {
|
} else if (rdoc.contest) {
|
||||||
const tdoc = await contest.get(domainId, rdoc.contest);
|
tdoc = await contest.get(domainId, rdoc.contest);
|
||||||
let canView = this.user.own(tdoc);
|
let canView = this.user.own(tdoc);
|
||||||
canView ||= contest.canShowRecord.call(this, tdoc);
|
canView ||= contest.canShowRecord.call(this, tdoc);
|
||||||
canView ||= contest.canShowSelfRecord.call(this, tdoc, true) && rdoc.uid === this.user._id;
|
canView ||= contest.canShowSelfRecord.call(this, tdoc, true) && rdoc.uid === this.user._id;
|
||||||
if (!canView) throw new PermissionError(rid);
|
if (!canView) throw new PermissionError(rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line prefer-const
|
||||||
|
let [pdoc, self, udoc] = await Promise.all([
|
||||||
|
problem.get(rdoc.domainId, rdoc.pid),
|
||||||
|
problem.getStatus(domainId, rdoc.pid, this.user._id),
|
||||||
|
user.getById(domainId, rdoc.uid),
|
||||||
|
]);
|
||||||
|
|
||||||
let canViewCode = rdoc.uid === this.user._id;
|
let canViewCode = rdoc.uid === this.user._id;
|
||||||
canViewCode ||= this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE);
|
canViewCode ||= this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE);
|
||||||
if (!canViewCode && this.user.hasPerm(PERM.PERM_READ_RECORD_CODE_ACCEPT)) {
|
canViewCode ||= this.user.hasPerm(PERM.PERM_READ_RECORD_CODE_ACCEPT) && self?.status === STATUS.STATUS_ACCEPTED;
|
||||||
const self = await problem.getStatus(domainId, rdoc.pid, this.user._id);
|
|
||||||
canViewCode ||= self.status === STATUS.STATUS_ACCEPTED;
|
|
||||||
}
|
|
||||||
if (!canViewCode) {
|
if (!canViewCode) {
|
||||||
rdoc.code = '';
|
rdoc.code = '';
|
||||||
rdoc.compilerTexts = [];
|
rdoc.compilerTexts = [];
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line prefer-const
|
|
||||||
let [pdoc, udoc] = await Promise.all([
|
let canView = pdoc && this.user.own(pdoc);
|
||||||
problem.get(rdoc.domainId, rdoc.pid),
|
canView ||= !pdoc?.hidden && this.user.hasPerm(PERM.PERM_VIEW_PROBLEM);
|
||||||
user.getById(domainId, rdoc.uid),
|
canView ||= !!rdoc.contest || this.user._id === rdoc.uid;
|
||||||
]);
|
if (!canView) this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
if (
|
|
||||||
!pdoc
|
this.response.body = {
|
||||||
|| !this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)
|
udoc, rdoc, pdoc, tdoc,
|
||||||
|| (!rdoc.contest && pdoc.hidden && !this.user.own(pdoc) && !this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN))
|
};
|
||||||
) {
|
|
||||||
if (this.user._id !== rdoc.uid) throw new PermissionError(PERM.PERM_READ_RECORD_CODE);
|
|
||||||
else pdoc = { ...problem.default, ...pdoc ? pick(pdoc, ['domainId', 'docId', 'pid']) : {} };
|
|
||||||
}
|
|
||||||
this.response.body = { udoc, rdoc, pdoc };
|
|
||||||
if (rdoc.contest && rdoc.contest.toHexString() !== '000000000000000000000000') {
|
|
||||||
this.response.body.tdoc = await contest.get(domainId, rdoc.contest);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@param('rid', Types.ObjectID)
|
@param('rid', Types.ObjectID)
|
||||||
@@ -281,22 +278,25 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
|||||||
canView ||= this.user._id === rdoc.uid && contest.canShowSelfRecord.call(this, tdoc);
|
canView ||= this.user._id === rdoc.uid && contest.canShowSelfRecord.call(this, tdoc);
|
||||||
if (!canView) throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
|
if (!canView) throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
|
||||||
}
|
}
|
||||||
|
const [pdoc, self] = await Promise.all([
|
||||||
|
problem.get(rdoc.domainId, rdoc.pid),
|
||||||
|
problem.getStatus(domainId, rdoc.pid, this.user._id),
|
||||||
|
]);
|
||||||
|
|
||||||
let canViewCode = rdoc.uid === this.user._id;
|
let canViewCode = rdoc.uid === this.user._id;
|
||||||
canViewCode ||= this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE);
|
canViewCode ||= this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE);
|
||||||
if (!canViewCode && this.user.hasPerm(PERM.PERM_READ_RECORD_CODE_ACCEPT)) {
|
canViewCode ||= this.user.hasPerm(PERM.PERM_READ_RECORD_CODE_ACCEPT) && self?.status === STATUS.STATUS_ACCEPTED;
|
||||||
const self = await problem.getStatus(domainId, rdoc.pid, this.user._id);
|
|
||||||
canViewCode ||= self.status === STATUS.STATUS_ACCEPTED;
|
|
||||||
}
|
|
||||||
if (!canViewCode) {
|
if (!canViewCode) {
|
||||||
rdoc.code = '';
|
rdoc.code = '';
|
||||||
rdoc.compilerTexts = [];
|
rdoc.compilerTexts = [];
|
||||||
}
|
}
|
||||||
const pdoc = await problem.get(rdoc.domainId, rdoc.pid);
|
|
||||||
let canView = pdoc && this.user.own(pdoc);
|
let canView = pdoc && this.user.own(pdoc);
|
||||||
canView ||= !pdoc?.hidden && this.user.hasPerm(PERM.PERM_VIEW_PROBLEM);
|
canView ||= !pdoc?.hidden && this.user.hasPerm(PERM.PERM_VIEW_PROBLEM);
|
||||||
canView ||= this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
canView ||= this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
canView ||= !!rdoc.contest || this.user._id === rdoc.uid;
|
canView ||= !!rdoc.contest || this.user._id === rdoc.uid;
|
||||||
if (!canView) throw new PermissionError(PERM.PERM_READ_RECORD_CODE);
|
if (!canView) throw new PermissionError(PERM.PERM_READ_RECORD_CODE);
|
||||||
|
|
||||||
this.rid = rid.toString();
|
this.rid = rid.toString();
|
||||||
this.cleanup = bus.on('record/change', this.onRecordChange.bind(this));
|
this.cleanup = bus.on('record/change', this.onRecordChange.bind(this));
|
||||||
this.onRecordChange(rdoc);
|
this.onRecordChange(rdoc);
|
||||||
|
|||||||
Reference in new issue
Block a user