diff --git a/packages/hydrooj/src/handler/record.ts b/packages/hydrooj/src/handler/record.ts index 3f8ceaebc..5f96af17c 100644 --- a/packages/hydrooj/src/handler/record.ts +++ b/packages/hydrooj/src/handler/record.ts @@ -54,6 +54,7 @@ class RecordListHandler extends ContestDetailBaseHandler { if (udoc) q.uid = udoc._id; else invalid = true; } + if (q.uid !== this.user._id) this.checkPerm(PERM.PERM_VIEW_RECORD); if (tid) { tdoc = await contest.get(domainId, tid); this.tdoc = tdoc; @@ -136,6 +137,7 @@ class RecordDetailHandler extends ContestDetailBaseHandler { async prepare(domainId: string, rid: ObjectId) { this.rdoc = await record.get(domainId, rid); if (!this.rdoc) throw new RecordNotFoundError(rid); + if (this.rdoc.uid !== this.user._id) this.checkPerm(PERM.PERM_VIEW_RECORD); } async download() { @@ -288,6 +290,7 @@ class RecordMainConnectionHandler extends ConnectionHandler { else throw new UserNotFoundError(uidOrName); } } + if (this.uid !== this.user._id) this.checkPerm(PERM.PERM_VIEW_RECORD); if (pid) { const pdoc = await problem.get(domainId, pid); if (pdoc) this.pid = pdoc.docId; diff --git a/packages/hydrooj/src/model/builtin.ts b/packages/hydrooj/src/model/builtin.ts index 052f803ca..e93112dff 100644 --- a/packages/hydrooj/src/model/builtin.ts +++ b/packages/hydrooj/src/model/builtin.ts @@ -25,6 +25,7 @@ export const PERM = { PERM_READ_PROBLEM_DATA: 1n << 10n, // Record + PERM_VIEW_RECORD: 1n << 70n, PERM_READ_RECORD_CODE: 1n << 12n, PERM_READ_RECORD_CODE_ACCEPT: 1n << 66n, PERM_REJUDGE_PROBLEM: 1n << 13n, @@ -114,6 +115,7 @@ export const PERMS = [ Permission('perm_problem', PERM.PERM_VIEW_PROBLEM_HIDDEN, 'View hidden problems'), Permission('perm_problem', PERM.PERM_SUBMIT_PROBLEM, 'Submit problem'), Permission('perm_problem', PERM.PERM_READ_PROBLEM_DATA, 'Read data of problem'), + Permission('perm_record', PERM.PERM_VIEW_RECORD, "View other's records"), Permission('perm_record', PERM.PERM_READ_RECORD_CODE, 'Read all record codes'), Permission('perm_record', PERM.PERM_READ_RECORD_CODE_ACCEPT, 'Read record codes after accept'), Permission('perm_record', PERM.PERM_REJUDGE_PROBLEM, 'Rejudge problems'), @@ -185,7 +187,8 @@ PERM.PERM_BASIC = PERM.PERM_VIEW | PERM.PERM_VIEW_HOMEWORK | PERM.PERM_VIEW_HOMEWORK_SCOREBOARD | PERM.PERM_VIEW_TRAINING - | PERM.PERM_VIEW_RANKING; + | PERM.PERM_VIEW_RANKING + | PERM.PERM_VIEW_RECORD; PERM.PERM_DEFAULT = PERM.PERM_VIEW | PERM.PERM_VIEW_DISPLAYNAME @@ -229,7 +232,8 @@ PERM.PERM_DEFAULT = PERM.PERM_VIEW | PERM.PERM_ATTEND_CONTEST | PERM.PERM_CREATE_TRAINING | PERM.PERM_ATTEND_HOMEWORK - | PERM.PERM_VIEW_RANKING; + | PERM.PERM_VIEW_RANKING + | PERM.PERM_VIEW_RECORD; PERM.PERM_ADMIN = PERM.PERM_ALL; diff --git a/packages/hydrooj/src/upgrade.ts b/packages/hydrooj/src/upgrade.ts index 5626397e5..3ca5cc01d 100644 --- a/packages/hydrooj/src/upgrade.ts +++ b/packages/hydrooj/src/upgrade.ts @@ -630,6 +630,15 @@ const scripts: UpgradeScript[] = [ } }); }, + async function _85_86() { + return await iterateAllDomain(async (ddoc) => { + for (const role of Object.keys(ddoc.roles)) { + if (role === 'root') return; + ddoc.roles[role] = (BigInt(ddoc.roles[role]) | PERM.PERM_VIEW_RECORD).toString(); + } + await domain.setRoles(ddoc._id, ddoc.roles); + }); + }, ]; export default scripts; diff --git a/packages/ui-default/locales/zh.yaml b/packages/ui-default/locales/zh.yaml index 3e21a4554..bebf21bc6 100644 --- a/packages/ui-default/locales/zh.yaml +++ b/packages/ui-default/locales/zh.yaml @@ -46,6 +46,7 @@ __langname: 简体中文 'Yes': 是 "Effects only when Difficulty is not 'Use algorithm calculated'.": 仅当难度不为“使用算法计算”时才起效。 "Split by ', '.": 由“, ”或“,”分隔。 +"View other's records": 查看他人的记录 "What's file?": 什么是文件? (All Problems): (所有题目) (leave blank if none): (若不需要则留空)