From 9f302e7b71cf771cfd5e461ecd521a39808aa619 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 10 Apr 2024 18:21:18 +0800 Subject: [PATCH] core: fix #781 --- packages/hydrooj/src/handler/contest.ts | 26 ++++++++++--------- packages/hydrooj/src/handler/problem.ts | 2 +- .../templates/contest_problemlist.html | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/hydrooj/src/handler/contest.ts b/packages/hydrooj/src/handler/contest.ts index 7fa3efd72..cd691f87c 100644 --- a/packages/hydrooj/src/handler/contest.ts +++ b/packages/hydrooj/src/handler/contest.ts @@ -261,21 +261,23 @@ export class ContestProblemListHandler extends ContestDetailBaseHandler { } this.response.body.psdict = this.tsdoc.detail || {}; const psdocs: any[] = Object.values(this.response.body.psdict); - if (contest.canShowSelfRecord.call(this, this.tdoc)) { - [this.response.body.rdict, this.response.body.rdocs] = await Promise.all([ + const canViewRecord = contest.canShowSelfRecord.call(this, this.tdoc); + this.response.body.canViewRecord = canViewRecord; + [this.response.body.rdict, this.response.body.rdocs] = canViewRecord + ? await Promise.all([ record.getList(domainId, psdocs.map((i: any) => i.rid)), - await record.getMulti(domainId, { contest: tid, uid: this.user._id }) + record.getMulti(domainId, { contest: tid, uid: this.user._id }) .sort({ _id: -1 }).toArray(), - ]); - if (!this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_EDIT_CONTEST)) { - this.response.body.rdocs = this.response.body.rdocs.map((rdoc) => contest.applyProjection(this.tdoc, rdoc, this.user)); - for (const psdoc of psdocs) { - this.response.body.rdict[psdoc.rid] = contest.applyProjection(this.tdoc, this.response.body.rdict[psdoc.rid], this.user); - } + ]) + : [Object.fromEntries(psdocs.map((i) => [i.rid, { _id: i.rid }])), []]; + if (!this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_EDIT_CONTEST)) { + this.response.body.rdocs = this.response.body.rdocs.map((rdoc) => contest.applyProjection(this.tdoc, rdoc, this.user)); + for (const psdoc of psdocs) { + this.response.body.rdict[psdoc.rid] = contest.applyProjection(this.tdoc, this.response.body.rdict[psdoc.rid], this.user); + } + for (const key in this.response.body.psdict) { + this.response.body.psdict[key] = contest.applyProjection(this.tdoc, this.response.body.psdict[key], this.user); } - this.response.body.canViewRecord = true; - } else { - for (const i of psdocs) this.response.body.rdict[i.rid] = { _id: i.rid }; } } diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 324f0408d..d35e61ca0 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -549,7 +549,7 @@ export class ProblemSubmitHandler extends ProblemDetailHandler { } if (tid && !pretest && !contest.canShowSelfRecord.call(this, this.tdoc)) { this.response.body = { tid }; - this.response.redirect = this.url(this.tdoc.rule === 'homework' ? 'homework_detail' : 'contest_detail', { tid }); + this.response.redirect = this.url(this.tdoc.rule === 'homework' ? 'homework_detail' : 'contest_problemlist', { tid }); } else { this.response.body = { rid }; this.response.redirect = this.url('record_detail', { rid }); diff --git a/packages/ui-default/templates/contest_problemlist.html b/packages/ui-default/templates/contest_problemlist.html index b590568da..d50f07838 100644 --- a/packages/ui-default/templates/contest_problemlist.html +++ b/packages/ui-default/templates/contest_problemlist.html @@ -41,8 +41,8 @@ {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %} {% if psdict[pid] and psdict[pid].rid %} {% set rdoc = rdict[psdict[pid].rid] %} - {% set displayScore = ((tdoc.score[pid]|default(100)) * (psdict[pid].score|default(0)) / 100) if showScore else (psdict[pid].penaltyScore|default(psdict[pid].score)) %} {% if model.contest.canShowSelfRecord.call(handler, tdoc) %} + {% set displayScore = ((tdoc.score[pid]|default(100)) * (psdict[pid].score|default(0)) / 100) if showScore else (psdict[pid].penaltyScore|default(psdict[pid].score)) %} {{ record.render_status_td(rdoc, displayScore=displayScore) }} {% else %}