@@ -16,6 +16,7 @@ import {
1616} from 'hydrooj' ;
1717import {
1818 NotAllowedToVisitPrivateListError ,
19+ ProblemListHiddenError ,
1920 ProblemListNotFountError ,
2021 ProblemNoNextError ,
2122 ProblemNoPreviousError ,
@@ -28,21 +29,28 @@ export class SystemProblemListMainHandler extends Handler {
2829 async get ( ) {
2930 const tdocs = await plist . getMulti ( this . domain . _id , { visibility : 'system' } , [ 'docId' , 'title' , 'content' , 'parent' , 'children' ] ) . toArray ( ) ;
3031
32+ const enableHidden = this . user . hasPriv ( PRIV . PRIV_EDIT_SYSTEM ) ;
33+
3134 const extractChildren = ( tdoc : plist . ProblemList ) => {
3235 if ( ! tdoc ) throw new Error ( ) ;
3336 if ( tdoc . children ?. length ) {
3437 return {
3538 ...tdoc ,
36- children : tdoc . children . map ( ( id ) => {
37- const _tdoc = tdocs . find ( ( doc ) => doc . docId . equals ( id ) ) ;
38- return extractChildren ( _tdoc ) ;
39- } ) ,
39+ children : tdoc . children
40+ . map ( ( id ) => {
41+ const _tdoc = tdocs . find ( ( doc ) => doc . docId . equals ( id ) ) ;
42+ if ( enableHidden || ! _tdoc ?. hidden ) {
43+ return extractChildren ( _tdoc ) ;
44+ }
45+ return false ;
46+ } )
47+ . filter ( ( v ) => v ) ,
4048 } ;
4149 }
4250 return { ...tdoc , children : [ ] } ;
4351 } ;
4452
45- const roots = tdocs . filter ( ( item ) => ! item . parent ) . map ( extractChildren ) ;
53+ const roots = tdocs . filter ( ( item ) => ! item . parent && ( enableHidden || ! item . hidden ) ) . map ( extractChildren ) ;
4654 this . response . body = { roots } ;
4755 this . response . template = 'system_plist_main.html' ;
4856 }
@@ -62,6 +70,8 @@ export class ProblemListDetailHandler extends Handler {
6270 // 检查权限(bypass超管)
6371 if ( ! this . user . hasPriv ( PRIV . PRIV_EDIT_SYSTEM ) && tdoc . visibility === 'private' && ! this . user . own ( tdoc ) ) {
6472 throw new NotAllowedToVisitPrivateListError ( tid ) ;
73+ } else if ( tdoc . hidden && ! this . user . hasPriv ( PRIV . PRIV_EDIT_SYSTEM ) ) {
74+ throw new ProblemListHiddenError ( tid ) ;
6575 }
6676
6777 this . allPids = tdoc . pids ;
@@ -145,6 +155,7 @@ export class SystemProblemListEditHandler extends Handler {
145155 @param ( 'content' , Types . Content )
146156 @param ( 'pids' , Types . Content )
147157 @param ( 'tid' , Types . ObjectId , true )
158+ @param ( 'hidden' , Types . Boolean , true )
148159 @param ( 'maintainer' , Types . NumericArray , true )
149160 @param ( 'assign' , Types . CommaSeperatedArray , true )
150161 @param ( 'parent' , Types . ObjectId , true )
@@ -154,6 +165,7 @@ export class SystemProblemListEditHandler extends Handler {
154165 content : string ,
155166 _pids : string ,
156167 _tid : ObjectId = null ,
168+ hidden : boolean = false ,
157169 maintainer : number [ ] = [ ] ,
158170 assign : string [ ] = [ ] ,
159171 parent : ObjectId = null ,
@@ -176,6 +188,7 @@ export class SystemProblemListEditHandler extends Handler {
176188 {
177189 maintainer,
178190 assign,
191+ hidden,
179192 } ,
180193 parent ,
181194 ) ;
@@ -186,6 +199,7 @@ export class SystemProblemListEditHandler extends Handler {
186199 pids,
187200 maintainer,
188201 assign,
202+ hidden,
189203 parent,
190204 } ) ;
191205 }
0 commit comments