core: add PERM_VIEW_RECORD (#753)

This commit is contained in:
panda authored and GitHub committed 2024-03-18 00:05:19 +08:00
1 parent ae7563841f
commit b7a331ec15
4 files changed
+19 -2

No files matched your search

+3
View File
@@ -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;
+6 -2
View File
@@ -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;
+9
View File
@@ -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;
+1
View File
@@ -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): (若不需要则留空)