mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: 允许导入题目时保留上传者
This commit is contained in:
1 parent
c49a24017f
commit
f7225fdc26
3 files changed
+10
-5
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.28.31",
|
||||
"version": "2.28.32",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -13,7 +13,7 @@ import { Logger } from '../logger';
|
||||
import type { ContentNode } from '../interface';
|
||||
import problem, { ProblemDoc } from '../model/problem';
|
||||
import TaskModel from '../model/task';
|
||||
import { PERM } from '../model/builtin';
|
||||
import { PERM, PRIV } from '../model/builtin';
|
||||
import {
|
||||
Route, Handler, Types, post,
|
||||
} from '../service/server';
|
||||
@@ -279,7 +279,8 @@ class ProblemImportHydroHandler extends Handler {
|
||||
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');
|
||||
const tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.import`);
|
||||
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 current = await problem.get(domainId, 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')) {
|
||||
const datas = await fs.readdir(path.join(tmpdir, i, 'testdata'), { withFileTypes: true });
|
||||
for (const f of datas) {
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
<div class="section__body">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<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">
|
||||
{% 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">
|
||||
</p>
|
||||
</form>
|
||||
|
||||
Reference in new issue
Block a user