mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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",
|
"name": "hydrooj",
|
||||||
"version": "2.29.7",
|
"version": "2.29.8",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -95,7 +95,12 @@ class RecordDetailHandler extends Handler {
|
|||||||
if (!rdoc) throw new RecordNotFoundError(rid);
|
if (!rdoc) throw new RecordNotFoundError(rid);
|
||||||
if (rdoc.contest) {
|
if (rdoc.contest) {
|
||||||
const tdoc = await contest.get(domainId, rdoc.contest.tid, rdoc.contest.type);
|
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 (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 (!this.user.hasPerm(PERM.PERM_READ_RECORD_CODE)) rdoc.code = null;
|
||||||
|
|||||||
@@ -441,6 +441,7 @@ export interface ContestRule {
|
|||||||
check: (args: any) => any;
|
check: (args: any) => any;
|
||||||
statusSort: any;
|
statusSort: any;
|
||||||
showScoreboard: (tdoc: Tdoc<30 | 60>, now: Date) => boolean;
|
showScoreboard: (tdoc: Tdoc<30 | 60>, now: Date) => boolean;
|
||||||
|
showSelfRecord: (tdoc: Tdoc<30 | 60>, now: Date) => boolean;
|
||||||
showRecord: (tdoc: Tdoc<30 | 60>, now: Date) => boolean;
|
showRecord: (tdoc: Tdoc<30 | 60>, now: Date) => boolean;
|
||||||
stat: (tdoc: Tdoc<30 | 60>, journal: any[]) => ContestStat;
|
stat: (tdoc: Tdoc<30 | 60>, journal: any[]) => ContestStat;
|
||||||
scoreboard: (
|
scoreboard: (
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const acm: ContestRule = {
|
|||||||
check: () => { },
|
check: () => { },
|
||||||
statusSort: { accept: -1, time: 1 },
|
statusSort: { accept: -1, time: 1 },
|
||||||
showScoreboard: () => true,
|
showScoreboard: () => true,
|
||||||
|
showSelfRecord: () => true,
|
||||||
showRecord: (tdoc, now) => now > tdoc.endAt,
|
showRecord: (tdoc, now) => now > tdoc.endAt,
|
||||||
stat: (tdoc, journal) => {
|
stat: (tdoc, journal) => {
|
||||||
const naccept = {};
|
const naccept = {};
|
||||||
@@ -152,6 +153,7 @@ const oi: ContestRule = {
|
|||||||
return { score, detail };
|
return { score, detail };
|
||||||
},
|
},
|
||||||
showScoreboard: (tdoc, now) => now > tdoc.endAt,
|
showScoreboard: (tdoc, now) => now > tdoc.endAt,
|
||||||
|
showSelfRecord: (tdoc, now) => now > tdoc.endAt,
|
||||||
showRecord: (tdoc, now) => now > tdoc.endAt,
|
showRecord: (tdoc, now) => now > tdoc.endAt,
|
||||||
async scoreboard(isExport, _, tdoc, pdict, cursor, page) {
|
async scoreboard(isExport, _, tdoc, pdict, cursor, page) {
|
||||||
const [rankedTsdocs, nPages] = await ranked(cursor, (a, b) => a.score === b.score, page);
|
const [rankedTsdocs, nPages] = await ranked(cursor, (a, b) => a.score === b.score, page);
|
||||||
@@ -244,7 +246,8 @@ const oi: ContestRule = {
|
|||||||
const ioi: ContestRule = {
|
const ioi: ContestRule = {
|
||||||
...oi,
|
...oi,
|
||||||
TEXT: 'IOI',
|
TEXT: 'IOI',
|
||||||
showRecord: () => true,
|
showRecord: (tdoc, now) => now > tdoc.endAt,
|
||||||
|
showSelfRecord: () => true,
|
||||||
showScoreboard: () => true,
|
showScoreboard: () => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -293,6 +296,7 @@ const homework: ContestRule = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
showScoreboard: () => true,
|
showScoreboard: () => true,
|
||||||
|
showSelfRecord: () => true,
|
||||||
showRecord: () => true,
|
showRecord: () => true,
|
||||||
async scoreboard(isExport, _, tdoc, pdict, cursor, page) {
|
async scoreboard(isExport, _, tdoc, pdict, cursor, page) {
|
||||||
const [rankedTsdocs, nPages] = await ranked(cursor, (a, b) => a.score === b.score, 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;
|
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) {
|
export function canShowScoreboard(tdoc: Tdoc<30 | 60>, allowPermOverride = true) {
|
||||||
if (RULES[tdoc.rule].showScoreboard(tdoc, new Date())) return true;
|
if (RULES[tdoc.rule].showScoreboard(tdoc, new Date())) return true;
|
||||||
if (allowPermOverride && canViewHiddenScoreboard.call(this)) return true;
|
if (allowPermOverride && canViewHiddenScoreboard.call(this)) return true;
|
||||||
@@ -650,6 +660,7 @@ global.Hydro.model.contest = {
|
|||||||
getAndListStatus,
|
getAndListStatus,
|
||||||
recalcStatus,
|
recalcStatus,
|
||||||
canShowRecord,
|
canShowRecord,
|
||||||
|
canShowSelfRecord,
|
||||||
canShowScoreboard,
|
canShowScoreboard,
|
||||||
canViewHiddenScoreboard,
|
canViewHiddenScoreboard,
|
||||||
getScoreboard,
|
getScoreboard,
|
||||||
|
|||||||
Reference in new issue
Block a user