core: admin can remove contestant before contest start (#1196)

This commit is contained in:
Baoshuo authored and GitHub committed 2026-08-03 12:42:33 +08:00
1 parent 52f811cf98
commit f29971a30d
11 files changed
+50 -3

No files matched your search

+1
View File
@@ -35,6 +35,7 @@ export const ContestNotAttendedError = Err('ContestNotAttendedError', ForbiddenE
export const RequireProError = Err('RequireProError', ForbiddenError, 'RequireProError');
export const ContestAlreadyAttendedError = Err('ContestAlreadyAttendedError', ForbiddenError, "You've already attended this contest.");
export const ContestNotLiveError = Err('ContestNotLiveError', ForbiddenError, 'This contest is not live.');
export const ContestAlreadyStartedError = Err('ContestAlreadyStartedError', ForbiddenError, 'This contest has already started.');
export const ContestNotEndedError = Err('ContestNotEndedError', ForbiddenError, 'This contest is not ended.');
export const ContestScoreboardHiddenError = Err('ContestScoreboardHiddenError', ForbiddenError, 'Contest scoreboard is not visible.');
export const TrainingAlreadyEnrollError = Err('TrainingAlreadyEnrollError', ForbiddenError, "You've already enrolled this training.");
+12 -2
View File
@@ -10,8 +10,8 @@ import {
} from '@hydrooj/utils/lib/utils';
import { Context, Service } from '../context';
import {
BadRequestError, ContestNotAttendedError, ContestNotEndedError, ContestNotFoundError, ContestNotLiveError,
ContestScoreboardHiddenError, FileLimitExceededError, FileUploadError,
BadRequestError, ContestAlreadyStartedError, ContestNotAttendedError, ContestNotEndedError, ContestNotFoundError,
ContestNotLiveError, ContestScoreboardHiddenError, FileLimitExceededError, FileUploadError,
InvalidTokenError, MethodNotAllowedError, NotAssignedError, NotFoundError, PermissionError, ValidationError,
} from '../error';
import { ContestStatusDoc, FileInfo, ScoreboardConfig, Tdoc } from '../interface';
@@ -761,6 +761,16 @@ export class ContestUserHandler extends ContestManagementBaseHandler {
await contest.setStatus(domainId, tid, uid, null, { endAt: '' });
this.back();
}
@param('tid', Types.ObjectId)
@param('uid', Types.Int)
async postRemoveUser(domainId: string, tid: ObjectId, uid: number) {
if (!contest.isNotStarted(this.tdoc)) throw new ContestAlreadyStartedError();
const tsdoc = await contest.getStatus(domainId, tid, uid);
if (!tsdoc?.attend) throw new ContestNotAttendedError(uid);
await contest.cancelAttend(domainId, tid, uid);
this.back();
}
}
export class ContestBalloonHandler extends ContestManagementBaseHandler {
+7
View File
@@ -939,6 +939,12 @@ export async function attend(domainId: string, tid: ObjectId, uid: number, paylo
return {};
}
export async function cancelAttend(domainId: string, tid: ObjectId, uid: number) {
await document.deleteMultiStatus(domainId, document.TYPE_CONTEST, { docId: tid, uid });
await document.inc(domainId, document.TYPE_CONTEST, tid, 'attend', -1);
return {};
}
export function getMultiStatus(domainId: string, query: any) {
return document.getMultiStatus(domainId, document.TYPE_CONTEST, query);
}
@@ -1148,6 +1154,7 @@ global.Hydro.model.contest = {
getListStatus,
getMultiStatus,
attend,
cancelAttend,
edit,
del,
get,