core: language limitation

This commit is contained in:
undefined committed 2021-10-27 17:33:54 +08:00
1 parent dbe52e5016
commit 4f8bdc9957
6 files changed
+23 -16

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.1.7",
"version": "3.1.8",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+11 -7
View File
@@ -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)
@@ -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);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.26.6",
"version": "4.26.7",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.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);
@@ -1,6 +1,6 @@
{% extends "layout/basic.html" %}
{% block content %}
{{ set(UiContext, 'pdocConfig', pdoc.config) }}
{{ set(UiContext, 'pdoc', pdoc) }}
<div class="row">
<div class="medium-9 columns">
<div class="section">