diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 16408f24c..ca6bf2a0a 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -208,6 +208,11 @@ export class ProblemMainHandler extends Handler { if (!ddoc) throw new NotFoundError(target); const dudoc = await user.getById(target, this.user._id); if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM); + // Check if user can access all those problems + await problem.getList( + domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, + true, ['docId'], true, + ); const ids = []; for (const pid of pids) { // eslint-disable-next-line no-await-in-loop diff --git a/packages/hydrooj/src/model/problem.ts b/packages/hydrooj/src/model/problem.ts index 2401995ab..2445e426b 100644 --- a/packages/hydrooj/src/model/problem.ts +++ b/packages/hydrooj/src/model/problem.ts @@ -396,13 +396,6 @@ export class ProblemModel { return indexByDocIdOnly ? r : Object.assign(r, l); } - static async getPrefixList(domainId: string, prefix: string) { - const $regex = new RegExp(`^${escapeRegExp(prefix.toLowerCase())}`, 'i'); - const filter = { $or: [{ pid: { $regex } }, { title: { $regex } }] }; - return await document.getMulti(domainId, document.TYPE_PROBLEM, filter, ['domainId', 'docId', 'pid', 'title']) - .limit(20).toArray(); - } - static async getListStatus(domainId: string, uid: number, pids: number[]) { const psdocs = await ProblemModel.getMultiStatus( domainId, { uid, docId: { $in: Array.from(new Set(pids)) } },