core: allow view self record in homework

This commit is contained in:
undefined committed 2023-04-03 13:00:30 +08:00
1 parent 1b89677456
commit 4d7190b9b4
3 files changed
+86 -21

No files matched your search

+8 -8
View File
@@ -46,12 +46,19 @@ class RecordListHandler extends ContestDetailBaseHandler {
this.response.template = 'record_main.html';
const q: Filter<RecordDoc> = { contest: tid };
if (full) uidOrName = this.user._id.toString();
if (uidOrName) {
const udoc = await user.getById(domainId, +uidOrName)
|| await user.getByUname(domainId, uidOrName)
|| await user.getByEmail(domainId, uidOrName);
if (udoc) q.uid = udoc._id;
else invalid = true;
}
if (tid) {
tdoc = await contest.get(domainId, tid);
this.tdoc = tdoc;
if (!tdoc) throw new ContestNotFoundError(domainId, pid);
if (!contest.canShowScoreboard.call(this, tdoc, true)) throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
if (!contest.canShowRecord.call(this, tdoc, true)) {
if (!contest[q.uid === this.user._id ? 'canShowSelfRecord' : 'canShowRecord'].call(this, tdoc, true)) {
throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
}
if (!(await contest.getStatus(domainId, tid, this.user._id))?.attend) {
@@ -61,13 +68,6 @@ class RecordListHandler extends ContestDetailBaseHandler {
notification.push({ name, args: { type: 'note' }, checker: () => true });
}
}
if (uidOrName) {
const udoc = await user.getById(domainId, +uidOrName)
|| await user.getByUname(domainId, uidOrName)
|| await user.getByEmail(domainId, uidOrName);
if (udoc) q.uid = udoc._id;
else invalid = true;
}
if (pid) {
if (typeof pid === 'string' && tdoc && /^[A-Z]$/.test(pid)) {
pid = tdoc.pids[parseInt(pid, 36) - 10];