mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: add showSelfRecord for contest
This commit is contained in:
1 parent
33208a0d1f
commit
3761a5c77d
4 files changed
+20
-3
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.29.7",
|
||||
"version": "2.29.8",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -95,7 +95,12 @@ class RecordDetailHandler extends Handler {
|
||||
if (!rdoc) throw new RecordNotFoundError(rid);
|
||||
if (rdoc.contest) {
|
||||
const tdoc = await contest.get(domainId, rdoc.contest.tid, rdoc.contest.type);
|
||||
if (!contest.canShowRecord.call(this, tdoc, true)) throw new PermissionError(rid);
|
||||
if (
|
||||
(rdoc.uid !== this.user._id && !contest.canShowRecord.call(this, tdoc, true))
|
||||
|| (rdoc.uid === this.user._id && !contest.canShowSelfRecord.call(this, tdoc, true))
|
||||
) {
|
||||
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;
|
||||
|
||||
@@ -441,6 +441,7 @@ export interface ContestRule {
|
||||
check: (args: any) => any;
|
||||
statusSort: any;
|
||||
showScoreboard: (tdoc: Tdoc<30 | 60>, now: Date) => boolean;
|
||||
showSelfRecord: (tdoc: Tdoc<30 | 60>, now: Date) => boolean;
|
||||
showRecord: (tdoc: Tdoc<30 | 60>, now: Date) => boolean;
|
||||
stat: (tdoc: Tdoc<30 | 60>, journal: any[]) => ContestStat;
|
||||
scoreboard: (
|
||||
|
||||
@@ -23,6 +23,7 @@ const acm: ContestRule = {
|
||||
check: () => { },
|
||||
statusSort: { accept: -1, time: 1 },
|
||||
showScoreboard: () => true,
|
||||
showSelfRecord: () => true,
|
||||
showRecord: (tdoc, now) => now > tdoc.endAt,
|
||||
stat: (tdoc, journal) => {
|
||||
const naccept = {};
|
||||
@@ -152,6 +153,7 @@ const oi: ContestRule = {
|
||||
return { score, detail };
|
||||
},
|
||||
showScoreboard: (tdoc, now) => now > tdoc.endAt,
|
||||
showSelfRecord: (tdoc, now) => now > tdoc.endAt,
|
||||
showRecord: (tdoc, now) => now > tdoc.endAt,
|
||||
async scoreboard(isExport, _, tdoc, pdict, cursor, page) {
|
||||
const [rankedTsdocs, nPages] = await ranked(cursor, (a, b) => a.score === b.score, page);
|
||||
@@ -244,7 +246,8 @@ const oi: ContestRule = {
|
||||
const ioi: ContestRule = {
|
||||
...oi,
|
||||
TEXT: 'IOI',
|
||||
showRecord: () => true,
|
||||
showRecord: (tdoc, now) => now > tdoc.endAt,
|
||||
showSelfRecord: () => true,
|
||||
showScoreboard: () => true,
|
||||
};
|
||||
|
||||
@@ -293,6 +296,7 @@ const homework: ContestRule = {
|
||||
};
|
||||
},
|
||||
showScoreboard: () => true,
|
||||
showSelfRecord: () => true,
|
||||
showRecord: () => true,
|
||||
async scoreboard(isExport, _, tdoc, pdict, cursor, page) {
|
||||
const [rankedTsdocs, nPages] = await ranked(cursor, (a, b) => a.score === b.score, page);
|
||||
@@ -595,6 +599,12 @@ export function canShowRecord(tdoc: Tdoc<30 | 60>, allowPermOverride = true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function canShowSelfRecord(tdoc: Tdoc<30 | 60>, allowPermOverride = true) {
|
||||
if (RULES[tdoc.rule].showSelfRecord(tdoc, new Date())) return true;
|
||||
if (allowPermOverride && canViewHiddenScoreboard.call(this)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function canShowScoreboard(tdoc: Tdoc<30 | 60>, allowPermOverride = true) {
|
||||
if (RULES[tdoc.rule].showScoreboard(tdoc, new Date())) return true;
|
||||
if (allowPermOverride && canViewHiddenScoreboard.call(this)) return true;
|
||||
@@ -650,6 +660,7 @@ global.Hydro.model.contest = {
|
||||
getAndListStatus,
|
||||
recalcStatus,
|
||||
canShowRecord,
|
||||
canShowSelfRecord,
|
||||
canShowScoreboard,
|
||||
canViewHiddenScoreboard,
|
||||
getScoreboard,
|
||||
|
||||
Reference in new issue
Block a user