mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: contest: add feature whitelist for hidden contest fule
This commit is contained in:
3 files changed
+15
No files matched your search
@@ -273,6 +273,11 @@ export class ContestPrintHandler extends ContestDetailBaseHandler {
|
||||
}
|
||||
|
||||
export class ContestProblemListHandler extends ContestDetailBaseHandler {
|
||||
@param('tid', Types.ObjectId)
|
||||
async prepare(domainId: string, tid: ObjectId) {
|
||||
if (contest.RULES[this.tdoc.rule].hidden) throw new ContestNotFoundError(domainId, tid);
|
||||
}
|
||||
|
||||
@param('tid', Types.ObjectId)
|
||||
async get(domainId: string, tid: ObjectId) {
|
||||
if (contest.isNotStarted(this.tdoc)) throw new ContestNotLiveError(domainId, tid);
|
||||
@@ -663,6 +668,9 @@ export class ContestFileDownloadHandler extends ContestDetailBaseHandler {
|
||||
@param('noDisposition', Types.Boolean)
|
||||
@param('type', Types.Range(['public', 'private']), true)
|
||||
async get(domainId: string, tid: ObjectId, filename: string, noDisposition = false, type = 'private') {
|
||||
if (contest.RULES[this.tdoc.rule].hidden && !contest.RULES[this.tdoc.rule].features?.includes('download')) {
|
||||
throw new ContestNotFoundError(domainId, tid);
|
||||
}
|
||||
if (type === 'private' && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_EDIT_CONTEST)) {
|
||||
if (!this.tsdoc?.attend) throw new ContestNotAttendedError(domainId, tid);
|
||||
if (!contest.isOngoing(this.tdoc) && !contest.isDone(this.tdoc)) throw new ContestNotLiveError(domainId, tid);
|
||||
@@ -785,6 +793,9 @@ export class ContestScoreboardHandler extends ContestDetailBaseHandler {
|
||||
@param('tid', Types.ObjectId)
|
||||
@param('view', Types.String, true)
|
||||
async get(domainId: string, tid: ObjectId, viewId = 'default') {
|
||||
if (contest.RULES[this.tdoc.rule].hidden && !contest.RULES[this.tdoc.rule].features?.includes('scoreboard')) {
|
||||
throw new ContestNotFoundError(domainId, tid);
|
||||
}
|
||||
if (!this.user.own(this.tdoc)) {
|
||||
if (!contest.canShowScoreboard.call(this, this.tdoc, true)) throw new ContestScoreboardHiddenError(tid);
|
||||
if (contest.isNotStarted(this.tdoc)) throw new ContestNotLiveError(domainId, tid);
|
||||
|
||||
@@ -422,10 +422,13 @@ export interface ScoreboardConfig {
|
||||
lockAt?: Date;
|
||||
}
|
||||
|
||||
export type Feature = 'scoreboard' | 'download';
|
||||
|
||||
export interface ContestRule<T = any> {
|
||||
_originalRule?: Partial<ContestRule<T>>;
|
||||
TEXT: string;
|
||||
hidden?: boolean;
|
||||
features?: Feature[];
|
||||
check: (args: any) => any;
|
||||
statusSort: Record<string, 1 | -1>;
|
||||
submitAfterAccept: boolean;
|
||||
|
||||
@@ -636,6 +636,7 @@ const ledo = buildContestRule({
|
||||
const homework = buildContestRule({
|
||||
TEXT: 'Assignment',
|
||||
hidden: true,
|
||||
features: ['scoreboard', 'download'],
|
||||
check: () => { },
|
||||
submitAfterAccept: false,
|
||||
statusSort: { penaltyScore: -1, time: 1 },
|
||||
|
||||
Reference in new issue
Block a user