mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: record: hide compilerText when canViewCode is false
This commit is contained in:
1 file changed
+13
-9
@@ -383,6 +383,7 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
|||||||
throttleSend: any;
|
throttleSend: any;
|
||||||
applyProjection = false;
|
applyProjection = false;
|
||||||
noTemplate = false;
|
noTemplate = false;
|
||||||
|
canViewCode = false;
|
||||||
|
|
||||||
@param('rid', Types.ObjectId)
|
@param('rid', Types.ObjectId)
|
||||||
@param('noTemplate', Types.Boolean, true)
|
@param('noTemplate', Types.Boolean, true)
|
||||||
@@ -404,14 +405,10 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
|||||||
problem.getStatus(domainId, rdoc.pid, this.user._id),
|
problem.getStatus(domainId, rdoc.pid, this.user._id),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let canViewCode = rdoc.uid === this.user._id;
|
this.canViewCode = rdoc.uid === this.user._id;
|
||||||
canViewCode ||= this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE);
|
this.canViewCode ||= this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE);
|
||||||
canViewCode ||= this.user.hasPerm(PERM.PERM_READ_RECORD_CODE);
|
this.canViewCode ||= this.user.hasPerm(PERM.PERM_READ_RECORD_CODE);
|
||||||
canViewCode ||= this.user.hasPerm(PERM.PERM_READ_RECORD_CODE_ACCEPT) && self?.status === STATUS.STATUS_ACCEPTED;
|
this.canViewCode ||= this.user.hasPerm(PERM.PERM_READ_RECORD_CODE_ACCEPT) && self?.status === STATUS.STATUS_ACCEPTED;
|
||||||
if (!canViewCode) {
|
|
||||||
rdoc.code = '';
|
|
||||||
rdoc.compilerTexts = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rdoc.contest || this.user._id !== rdoc.uid) {
|
if (!rdoc.contest || this.user._id !== rdoc.uid) {
|
||||||
if (!problem.canViewBy(pdoc, this.user)) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
if (!problem.canViewBy(pdoc, this.user)) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
@@ -444,9 +441,16 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
|||||||
clearTimeout(this.disconnectTimeout);
|
clearTimeout(this.disconnectTimeout);
|
||||||
this.disconnectTimeout = null;
|
this.disconnectTimeout = null;
|
||||||
}
|
}
|
||||||
if (this.applyProjection && rdoc.input === undefined) rdoc = contest.applyProjection(this.tdoc, rdoc, this.user);
|
if (this.applyProjection) rdoc = contest.applyProjection(this.tdoc, rdoc, this.user);
|
||||||
// TODO: frontend doesn't support incremental update
|
// TODO: frontend doesn't support incremental update
|
||||||
// if ($set) this.send({ $set, $push });
|
// if ($set) this.send({ $set, $push });
|
||||||
|
if (!this.canViewCode) {
|
||||||
|
rdoc = {
|
||||||
|
...rdoc,
|
||||||
|
code: '',
|
||||||
|
compilerTexts: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
if (![STATUS.STATUS_WAITING, STATUS.STATUS_JUDGING, STATUS.STATUS_COMPILING, STATUS.STATUS_FETCHED].includes(rdoc.status)) {
|
if (![STATUS.STATUS_WAITING, STATUS.STATUS_JUDGING, STATUS.STATUS_COMPILING, STATUS.STATUS_FETCHED].includes(rdoc.status)) {
|
||||||
this.disconnectTimeout = setTimeout(() => this.close(4001, 'Ended'), 30000);
|
this.disconnectTimeout = setTimeout(() => this.close(4001, 'Ended'), 30000);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user