From ba0beee9a8dabb0b02953cba47025d6297016ebe Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 29 Jul 2022 16:14:47 +0800 Subject: [PATCH] core&ui: allow admin view contest when its not started --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/handler/contest.ts | 6 +++++- packages/hydrooj/src/handler/homework.ts | 10 ++++++---- packages/ui-default/package.json | 2 +- packages/ui-default/templates/contest_detail.html | 12 ++++++++---- packages/ui-default/templates/homework_detail.html | 12 ++++++++---- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 806612bea..d0e5eddff 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "3.14.20", + "version": "3.14.21", "bin": "bin/hydrooj.js", "main": "src/loader", "module": "src/loader", diff --git a/packages/hydrooj/src/handler/contest.ts b/packages/hydrooj/src/handler/contest.ts index 8c4486610..ee8a6de58 100644 --- a/packages/hydrooj/src/handler/contest.ts +++ b/packages/hydrooj/src/handler/contest.ts @@ -121,12 +121,16 @@ export class ContestDetailHandler extends ContestDetailBaseHandler { this.response.body = { tdoc: this.tdoc, tsdoc: this.tsdoc, udict, }; - if (contest.isNotStarted(this.tdoc)) return; if (!this.request.json) { this.response.body.tdoc.content = this.response.body.tdoc.content .replace(/\(file:\/\//g, `(./${this.tdoc.docId}/file/`) .replace(/="file:\/\//g, `="./${this.tdoc.docId}/file/`); } + if ( + (contest.isNotStarted(this.tdoc) || !this.tsdoc?.attend) + && !this.user.own(this.tdoc) + && !this.user.hasPerm(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD) + ) return; const pdict = await problem.getList(domainId, this.tdoc.pids, true, undefined, undefined, problem.PROJECTION_CONTEST_LIST); const psdict = {}; let rdict = {}; diff --git a/packages/hydrooj/src/handler/homework.ts b/packages/hydrooj/src/handler/homework.ts index 3e5f12a93..5b2f139fd 100644 --- a/packages/hydrooj/src/handler/homework.ts +++ b/packages/hydrooj/src/handler/homework.ts @@ -73,7 +73,11 @@ class HomeworkDetailHandler extends Handler { this.response.body = { tdoc, tsdoc, udict, ddocs, page, dpcount, dcount, }; - if (contest.isNotStarted(tdoc)) return; + if ( + (contest.isNotStarted(tdoc) || !tsdoc?.attend) + && !this.user.own(tdoc) + && !this.user.hasPerm(PERM.PERM_VIEW_HOMEWORK_HIDDEN_SCOREBOARD) + ) return; const pdict = await problem.getList(domainId, tdoc.pids, true, undefined, undefined, problem.PROJECTION_CONTEST_LIST); const psdict = {}; let rdict = {}; @@ -93,9 +97,7 @@ class HomeworkDetailHandler extends Handler { ); } } - this.response.body.pdict = pdict; - this.response.body.psdict = psdict; - this.response.body.rdict = rdict; + Object.assign(this.response.body, { pdict, psdict, rdict }); } @param('tid', Types.ObjectID) diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index bb5a3fda6..d02cc3926 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.38.24", + "version": "4.38.25", "author": "undefined ", "license": "AGPL-3.0", "main": "hydro.js", diff --git a/packages/ui-default/templates/contest_detail.html b/packages/ui-default/templates/contest_detail.html index 9710c496e..a51dfa586 100644 --- a/packages/ui-default/templates/contest_detail.html +++ b/packages/ui-default/templates/contest_detail.html @@ -37,12 +37,11 @@ {% endif %} - {% if model.contest.isOngoing(tdoc, tsdoc) or model.contest.isDone(tdoc, tsdoc) %}

{{ _('Problem') }}

- {% if tsdoc.attend or model.contest.isDone(tdoc) %} + {% if pdict %}
@@ -79,18 +78,23 @@ {% endif %} {% endif %} {%- endfor -%}
- {{ problem.render_problem_title(pdict[pid], tdoc=tdoc, show_invisible_flag=false, show_tags=false) }} + {% if model.contest.isNotStarted(tdoc) %} + {{ problem.render_problem_title(pdict[pid], show_invisible_flag=false, show_tags=false) }} + {% else %} + {{ problem.render_problem_title(pdict[pid], tdoc=tdoc, show_invisible_flag=false, show_tags=false) }} + {% endif %}
+ {% elif tsdoc.attend %} + {{ nothing.render('This contest is not live.') }} {% else %} {{ nothing.render('Please attend contest to see the problems.') }} {% endif %}
- {% endif %}
{% set owner_udoc = udict[tdoc.owner] %} diff --git a/packages/ui-default/templates/homework_detail.html b/packages/ui-default/templates/homework_detail.html index 281b82ee1..d37ed8fc0 100644 --- a/packages/ui-default/templates/homework_detail.html +++ b/packages/ui-default/templates/homework_detail.html @@ -16,9 +16,7 @@

{{ _('Problem') }}

- {% if model.contest.isNotStarted(tdoc) %} - {{ nothing.render('This homework is not open and you cannot view problems.') }} - {% elif tsdoc.attend or model.contest.isDone(tdoc) %} + {% if pdict %}
@@ -55,13 +53,19 @@ {% endif %} {% endif %} {%- endfor -%}
- {{ problem.render_problem_title(pdict[pid], tdoc=tdoc, show_invisible_flag=false, show_tags=false) }} + {% if model.contest.isNotStarted(tdoc) %} + {{ problem.render_problem_title(pdict[pid], show_invisible_flag=false, show_tags=false) }} + {% else %} + {{ problem.render_problem_title(pdict[pid], tdoc=tdoc, show_invisible_flag=false, show_tags=false) }} + {% endif %}
+ {% elif tsdoc.attend %} + {{ nothing.render('This homework is not open and you cannot view problems.') }} {% else %} {{ nothing.render('Please claim the assignment to see the problems.') }} {% endif %}