@@ -192,23 +192,35 @@ export class ProblemMainHandler extends Handler {
192192 @param ( 'target' , Types . String )
193193 @param ( 'hidden' , Types . Boolean )
194194 async postCopy ( domainId : string , pids : number [ ] , target : string , hidden ?: boolean ) {
195- const t = `,${ this . domain . share || '' } ,` ;
196- if ( t !== ',*,' && ! t . includes ( `,${ target } ,` ) ) throw new PermissionError ( target ) ;
197- const ddoc = await domain . get ( target ) ;
195+ let t = `,${ this . domain . share || '' } ,` ;
196+ if ( t !== ',*,' && ! t . includes ( `,${ target } ,` ) ) throw new ProblemNotAllowCopyError ( this . domain . _id , target ) ;
197+ let ddoc = await domain . get ( target ) ;
198198 if ( ! ddoc ) throw new NotFoundError ( target ) ;
199199 const dudoc = await user . getById ( target , this . user . _id ) ;
200200 if ( ! dudoc . hasPerm ( PERM . PERM_CREATE_PROBLEM ) ) throw new PermissionError ( PERM . PERM_CREATE_PROBLEM ) ;
201201 // Check if user can access all those problems
202- await problem . getList (
202+ const pdict = await problem . getList (
203203 domainId , pids , this . user . hasPerm ( PERM . PERM_VIEW_PROBLEM_HIDDEN ) || this . user . _id ,
204204 true , [ 'docId' ] , true ,
205205 ) ;
206206 const ids = [ ] ;
207207 for ( const pid of pids ) {
208+ let pdoc = pdict [ pid ] ;
209+ if ( pdoc . reference ) {
210+ // eslint-disable-next-line no-await-in-loop
211+ [ pdoc , ddoc ] = await Promise . all ( [
212+ problem . get ( pdoc . reference . domainId , pdoc . reference . pid ) ,
213+ domain . get ( pdoc . reference . domainId ) ,
214+ ] ) ;
215+ if ( ! pdoc ) throw new ProblemNotFoundError ( pdoc . reference . domainId , pdoc . reference . pid ) ;
216+ t = `,${ ddoc . share || '' } ,` ;
217+ if ( t !== ',*,' && ! t . includes ( `,${ target } ,` ) ) throw new ProblemNotAllowCopyError ( ddoc . _id , target ) ;
218+ }
208219 // eslint-disable-next-line no-await-in-loop
209- ids . push ( await problem . copy ( domainId , pid , target , undefined , hidden ) ) ;
220+ ids . push ( await problem . copy ( pdoc . domainId , pdoc . docId , target , undefined , hidden ) ) ;
210221 }
211222 this . response . body = ids ;
223+ if ( ids . length === 1 ) this . response . redirect = this . url ( 'problem_detail' , { domainId : target , pid : ids [ 0 ] } ) ;
212224 }
213225
214226 @param ( 'pids' , Types . NumericArray )
@@ -420,28 +432,6 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
420432 this . back ( ) ;
421433 }
422434
423- @param ( 'target' , Types . String )
424- async postCopy ( { } , target : string ) {
425- let t = `,${ this . domain . share || '' } ,` ;
426- if ( t !== ',*,' && ! t . includes ( `,${ target } ,` ) ) throw new ProblemNotAllowCopyError ( this . domain . _id , target ) ;
427- let ddoc = await domain . get ( target ) ;
428- if ( ! ddoc ) throw new NotFoundError ( target ) ;
429- const dudoc = await user . getById ( target , this . user . _id ) ;
430- let pdoc = this . pdoc ;
431- if ( this . pdoc . reference ) {
432- [ pdoc , ddoc ] = await Promise . all ( [
433- problem . get ( this . pdoc . reference . domainId , this . pdoc . reference . pid ) ,
434- domain . get ( this . pdoc . reference . domainId ) ,
435- ] ) ;
436- if ( ! pdoc ) throw new ProblemNotFoundError ( this . pdoc . reference . domainId , this . pdoc . reference . pid ) ;
437- t = `,${ ddoc . share || '' } ,` ;
438- if ( t !== ',*,' && ! t . includes ( `,${ target } ,` ) ) throw new ProblemNotAllowCopyError ( ddoc . _id , target ) ;
439- }
440- if ( ! dudoc . hasPerm ( PERM . PERM_CREATE_PROBLEM ) ) throw new PermissionError ( PERM . PERM_CREATE_PROBLEM ) ;
441- const docId = await problem . copy ( pdoc . domainId , pdoc . docId , target ) ;
442- this . response . redirect = this . url ( 'problem_detail' , { domainId : target , pid : docId } ) ;
443- }
444-
445435 async postDelete ( ) {
446436 if ( ! this . user . own ( this . pdoc , PERM . PERM_EDIT_PROBLEM_SELF ) ) this . checkPerm ( PERM . PERM_EDIT_PROBLEM ) ;
447437 const tdocs = await contest . getRelated ( this . args . domainId , this . pdoc . docId ) ;
0 commit comments