diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index b562b39b5..7f5dd74ca 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "3.1.7", + "version": "3.1.8", "bin": "bin/hydrooj.js", "main": "src/loader", "module": "src/loader", diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 6961bcd97..586bb8d96 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -11,6 +11,7 @@ import { SolutionNotFoundError, ValidationError, } from '../error'; import { + ProblemConfig, ProblemDoc, ProblemStatusDoc, Tdoc, User, } from '../interface'; import difficultyAlgorithm from '../lib/difficulty'; @@ -246,10 +247,19 @@ export class ProblemDetailHandler extends ProblemHandler { } else if (this.pdoc.hidden && !this.user.own(this.pdoc)) { this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN); } + let ddoc = this.domain; if (this.pdoc.reference) { + ddoc = await domain.get(this.pdoc.reference.domainId); const pdoc = await problem.get(this.pdoc.reference.domainId, this.pdoc.reference.pid); + if (!ddoc || !pdoc) throw new ProblemNotFoundError(this.pdoc.reference.domainId, this.pdoc.reference.pid); this.pdoc.config = pdoc.config; } + if (ddoc.langs) { + (this.pdoc.config as ProblemConfig).langs = intersection( + this.response.body.pdoc.config.langs || ddoc.langs.split(','), + ddoc.langs.split(','), + ); + } await bus.serial('problem/get', this.pdoc, this); [this.psdoc, this.udoc] = await Promise.all([ problem.getStatus(domainId, this.pdoc.docId, this.user._id), @@ -327,6 +337,7 @@ export class ProblemDetailHandler extends ProblemHandler { export class ProblemSubmitHandler extends ProblemDetailHandler { async get(domainId: string, tid?: ObjectID) { + if (tid && !contest.isOngoing(this.tdoc)) throw new ContestNotLiveError(this.tdoc.docId); this.response.template = 'problem_submit.html'; this.response.body = { pdoc: this.pdoc, @@ -338,13 +349,6 @@ export class ProblemSubmitHandler extends ProblemDetailHandler { : 'contest_detail_problem_submit' : 'problem_submit', }; - if (tid && !contest.isOngoing(this.tdoc)) throw new ContestNotLiveError(this.tdoc.docId); - if (this.domain.langs) { - this.response.body.pdoc.config.langs = intersection( - this.response.body.pdoc.config.langs || this.domain.langs.split(','), - this.domain.langs.split(','), - ); - } } @param('lang', Types.Name) diff --git a/packages/ui-default/components/scratchpad/ScratchpadToolbarContainer.jsx b/packages/ui-default/components/scratchpad/ScratchpadToolbarContainer.jsx index 3a6e857fe..19a81e94c 100644 --- a/packages/ui-default/components/scratchpad/ScratchpadToolbarContainer.jsx +++ b/packages/ui-default/components/scratchpad/ScratchpadToolbarContainer.jsx @@ -81,11 +81,11 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool render() { const LANGS = {}; const prefix = new Set(Object.keys(window.LANGS).filter((i) => i.includes('.')).map((i) => i.split('.')[0])); + const domainId = UiContext.pdoc.reference?.domainId || UiContext.pdoc.domainId; for (const key in window.LANGS) { if (prefix.has(key)) continue; if (UiContext.pdoc.config.langs && !UiContext.pdoc.config.langs.includes(key)) continue; - if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(UiContext.domainId)) continue; - if (UiContext.domain.langs && !`,${UiContext.domain.langs},`.includes(`,${key},`)) continue; + if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(domainId)) continue; LANGS[key] = window.LANGS[key]; } const keys = Object.keys(LANGS); diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index e0b53773b..2ec5e3fd0 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.26.6", + "version": "4.26.7", "author": "undefined ", "license": "AGPL-3.0", "main": "hydro.js", diff --git a/packages/ui-default/pages/problem_submit.page.js b/packages/ui-default/pages/problem_submit.page.js index f02f68684..b69a22950 100644 --- a/packages/ui-default/pages/problem_submit.page.js +++ b/packages/ui-default/pages/problem_submit.page.js @@ -8,11 +8,14 @@ function setOptions($el, options) { } const page = new NamedPage(['problem_submit', 'contest_detail_problem_submit', 'homework_detail_problem_submit'], async () => { + const { config } = UiContext.pdoc; + const domainId = UiContext.pdoc.reference?.domainId || UiContext.pdoc.domainId; + function onChangeMain(update = true) { const options = {}; for (const key in window.LANGS) { - if (UiContext.pdocConfig.langs && !UiContext.pdocConfig.langs.includes(key)) continue; - if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(UiContext.domainId)) continue; + if (config.langs && !config.langs.includes(key)) continue; + if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(domainId)) continue; if (key.startsWith(`${this.value}.`) && key !== this.value) options[key] = window.LANGS[key].display; } setOptions($('#codelang-sub-select'), options); @@ -27,8 +30,8 @@ const page = new NamedPage(['problem_submit', 'contest_detail_problem_submit', ' } const main = {}; for (const key in window.LANGS) { - if (UiContext.pdocConfig.langs && !UiContext.pdocConfig.langs.filter((i) => i === key || i.startsWith(`${key}.`)).length) continue; - if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(UiContext.domainId)) continue; + if (config.langs && !config.langs.filter((i) => i === key || i.startsWith(`${key}.`)).length) continue; + if (window.LANGS[key].domain && !window.LANGS[key].domain.includes(domainId)) continue; if (!key.includes('.')) main[key] = window.LANGS[key].display; } setOptions($('#codelang-main-select'), main); diff --git a/packages/ui-default/templates/problem_submit.html b/packages/ui-default/templates/problem_submit.html index bded3a04b..3447c9d0b 100644 --- a/packages/ui-default/templates/problem_submit.html +++ b/packages/ui-default/templates/problem_submit.html @@ -1,6 +1,6 @@ {% extends "layout/basic.html" %} {% block content %} -{{ set(UiContext, 'pdocConfig', pdoc.config) }} +{{ set(UiContext, 'pdoc', pdoc) }}