|
|
@ -74,12 +74,13 @@ ScheduleModel.Worker.addHandler('contest', async (doc) => {
|
|
|
|
export class ContestListHandler extends Handler {
|
|
|
|
export class ContestListHandler extends Handler {
|
|
|
|
@param('rule', Types.Range(contest.RULES), true)
|
|
|
|
@param('rule', Types.Range(contest.RULES), true)
|
|
|
|
@param('page', Types.PositiveInt, true)
|
|
|
|
@param('page', Types.PositiveInt, true)
|
|
|
|
@param('all', Types.Boolean)
|
|
|
|
async get(domainId: string, rule = '', page = 1) {
|
|
|
|
async get(domainId: string, rule = '', page = 1, all = false) {
|
|
|
|
|
|
|
|
if (rule && contest.RULES[rule].hidden) throw new BadRequestError();
|
|
|
|
if (rule && contest.RULES[rule].hidden) throw new BadRequestError();
|
|
|
|
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
|
|
|
|
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
|
|
|
|
if (all && !this.user.hasPerm(PERM.PERM_MOD_BADGE)) all = false;
|
|
|
|
const q = {
|
|
|
|
const q = { ...all ? { assign: { $in: [...this.user.group, null] } } : {}, ...rule ? { rule } : { rule: { $in: rules } } };
|
|
|
|
...this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST) ? {} : { $or: [{ assign: { $in: this.user.group } }, { assign: { $size: 0 } }] },
|
|
|
|
|
|
|
|
...rule ? { rule } : { rule: { $in: rules } },
|
|
|
|
|
|
|
|
};
|
|
|
|
const cursor = contest.getMulti(domainId, q);
|
|
|
|
const cursor = contest.getMulti(domainId, q);
|
|
|
|
const qs = rule ? `rule=${rule}` : '';
|
|
|
|
const qs = rule ? `rule=${rule}` : '';
|
|
|
|
const [tdocs, tpcount] = await paginate<Tdoc>(cursor, page, system.get('pagination.contest'));
|
|
|
|
const [tdocs, tpcount] = await paginate<Tdoc>(cursor, page, system.get('pagination.contest'));
|
|
|
@ -104,7 +105,7 @@ export class ContestDetailBaseHandler extends Handler {
|
|
|
|
contest.get(domainId, tid),
|
|
|
|
contest.get(domainId, tid),
|
|
|
|
contest.getStatus(domainId, tid, this.user._id),
|
|
|
|
contest.getStatus(domainId, tid, this.user._id),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
if (this.tdoc.assign?.length && !this.user.own(this.tdoc)) {
|
|
|
|
if (this.tdoc.assign?.length && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST)) {
|
|
|
|
const groups = await user.listGroup(domainId, this.user._id);
|
|
|
|
const groups = await user.listGroup(domainId, this.user._id);
|
|
|
|
if (!Set.intersection(this.tdoc.assign, groups.map((i) => i.name)).size) {
|
|
|
|
if (!Set.intersection(this.tdoc.assign, groups.map((i) => i.name)).size) {
|
|
|
|
throw new NotAssignedError('contest', tid);
|
|
|
|
throw new NotAssignedError('contest', tid);
|
|
|
@ -163,7 +164,7 @@ export class ContestDetailHandler extends Handler {
|
|
|
|
contest.getStatus(domainId, tid, this.user._id),
|
|
|
|
contest.getStatus(domainId, tid, this.user._id),
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
if (contest.RULES[this.tdoc.rule].hidden) throw new ContestNotFoundError(domainId, tid);
|
|
|
|
if (contest.RULES[this.tdoc.rule].hidden) throw new ContestNotFoundError(domainId, tid);
|
|
|
|
if (this.tdoc.assign?.length && !this.user.own(this.tdoc)) {
|
|
|
|
if (this.tdoc.assign?.length && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST)) {
|
|
|
|
const groups = await user.listGroup(domainId, this.user._id);
|
|
|
|
const groups = await user.listGroup(domainId, this.user._id);
|
|
|
|
if (!Set.intersection(this.tdoc.assign, groups.map((i) => i.name)).size) {
|
|
|
|
if (!Set.intersection(this.tdoc.assign, groups.map((i) => i.name)).size) {
|
|
|
|
throw new NotAssignedError('contest', tid);
|
|
|
|
throw new NotAssignedError('contest', tid);
|
|
|
@ -413,7 +414,7 @@ export class ContestEditHandler extends Handler {
|
|
|
|
async postUpdate(
|
|
|
|
async postUpdate(
|
|
|
|
domainId: string, tid: ObjectId, beginAtDate: string, beginAtTime: string, duration: number,
|
|
|
|
domainId: string, tid: ObjectId, beginAtDate: string, beginAtTime: string, duration: number,
|
|
|
|
title: string, content: string, rule: string, _pids: string, rated = false,
|
|
|
|
title: string, content: string, rule: string, _pids: string, rated = false,
|
|
|
|
_code = '', autoHide = false, assign: string[] = null, lock: number = null,
|
|
|
|
_code = '', autoHide = false, assign: string[] = [], lock: number = null,
|
|
|
|
contestDuration: number = null, maintainer: number[] = [], allowViewCode = false,
|
|
|
|
contestDuration: number = null, maintainer: number[] = [], allowViewCode = false,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if (autoHide) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
|
|
|
if (autoHide) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
|
|
|