Skip to content

Commit 1282f80

Browse files
035966-L3undefined-moe
andauthored
core: discussion not found error msg (#1079)
Co-authored-by: undefined <i@undefined.moe>
1 parent 9898c56 commit 1282f80

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

packages/hydrooj/src/handler/discussion.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ class DiscussionHandler extends Handler {
5656
// TODO(twd2): exclude problem/contest discussions?
5757
// TODO(iceboy): continuation based pagination.
5858
this.vnode = await discussion.getVnode(domainId, typeMapper[type], name, this.user._id);
59-
if (!discussion.checkVNodeVisibility(typeMapper[type], this.vnode, this.user)) throw new DiscussionNodeNotFoundError(this.vnode.id);
59+
if (!discussion.checkVNodeVisibility(typeMapper[type], this.vnode, this.user)) {
60+
throw new DiscussionNodeNotFoundError(domainId, this.vnode.id);
61+
}
6062
if (this.ddoc) {
6163
this.ddoc.parentType ||= this.vnode.type;
6264
this.ddoc.parentId ||= this.vnode.id;
@@ -422,7 +424,7 @@ class DiscussionEditHandler extends DiscussionHandler {
422424
}
423425

424426
export async function apply(ctx) {
425-
ctx.Route('discussion_main', '/discuss', DiscussionMainHandler);
427+
ctx.Route('discussion_main', '/discuss', DiscussionMainHandler, PERM.PERM_VIEW_DISCUSSION);
426428
ctx.Route('discussion_detail', '/discuss/:did', DiscussionDetailHandler);
427429
ctx.Route('discussion_edit', '/discuss/:did/edit', DiscussionEditHandler);
428430
ctx.Route('discussion_raw', '/discuss/:did/raw', DiscussionRawHandler);

packages/hydrooj/src/model/discussion.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,16 @@ export function flushNodes(domainId: string) {
276276
export async function getVnode(domainId: string, type: number, id: string, uid?: number) {
277277
if (type === document.TYPE_PROBLEM) {
278278
const pdoc = await problem.get(domainId, Number.isSafeInteger(+id) ? +id : id, problem.PROJECTION_LIST);
279-
if (!pdoc) throw new DiscussionNodeNotFoundError(`problem/${id}`);
279+
if (!pdoc) throw new DiscussionNodeNotFoundError(domainId, `problem/${id}`);
280280
return { ...pdoc, type, id: pdoc.docId };
281281
}
282282
if ([document.TYPE_CONTEST, document.TYPE_TRAINING].includes(type as any)) {
283283
const model = type === document.TYPE_TRAINING ? training : contest;
284-
if (!ObjectId.isValid(id)) throw new DiscussionNodeNotFoundError(`contest/${id}`);
284+
const typeName = type === document.TYPE_TRAINING ? 'training' : 'contest';
285+
if (!ObjectId.isValid(id)) throw new DiscussionNodeNotFoundError(domainId, `${typeName}/${id}`);
285286
const _id = new ObjectId(id);
286287
const tdoc = await model.get(domainId, _id);
287-
if (!tdoc) throw new DiscussionNodeNotFoundError(`contest/${id}`);
288+
if (!tdoc) throw new DiscussionNodeNotFoundError(domainId, `${typeName}/${id}`);
288289
if (uid) {
289290
const tsdoc = await model.getStatus(domainId, _id, uid);
290291
tdoc.attend = tsdoc?.attend || tsdoc?.enroll;

0 commit comments

Comments
 (0)