diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 62bb99f3f..b42b85932 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -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", diff --git a/packages/hydrooj/src/handler/import.ts b/packages/hydrooj/src/handler/import.ts index f321d224a..82216fed5 100644 --- a/packages/hydrooj/src/handler/import.ts +++ b/packages/hydrooj/src/handler/import.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) { diff --git a/packages/ui-default/templates/problem_import.html b/packages/ui-default/templates/problem_import.html index 700de5597..59d6ee5a1 100644 --- a/packages/ui-default/templates/problem_import.html +++ b/packages/ui-default/templates/problem_import.html @@ -6,8 +6,9 @@