core: 允许导入题目时保留上传者

This commit is contained in:
undefined committed 2021-06-13 10:34:14 +08:00
1 parent c49a24017f
commit f7225fdc26
3 files changed
+10 -5

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.28.31", "version": "2.28.32",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+7 -3
View File
@@ -13,7 +13,7 @@ import { Logger } from '../logger';
import type { ContentNode } from '../interface'; import type { ContentNode } from '../interface';
import problem, { ProblemDoc } from '../model/problem'; import problem, { ProblemDoc } from '../model/problem';
import TaskModel from '../model/task'; import TaskModel from '../model/task';
import { PERM } from '../model/builtin'; import { PERM, PRIV } from '../model/builtin';
import { import {
Route, Handler, Types, post, Route, Handler, Types, post,
} from '../service/server'; } from '../service/server';
@@ -279,7 +279,8 @@ class ProblemImportHydroHandler extends Handler {
this.response.template = 'problem_import.html'; this.response.template = 'problem_import.html';
} }
async post({ domainId }) { async post({ domainId, keepUser }) {
if (keepUser) this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
if (!this.request.files.file) throw new ValidationError('file'); if (!this.request.files.file) throw new ValidationError('file');
const tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.import`); const tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.import`);
const zip = new AdmZip(this.request.files.file.path); const zip = new AdmZip(this.request.files.file.path);
@@ -298,7 +299,10 @@ class ProblemImportHydroHandler extends Handler {
const pdoc: ProblemDoc = yaml.load(content) as any; const pdoc: ProblemDoc = yaml.load(content) as any;
const current = await problem.get(domainId, pdoc.pid); const current = await problem.get(domainId, pdoc.pid);
const pid = current ? undefined : pdoc.pid; const pid = current ? undefined : pdoc.pid;
const docId = await problem.add(domainId, pid, pdoc.title, pdoc.content, pdoc.owner, pdoc.tag, pdoc.hidden); const docId = await problem.add(
domainId, pid, pdoc.title, pdoc.content,
keepUser ? pdoc.owner : this.user._id, pdoc.tag, pdoc.hidden,
);
if (files.includes('testdata')) { if (files.includes('testdata')) {
const datas = await fs.readdir(path.join(tmpdir, i, 'testdata'), { withFileTypes: true }); const datas = await fs.readdir(path.join(tmpdir, i, 'testdata'), { withFileTypes: true });
for (const f of datas) { for (const f of datas) {
@@ -6,8 +6,9 @@
<div class="section__body"> <div class="section__body">
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}"> <input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
<p>{{ _('Upload zipfile') }} ({{ _('Type') }}: {{type}}): <p>{{ _('Upload zipfile') }} {% if type %}({{ _('Type') }}: {{type}}){% endif %}:
<input type="file" name="file"> <input type="file" name="file">
{% if handler.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM) not type %}<input type="checkbox" name="keepUser">{% endif %}
<input type="submit" value="{{ _('Upload') }}" class="rounded primary button"> <input type="submit" value="{{ _('Upload') }}" class="rounded primary button">
</p> </p>
</form> </form>