core: discussion not found error msg (#1079)

Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
035966-L3andundefined authored and GitHub committed 2025-11-09 20:02:19 +00:00
1 parent 9898c56de1
commit 1282f80c1a
2 files changed
+8 -5

No files matched your search

+4 -2
View File
@@ -56,7 +56,9 @@ class DiscussionHandler extends Handler {
// TODO(twd2): exclude problem/contest discussions?
// TODO(iceboy): continuation based pagination.
this.vnode = await discussion.getVnode(domainId, typeMapper[type], name, this.user._id);
if (!discussion.checkVNodeVisibility(typeMapper[type], this.vnode, this.user)) throw new DiscussionNodeNotFoundError(this.vnode.id);
if (!discussion.checkVNodeVisibility(typeMapper[type], this.vnode, this.user)) {
throw new DiscussionNodeNotFoundError(domainId, this.vnode.id);
}
if (this.ddoc) {
this.ddoc.parentType ||= this.vnode.type;
this.ddoc.parentId ||= this.vnode.id;
@@ -422,7 +424,7 @@ class DiscussionEditHandler extends DiscussionHandler {
}
export async function apply(ctx) {
ctx.Route('discussion_main', '/discuss', DiscussionMainHandler);
ctx.Route('discussion_main', '/discuss', DiscussionMainHandler, PERM.PERM_VIEW_DISCUSSION);
ctx.Route('discussion_detail', '/discuss/:did', DiscussionDetailHandler);
ctx.Route('discussion_edit', '/discuss/:did/edit', DiscussionEditHandler);
ctx.Route('discussion_raw', '/discuss/:did/raw', DiscussionRawHandler);
+4 -3
View File
@@ -276,15 +276,16 @@ export function flushNodes(domainId: string) {
export async function getVnode(domainId: string, type: number, id: string, uid?: number) {
if (type === document.TYPE_PROBLEM) {
const pdoc = await problem.get(domainId, Number.isSafeInteger(+id) ? +id : id, problem.PROJECTION_LIST);
if (!pdoc) throw new DiscussionNodeNotFoundError(`problem/${id}`);
if (!pdoc) throw new DiscussionNodeNotFoundError(domainId, `problem/${id}`);
return { ...pdoc, type, id: pdoc.docId };
}
if ([document.TYPE_CONTEST, document.TYPE_TRAINING].includes(type as any)) {
const model = type === document.TYPE_TRAINING ? training : contest;
if (!ObjectId.isValid(id)) throw new DiscussionNodeNotFoundError(`contest/${id}`);
const typeName = type === document.TYPE_TRAINING ? 'training' : 'contest';
if (!ObjectId.isValid(id)) throw new DiscussionNodeNotFoundError(domainId, `${typeName}/${id}`);
const _id = new ObjectId(id);
const tdoc = await model.get(domainId, _id);
if (!tdoc) throw new DiscussionNodeNotFoundError(`contest/${id}`);
if (!tdoc) throw new DiscussionNodeNotFoundError(domainId, `${typeName}/${id}`);
if (uid) {
const tsdoc = await model.getStatus(domainId, _id, uid);
tdoc.attend = tsdoc?.attend || tsdoc?.enroll;