| 275 | @param('allDomain', Types.Boolean) |
| 276 | @param('noTemplate', Types.Boolean, true) |
| 277 | async prepare( |
| 278 | domainId: string, tid?: ObjectId, pid?: string | number, uidOrName?: string, |
| 279 | status?: number, pretest = false, all = false, allDomain = false, noTemplate = false, |
| 280 | ) { |
| 281 | if (tid) { |
| 282 | this.tdoc = await contest.get(domainId, tid); |
| 283 | if (!this.tdoc) throw new ContestNotFoundError(domainId, tid); |
| 284 | if (pretest || contest.canShowScoreboard.call(this, this.tdoc, true)) this.tid = tid.toHexString(); |
| 285 | else throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD); |
| 286 | if (!this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_EDIT_CONTEST)) { |
| 287 | this.applyProjection = true; |
| 288 | } |
| 289 | } |
| 290 | if (pretest) { |
| 291 | this.pretest = true; |
| 292 | this.uid = this.user._id; |
| 293 | } else if (uidOrName) { |
| 294 | let udoc = await user.getById(domainId, +uidOrName); |
| 295 | if (udoc) this.uid = udoc._id; |
| 296 | else { |
| 297 | udoc = await user.getByUname(domainId, uidOrName); |
| 298 | if (udoc) this.uid = udoc._id; |
| 299 | else throw new UserNotFoundError(uidOrName); |
| 300 | } |
| 301 | } |
| 302 | if (this.uid !== this.user._id) this.checkPerm(PERM.PERM_VIEW_RECORD); |
| 303 | if (pid) { |
| 304 | const pdoc = await problem.get(domainId, pid); |
| 305 | if (pdoc) this.pid = pdoc.docId; |
| 306 | else throw new ProblemNotFoundError(domainId, pid); |
| 307 | } |
| 308 | if (status) this.status = status; |
| 309 | if (all) { |
| 310 | this.checkPerm(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD); |
| 311 | this.checkPerm(PERM.PERM_VIEW_HOMEWORK_HIDDEN_SCOREBOARD); |
| 312 | this.all = true; |
| 313 | } |
| 314 | if (allDomain) { |
| 315 | this.checkPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN); |
| 316 | this.allDomain = true; |
| 317 | } |
| 318 | this.noTemplate = noTemplate; |
| 319 | this.throttleQueueClear = throttle(this.queueClear, 100, { trailing: true }); |
| 320 | } |
| 321 | |
| 322 | async message(msg: { rids: string[] }) { |
| 323 | if (!(msg.rids instanceof Array)) return; |