mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: limit ViewRecord
This commit is contained in:
1 parent
63894f9959
commit
77fc46c069
17 files changed
+37
-30
No files matched your search
@@ -386,11 +386,11 @@ export class ContestDetailProblemSubmitHandler extends ContestProblemHandler {
|
||||
export class ContestCodeHandler extends Handler {
|
||||
@param('tid', Types.ObjectID)
|
||||
async get(domainId: string, tid: ObjectID) {
|
||||
if (!this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE)) {
|
||||
this.checkPerm(PERM.PERM_READ_RECORD_CODE);
|
||||
}
|
||||
await this.limitRate('homework_code', 3600, 60);
|
||||
await this.limitRate('contest_code', 3600, 60);
|
||||
const [tdoc, tsdocs] = await contest.getAndListStatus(domainId, tid);
|
||||
if (!this.user.own(tdoc) && !this.user.hasPriv(PRIV.PRIV_READ_RECORD)) {
|
||||
this.checkPerm(PERM.PERM_READ_RECORD);
|
||||
}
|
||||
if (!contest.canShowRecord.call(this, tdoc as any, true)) {
|
||||
throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
|
||||
}
|
||||
|
||||
@@ -389,11 +389,13 @@ class HomeworkScoreboardDownloadHandler extends Handler {
|
||||
class HomeworkCodeHandler extends Handler {
|
||||
@param('tid', Types.ObjectID)
|
||||
async get(domainId: string, tid: ObjectID) {
|
||||
if (!this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE)) this.checkPerm(PERM.PERM_READ_RECORD_CODE);
|
||||
await this.limitRate('homework_code', 3600, 60);
|
||||
await this.limitRate('contest_code', 3600, 60);
|
||||
const [tdoc, tsdocs] = await contest.getAndListStatus(
|
||||
domainId, tid, document.TYPE_HOMEWORK,
|
||||
);
|
||||
if (!this.user.own(tdoc) && !this.user.hasPriv(PRIV.PRIV_READ_RECORD)) {
|
||||
this.checkPerm(PERM.PERM_READ_RECORD);
|
||||
}
|
||||
const rnames = {};
|
||||
for (const tsdoc of tsdocs) {
|
||||
for (const pid in tsdoc.detail || {}) {
|
||||
|
||||
@@ -104,8 +104,8 @@ class RecordDetailHandler extends Handler {
|
||||
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 = null;
|
||||
if (rdoc.uid !== this.user._id && !this.user.hasPriv(PRIV.PRIV_READ_RECORD)) {
|
||||
this.checkPerm(PERM.PERM_READ_RECORD);
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [pdoc, udoc] = await Promise.all([
|
||||
@@ -188,7 +188,10 @@ class RecordMainConnectionHandler extends ConnectionHandler {
|
||||
if (pretest || contest.canShowScoreboard.call(this, tdoc, true)) this.tid = tid.toHexString();
|
||||
else throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
|
||||
}
|
||||
if (uidOrName) {
|
||||
if (pretest) {
|
||||
this.pretest = true;
|
||||
this.uid = this.user._id;
|
||||
} else if (uidOrName) {
|
||||
let udoc = await user.getById(domainId, +uidOrName);
|
||||
if (udoc) this.uid = udoc._id;
|
||||
else {
|
||||
@@ -207,7 +210,6 @@ class RecordMainConnectionHandler extends ConnectionHandler {
|
||||
} else throw new ProblemNotFoundError(domainId, pid);
|
||||
}
|
||||
if (status) this.status = status;
|
||||
if (pretest) this.pretest = true;
|
||||
this.dispose = bus.on('record/change', this.onRecordChange.bind(this));
|
||||
}
|
||||
|
||||
@@ -261,6 +263,9 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
||||
const tdoc = await contest.get(domainId, rdoc.contest.tid, -1);
|
||||
if (!contest.canShowRecord.call(this, tdoc)) throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
|
||||
}
|
||||
if (rdoc.uid !== this.user._id && !this.user.hasPriv(PRIV.PRIV_READ_RECORD)) {
|
||||
this.checkPerm(PERM.PERM_READ_RECORD);
|
||||
}
|
||||
this.rid = rid.toString();
|
||||
this.dispose = bus.on('record/change', this.onRecordChange.bind(this));
|
||||
this.onRecordChange(rdoc);
|
||||
|
||||
@@ -34,16 +34,18 @@ const buildChecker = (...permPrivChecker: Array<number | bigint | Function>) =>
|
||||
};
|
||||
|
||||
export const Nav = (
|
||||
name: string, args: Dictionary<any> = {}, prefix: string,
|
||||
name: string, args: ((handler: any) => Record<string, any>) | Record<string, any> = {}, prefix: string,
|
||||
...permPrivChecker: Array<number | bigint | Function>
|
||||
) => {
|
||||
if (typeof args !== 'function') args = () => (args || {});
|
||||
const checker = buildChecker(...permPrivChecker);
|
||||
if (name.startsWith('@@')) {
|
||||
global.Hydro.ui.nodes.nav.splice(+name.split('@@')[1], 0, {
|
||||
name: name.split('@@')[2], args: args || {}, prefix, checker: buildChecker(...permPrivChecker),
|
||||
name: name.split('@@')[2], args, prefix, checker,
|
||||
});
|
||||
} else {
|
||||
global.Hydro.ui.nodes.nav.push({
|
||||
name, args: args || {}, prefix, checker: buildChecker(...permPrivChecker),
|
||||
name, args, prefix, checker,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -70,7 +72,7 @@ Nav('training_main', {}, 'training', PERM.PERM_VIEW_TRAINING);
|
||||
Nav('homework_main', {}, 'homework', PERM.PERM_VIEW_HOMEWORK);
|
||||
Nav('discussion_main', {}, 'discussion', PERM.PERM_VIEW_DISCUSSION);
|
||||
Nav('contest_main', {}, 'contest', PERM.PERM_VIEW_CONTEST);
|
||||
Nav('record_main', {}, 'record');
|
||||
Nav('record_main', (handler) => (handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) ? { query: { uidOrName: handler.user._id } } : {}), 'record');
|
||||
Nav('ranking', {}, 'ranking', PERM.PERM_VIEW_RANKING);
|
||||
Nav('domain_dashboard', {}, 'domain', PERM.PERM_EDIT_DOMAIN);
|
||||
Nav('manage_dashboard', {}, 'manage', PRIV.PRIV_EDIT_SYSTEM);
|
||||
|
||||
@@ -30,7 +30,7 @@ export const PERM = {
|
||||
PERM_VIEW_PROBLEM_HIDDEN: 1n << 8n,
|
||||
PERM_SUBMIT_PROBLEM: 1n << 9n,
|
||||
PERM_READ_PROBLEM_DATA: 1n << 10n,
|
||||
PERM_READ_RECORD_CODE: 1n << 12n,
|
||||
PERM_READ_RECORD: 1n << 12n,
|
||||
PERM_REJUDGE_PROBLEM: 1n << 13n,
|
||||
PERM_REJUDGE: 1n << 14n,
|
||||
|
||||
@@ -113,7 +113,7 @@ export const PERMS = [
|
||||
Permission('perm_problem', PERM.PERM_VIEW_PROBLEM_HIDDEN, 'View hidden problems'),
|
||||
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, 'Read all records'),
|
||||
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'),
|
||||
@@ -232,7 +232,7 @@ export const PRIV = {
|
||||
PRIV_USER_PROFILE: 1 << 2,
|
||||
PRIV_REGISTER_USER: 1 << 3,
|
||||
PRIV_READ_PROBLEM_DATA: 1 << 4,
|
||||
PRIV_READ_RECORD_CODE: 1 << 7,
|
||||
PRIV_READ_RECORD: 1 << 7,
|
||||
PRIV_VIEW_HIDDEN_RECORD: 1 << 8,
|
||||
PRIV_JUDGE: 1 << 9, // (renamed)
|
||||
PRIV_CREATE_DOMAIN: 1 << 10,
|
||||
|
||||
Reference in new issue
Block a user