diff --git a/packages/hydrooj/src/handler/contest.ts b/packages/hydrooj/src/handler/contest.ts index 3d7826ad1..4b2e4037d 100644 --- a/packages/hydrooj/src/handler/contest.ts +++ b/packages/hydrooj/src/handler/contest.ts @@ -169,7 +169,7 @@ export class ContestDetailHandler extends ContestDetailBaseHandler { && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD) ) return; - const pdict = await problem.getList(domainId, this.tdoc.pids, true, undefined, undefined, problem.PROJECTION_CONTEST_LIST); + const pdict = await problem.getList(domainId, this.tdoc.pids, true, true, problem.PROJECTION_CONTEST_LIST); let psdict = {}; let rdict = {}; if (this.tsdoc) { @@ -252,7 +252,7 @@ export class ContestScoreboardHandler extends ContestDetailBaseHandler { const tdoc = await contest.get(domainId, tid); if (!contest.canShowScoreboard.call(this, tdoc)) throw new ContestScoreboardHiddenError(tid); const [pdict, teams] = await Promise.all([ - problem.getList(domainId, tdoc.pids, true, undefined, false, undefined, true), + problem.getList(domainId, tdoc.pids, true, false, undefined, true), contest.getMultiStatus(domainId, { docId: tid }).toArray(), ]); const udict = await user.getList(domainId, teams.map((i) => i.uid)); @@ -373,7 +373,7 @@ export class ContestEditHandler extends Handler { if (beginAtMoment.isSameOrAfter(endAt)) throw new ValidationError('duration'); const beginAt = beginAtMoment.toDate(); const lockAt = lock ? moment(endAt).add(-lock, 'minutes').toDate() : null; - await problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, this.user.group, true); + await problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, true); if (tid) { await contest.edit(domainId, tid, { title, content, rule, beginAt, endAt, pids, rated, duration: contestDuration, diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 9d92e9ec2..29581f3dc 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -64,7 +64,6 @@ registerValue('Problem', [ ['difficulty', 'Int'], ['tag', '[String]'], ['hidden', 'Boolean'], - ['assign', '[String]'], ]); registerResolver( @@ -74,11 +73,6 @@ registerResolver( const pdoc = await problem.get(ctx.args.domainId, arg.pid || arg.id); if (!pdoc) return null; if (pdoc.hidden) ctx.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN); - if (pdoc.assign.length && !ctx.user.own(pdoc)) { - if (!Set.intersection(new Set(pdoc.assign), new Set(ctx.user.group)).size) { - throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN); - } - } ctx.pdoc = pdoc; return pdoc; }, @@ -86,7 +80,7 @@ registerResolver( registerResolver('Query', 'problems(ids: [Int])', '[Problem]', async (arg, ctx) => { ctx.checkPerm(PERM.PERM_VIEW); const res = await problem.getList(ctx.args.domainId, arg.ids, ctx.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || ctx.user._id, - ctx.user.group, undefined, undefined, true); + undefined, undefined, true); return Object.keys(res).map((id) => res[+id]); }, 'Get a list of problem by ids'); registerResolver( @@ -105,7 +99,7 @@ registerResolver( }, ); registerResolver( - 'ProblemManage', 'edit(title: String, content: String, tag: [String], hidden: Boolean, assign: [String])', 'Problem!', + 'ProblemManage', 'edit(title: String, content: String, tag: [String], hidden: Boolean)', 'Problem!', (arg, ctx) => problem.edit(ctx.args.domainId, ctx.pdoc.docId, arg), ); @@ -640,14 +634,13 @@ export class ProblemEditHandler extends ProblemManageHandler { @post('hidden', Types.Boolean) @post('tag', Types.Content, true, null, parseCategory) @post('difficulty', Types.PositiveInt, (i) => +i <= 10, true) - @post('assign', Types.CommaSeperatedArray, true) async post( domainId: string, pid: string | number, title: string, content: string, - newPid: string = '', hidden = false, tag: string[] = [], difficulty = 0, assign: string[] = [], + newPid: string = '', hidden = false, tag: string[] = [], difficulty = 0, ) { if (newPid !== this.pdoc.pid && await problem.get(domainId, newPid)) throw new BadRequestError('new pid exists'); const $update: Partial = { - title, content, pid: newPid, hidden, assign, tag: tag ?? [], difficulty, html: false, + title, content, pid: newPid, hidden, tag: tag ?? [], difficulty, html: false, }; const pdoc = await problem.edit(domainId, this.pdoc.docId, $update); this.response.redirect = this.url('problem_detail', { pid: newPid || pdoc.docId }); @@ -972,13 +965,12 @@ export class ProblemCreateHandler extends Handler { @post('hidden', Types.Boolean) @post('difficulty', Types.PositiveInt, (i) => +i <= 10, true) @post('tag', Types.Content, true, null, parseCategory) - @post('assign', Types.CommaSeperatedArray, true) async post( domainId: string, title: string, content: string, pid: string, - hidden = false, difficulty = 0, tag: string[] = [], assign: string[] = [], + hidden = false, difficulty = 0, tag: string[] = [], ) { if (pid && await problem.get(domainId, pid)) throw new BadRequestError('ProblemID already exists'); - const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], hidden, assign); + const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], hidden); const files = new Set(Array.from(content.matchAll(/file:\/\/([a-zA-Z0-9_-]+\.[a-zA-Z0-9]+)/g)).map((i) => i[1])); const tasks = []; for (const file of files) { diff --git a/packages/hydrooj/src/handler/record.ts b/packages/hydrooj/src/handler/record.ts index f81dafc37..36087dc74 100644 --- a/packages/hydrooj/src/handler/record.ts +++ b/packages/hydrooj/src/handler/record.ts @@ -89,7 +89,7 @@ class RecordListHandler extends ContestDetailBaseHandler { : await Promise.all([ user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)), canViewProblem - ? problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid), canViewHiddenProblem, this.user.group, false) + ? problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid), canViewHiddenProblem, false) : Object.fromEntries([rdocs.map((rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }])]), ]); this.response.body = { diff --git a/packages/hydrooj/src/handler/training.ts b/packages/hydrooj/src/handler/training.ts index 35e246d6c..ea840a2a8 100644 --- a/packages/hydrooj/src/handler/training.ts +++ b/packages/hydrooj/src/handler/training.ts @@ -98,7 +98,7 @@ class TrainingDetailHandler extends Handler { const canViewHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id; const [owner, pdict] = await Promise.all([ user.getById(domainId, tdoc.owner), - problem.getList(domainId, pids, canViewHidden, this.user.group, true), + problem.getList(domainId, pids, canViewHidden, true), ]); const psdict = await problem.getListStatus(domainId, this.user._id, pids); const donePids = new Set(); diff --git a/packages/hydrooj/src/handler/user.ts b/packages/hydrooj/src/handler/user.ts index ff70d606c..4ca094e6f 100644 --- a/packages/hydrooj/src/handler/user.ts +++ b/packages/hydrooj/src/handler/user.ts @@ -344,7 +344,7 @@ class UserDetailHandler extends Handler { pdocs.push(...Object.values( await problem.getList( did, psdocs.map((i) => i.docId), canViewHidden, - this.user.group, false, problem.PROJECTION_LIST, true, + false, problem.PROJECTION_LIST, true, ), )); })); @@ -366,7 +366,7 @@ class UserDetailHandler extends Handler { if (this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) { this.response.body.pdict = await problem.getList( domainId, psdocs.map((i) => i.parentId), canViewHidden, - this.user.group, false, problem.PROJECTION_LIST, + false, problem.PROJECTION_LIST, ); } } diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index 5e5c548a3..1ea58d51a 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -229,7 +229,6 @@ declare module './model/problem' { data: FileInfo[]; additional_file: FileInfo[]; hidden?: boolean; - assign: string[]; html?: boolean; stats?: any; difficulty?: number; diff --git a/packages/hydrooj/src/model/contest.ts b/packages/hydrooj/src/model/contest.ts index b44f0ec6b..a14abc0b9 100644 --- a/packages/hydrooj/src/model/contest.ts +++ b/packages/hydrooj/src/model/contest.ts @@ -726,7 +726,7 @@ export async function getScoreboard( const tdoc = await get(domainId, tid); if (!canShowScoreboard.call(this, tdoc)) throw new ContestScoreboardHiddenError(tid); const tsdocsCursor = getMultiStatus(domainId, { docId: tid }).sort(RULES[tdoc.rule].statusSort); - const pdict = await problem.getList(domainId, tdoc.pids, true, problem.PROJECTION_CONTEST_DETAIL); + const pdict = await problem.getList(domainId, tdoc.pids, true, true, problem.PROJECTION_CONTEST_DETAIL); const [rows, udict] = await RULES[tdoc.rule].scoreboard( isExport, this.translate.bind(this), tdoc, pdict, tsdocsCursor, diff --git a/packages/hydrooj/src/model/problem.ts b/packages/hydrooj/src/model/problem.ts index 79d71d9da..61a5c6bde 100644 --- a/packages/hydrooj/src/model/problem.ts +++ b/packages/hydrooj/src/model/problem.ts @@ -28,7 +28,7 @@ function sortable(source: string) { export class ProblemModel { static PROJECTION_CONTEST_LIST: Field[] = [ '_id', 'domainId', 'docType', 'docId', 'pid', - 'owner', 'title', 'assign', + 'owner', 'title', ]; static PROJECTION_LIST: Field[] = [ @@ -66,7 +66,6 @@ export class ProblemModel { additional_file: [], stats: {}, hidden: true, - assign: [], config: '', difficulty: 0, }; @@ -88,31 +87,30 @@ export class ProblemModel { additional_file: [], stats: {}, hidden: true, - assign: [], config: '', difficulty: 0, }; static async add( domainId: string, pid: string = '', title: string, content: string, owner: number, - tag: string[] = [], hidden = false, assign: string[] = [], + tag: string[] = [], hidden = false, ) { const [doc] = await ProblemModel.getMulti(domainId, {}) .sort({ docId: -1 }).limit(1).project({ docId: 1 }) .toArray(); const result = await ProblemModel.addWithId( domainId, (doc?.docId || 0) + 1, pid, - title, content, owner, tag, hidden, assign, + title, content, owner, tag, hidden, ); return result; } static async addWithId( domainId: string, docId: number, pid: string = '', title: string, - content: string, owner: number, tag: string[] = [], hidden = false, assign: string[] = [], + content: string, owner: number, tag: string[] = [], hidden = false, ) { const args: Partial = { - title, tag, hidden, assign, nSubmit: 0, nAccept: 0, sort: sortable(pid || `P${docId}`), + title, tag, hidden, nSubmit: 0, nAccept: 0, sort: sortable(pid || `P${docId}`), }; if (pid) args.pid = pid; await bus.parallel('problem/before-add', domainId, content, owner, docId, args); @@ -298,8 +296,7 @@ export class ProblemModel { static async getList( domainId: string, pids: number[], canViewHidden: number | boolean = false, - group: string[] = [], doThrow = true, projection = ProblemModel.PROJECTION_PUBLIC, - indexByDocIdOnly = false, + doThrow = true, projection = ProblemModel.PROJECTION_PUBLIC, indexByDocIdOnly = false, ): Promise { if (!pids?.length) return []; const r: Record = {}; @@ -307,9 +304,6 @@ export class ProblemModel { const q: any = { docId: { $in: pids } }; let pdocs = await document.getMulti(domainId, document.TYPE_PROBLEM, q) .project(buildProjection(projection)).toArray(); - if (group.length > 0 && canViewHidden !== true) { - pdocs = pdocs.filter((i) => !i.assign?.length || Set.intersection(group, i.assign).size); - } if (canViewHidden !== true) { pdocs = pdocs.filter((i) => i.owner === canViewHidden || i.maintainer?.includes(canViewHidden as any) || !i.hidden); } @@ -383,8 +377,7 @@ export class ProblemModel { if (udoc.own(pdoc)) return true; if (udoc.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) return true; if (pdoc.hidden) return false; - if (!pdoc.assign.length) return true; - return !!Set.intersection(pdoc.assign, udoc.group).size; + return true; } } diff --git a/packages/hydrooj/src/upgrade.ts b/packages/hydrooj/src/upgrade.ts index a987d555e..606da6874 100644 --- a/packages/hydrooj/src/upgrade.ts +++ b/packages/hydrooj/src/upgrade.ts @@ -385,14 +385,7 @@ const scripts: UpgradeScript[] = [ await db.collection('oplog').deleteMany({ type: 'user.login' }); return true; }, - async function _57_58() { - const _FRESH_INSTALL_IGNORE = 1; - await db.collection('document').updateMany( - { docType: document.TYPE_PROBLEM, assign: null }, - { $set: { assign: [] } }, - ); - return true; - }, + null, async function _58_59() { const _FRESH_INSTALL_IGNORE = 1; const tasks = await db.collection('task').find({ type: 'schedule', subType: 'contest.problemHide' }).toArray(); diff --git a/packages/ui-default/templates/problem_edit.html b/packages/ui-default/templates/problem_edit.html index 511f55b09..a1846e4bc 100644 --- a/packages/ui-default/templates/problem_edit.html +++ b/packages/ui-default/templates/problem_edit.html @@ -6,12 +6,6 @@
-
- -
+
+ +