core&ui: allow copy/import as hidden

This commit is contained in:
undefined committed 2025-07-17 17:40:58 +08:00
1 parent 4165e9b153
commit aa2e35ab42
6 files changed
+46 -25

No files matched your search

+3 -1
View File
@@ -13,7 +13,8 @@ class ProblemImportHydroHandler extends Handler {
@param('keepUser', Types.Boolean)
@param('preferredPrefix', Types.String, true)
async post(domainId: string, keepUser: boolean, preferredPrefix?: string) {
@param('hidden', Types.Boolean)
async post(domainId: string, keepUser: boolean, preferredPrefix?: string, hidden?: boolean) {
if (keepUser) this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
if (!this.request.files.file) throw new ValidationError('file');
if (preferredPrefix && !/^[a-zA-Z]+$/.test(preferredPrefix)) throw new ValidationError('preferredPrefix');
@@ -24,6 +25,7 @@ class ProblemImportHydroHandler extends Handler {
progress: this.progress.bind(this),
operator: keepUser ? null : this.user._id,
delSource: true,
hidden,
},
).catch((e) => MessageModel.send(1, this.user._id, `Import failed: ${e.message}\n${e.stack}`));
let resolved = false;
+3 -2
View File
@@ -190,7 +190,8 @@ export class ProblemMainHandler extends Handler {
@param('pids', Types.NumericArray)
@param('target', Types.String)
async postCopy(domainId: string, pids: number[], target: string) {
@param('hidden', Types.Boolean)
async postCopy(domainId: string, pids: number[], target: string, hidden?: boolean) {
const t = `,${this.domain.share || ''},`;
if (t !== ',*,' && !t.includes(`,${target},`)) throw new PermissionError(target);
const ddoc = await domain.get(target);
@@ -205,7 +206,7 @@ export class ProblemMainHandler extends Handler {
const ids = [];
for (const pid of pids) {
// eslint-disable-next-line no-await-in-loop
ids.push(await problem.copy(domainId, pid, target));
ids.push(await problem.copy(domainId, pid, target, undefined, hidden));
}
this.response.body = ids;
}
+5 -3
View File
@@ -66,6 +66,7 @@ interface ProblemImportOptions {
override?: boolean;
operator?: number;
delSource?: boolean;
hidden?: boolean;
}
interface ProblemCreateOptions {
@@ -244,7 +245,7 @@ export class ProblemModel {
return result;
}
static async copy(domainId: string, _id: number, target: string, pid?: string) {
static async copy(domainId: string, _id: number, target: string, pid?: string, hidden?: boolean) {
const original = await ProblemModel.get(domainId, _id);
if (!original) throw new ProblemNotFoundError(domainId, _id);
if (original.reference) throw new ValidationError('reference');
@@ -252,7 +253,7 @@ export class ProblemModel {
if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid;
return await ProblemModel.add(
target, pid, original.title, original.content,
original.owner, original.tag, { hidden: original.hidden, reference: { domainId, pid: _id } },
original.owner, original.tag, { hidden: hidden || original.hidden, reference: { domainId, pid: _id } },
);
}
@@ -560,10 +561,11 @@ export class ProblemModel {
content: overrideContent || pdoc.content?.toString() || 'No content',
tag,
difficulty: pdoc.difficulty,
...(options.hidden ? { hidden: true } : {}),
})).docId
: await ProblemModel.add(
domainId, pid, title.trim(), overrideContent || pdoc.content?.toString() || 'No content',
operator || pdoc.owner, tag, { hidden: pdoc.hidden, difficulty: pdoc.difficulty },
operator || pdoc.owner, tag, { hidden: options.hidden || pdoc.hidden, difficulty: pdoc.difficulty },
);
// TODO delete unused file when updating pdoc
for (const [f, loc] of await getFiles('testdata', 'attachments', 'generators', 'include')) {