Skip to content

Commit 1db447d

Browse files
committed
fix: add getWithChildren hidden
1 parent 014eeaa commit 1db447d

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

packages/codemate-plugin/plugins/assign-problem-list/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class SystemProblemListMainHandler extends Handler {
4141
children: tdoc.children
4242
.map((id) => {
4343
const _tdoc = tdocs.find((doc) => doc.docId.equals(id));
44-
if (enableHidden || !_tdoc?.hidden) {
44+
if (_tdoc && (enableHidden || !_tdoc.hidden)) {
4545
return extractChildren(_tdoc);
4646
}
4747
return false;
@@ -67,12 +67,13 @@ export class ProblemListDetailHandler extends Handler {
6767
@param('page', Types.PositiveInt, true)
6868
@param('pageSize', Types.PositiveInt, true)
6969
async prepare(domainId: string, tid: ObjectId, page = 1, pageSize = 15) {
70-
const tdoc = await plist.getWithChildren(domainId, tid);
70+
const enableHidden = this.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM);
71+
const tdoc = await plist.getWithChildren(domainId, tid, null, enableHidden);
7172

7273
// 检查权限(bypass超管)
7374
if (!this.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM) && tdoc.visibility === 'private' && !this.user.own(tdoc)) {
7475
throw new NotAllowedToVisitPrivateListError(tid);
75-
} else if (tdoc.hidden && !this.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM)) {
76+
} else if (tdoc.hidden && !enableHidden) {
7677
throw new ProblemListHiddenError(tid);
7778
}
7879

packages/codemate-plugin/plugins/assign-problem-list/model.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ export function getMulti(domainId: string, query: Filter<ProblemList> = {}, proj
2929
return document.getMulti(domainId, TYPE_PROBLEM_LIST, query, projection);
3030
}
3131

32-
export async function getWithChildren(domainId: string, tid: ObjectId, projection?: Projection<ProblemList>): Promise<ProblemList> {
32+
export async function getWithChildren(
33+
domainId: string,
34+
tid: ObjectId,
35+
projection?: Projection<ProblemList>,
36+
enableHidden?: boolean,
37+
): Promise<ProblemList> {
3338
const root = await get(domainId, tid, projection);
34-
if (root.children?.length) {
35-
const subPids = await Promise.all(root.children.map(async (c) => (await getWithChildren(domainId, c)).pids));
39+
if (root.children?.length && (enableHidden || !root.hidden)) {
40+
const subPids = await Promise.all(root.children.map(async (c) => (await getWithChildren(domainId, c, projection, enableHidden)).pids));
3641
root.pids.push(...Array.from(new Set(subPids.flat())));
3742
}
3843
return root;

0 commit comments

Comments
 (0)