@@ -430,72 +430,7 @@ func SearchConversations(ctx *context.Context) {
430430 isClosed = optional .Some (false )
431431 }
432432
433- var (
434- repoIDs []int64
435- allPublic bool
436- )
437- {
438- // find repos user can access (for conversation search)
439- opts := & repo_model.SearchRepoOptions {
440- Private : false ,
441- AllPublic : true ,
442- TopicOnly : false ,
443- Collaborate : optional .None [bool ](),
444- // This needs to be a column that is not nil in fixtures or
445- // MySQL will return different results when sorting by null in some cases
446- OrderBy : db .SearchOrderByAlphabetically ,
447- Actor : ctx .Doer ,
448- }
449- if ctx .IsSigned {
450- opts .Private = true
451- opts .AllLimited = true
452- }
453- if ctx .FormString ("owner" ) != "" {
454- owner , err := user_model .GetUserByName (ctx , ctx .FormString ("owner" ))
455- if err != nil {
456- if user_model .IsErrUserNotExist (err ) {
457- ctx .Error (http .StatusBadRequest , "Owner not found" , err .Error ())
458- } else {
459- ctx .Error (http .StatusInternalServerError , "GetUserByName" , err .Error ())
460- }
461- return
462- }
463- opts .OwnerID = owner .ID
464- opts .AllLimited = false
465- opts .AllPublic = false
466- opts .Collaborate = optional .Some (false )
467- }
468- if ctx .FormString ("team" ) != "" {
469- if ctx .FormString ("owner" ) == "" {
470- ctx .Error (http .StatusBadRequest , "" , "Owner organisation is required for filtering on team" )
471- return
472- }
473- team , err := organization .GetTeam (ctx , opts .OwnerID , ctx .FormString ("team" ))
474- if err != nil {
475- if organization .IsErrTeamNotExist (err ) {
476- ctx .Error (http .StatusBadRequest , "Team not found" , err .Error ())
477- } else {
478- ctx .Error (http .StatusInternalServerError , "GetUserByName" , err .Error ())
479- }
480- return
481- }
482- opts .TeamID = team .ID
483- }
484-
485- if opts .AllPublic {
486- allPublic = true
487- opts .AllPublic = false // set it false to avoid returning too many repos, we could filter by indexer
488- }
489- repoIDs , _ , err = repo_model .SearchRepositoryIDs (ctx , opts )
490- if err != nil {
491- ctx .Error (http .StatusInternalServerError , "SearchRepositoryIDs" , err .Error ())
492- return
493- }
494- if len (repoIDs ) == 0 {
495- // no repos found, don't let the indexer return all repos
496- repoIDs = []int64 {0 }
497- }
498- }
433+ repoIDs , allPublic := GetUserAccessibleRepo (ctx )
499434
500435 keyword := ctx .FormTrim ("q" )
501436 if strings .IndexByte (keyword , 0 ) >= 0 {
@@ -568,6 +503,74 @@ func SearchConversations(ctx *context.Context) {
568503 ctx .JSON (http .StatusOK , convert .ToConversationList (ctx , ctx .Doer , conversations ))
569504}
570505
506+ func GetUserAccessibleRepo (ctx * context.Context ) ([]int64 , bool ) {
507+ var (
508+ repoIDs []int64
509+ allPublic bool
510+ )
511+ // find repos user can access (for conversation search)
512+ opts := & repo_model.SearchRepoOptions {
513+ Private : false ,
514+ AllPublic : true ,
515+ TopicOnly : false ,
516+ Collaborate : optional .None [bool ](),
517+ // This needs to be a column that is not nil in fixtures or
518+ // MySQL will return different results when sorting by null in some cases
519+ OrderBy : db .SearchOrderByAlphabetically ,
520+ Actor : ctx .Doer ,
521+ }
522+ if ctx .IsSigned {
523+ opts .Private = true
524+ opts .AllLimited = true
525+ }
526+ if ctx .FormString ("owner" ) != "" {
527+ owner , err := user_model .GetUserByName (ctx , ctx .FormString ("owner" ))
528+ if err != nil {
529+ if user_model .IsErrUserNotExist (err ) {
530+ ctx .Error (http .StatusBadRequest , "Owner not found" , err .Error ())
531+ } else {
532+ ctx .Error (http .StatusInternalServerError , "GetUserByName" , err .Error ())
533+ }
534+ return nil , false
535+ }
536+ opts .OwnerID = owner .ID
537+ opts .AllLimited = false
538+ opts .AllPublic = false
539+ opts .Collaborate = optional .Some (false )
540+ }
541+ if ctx .FormString ("team" ) != "" {
542+ if ctx .FormString ("owner" ) == "" {
543+ ctx .Error (http .StatusBadRequest , "" , "Owner organisation is required for filtering on team" )
544+ return nil , false
545+ }
546+ team , err := organization .GetTeam (ctx , opts .OwnerID , ctx .FormString ("team" ))
547+ if err != nil {
548+ if organization .IsErrTeamNotExist (err ) {
549+ ctx .Error (http .StatusBadRequest , "Team not found" , err .Error ())
550+ } else {
551+ ctx .Error (http .StatusInternalServerError , "GetUserByName" , err .Error ())
552+ }
553+ return nil , false
554+ }
555+ opts .TeamID = team .ID
556+ }
557+
558+ if opts .AllPublic {
559+ allPublic = true
560+ opts .AllPublic = false // set it false to avoid returning too many repos, we could filter by indexer
561+ }
562+ repoIDs , _ , err := repo_model .SearchRepositoryIDs (ctx , opts )
563+ if err != nil {
564+ ctx .Error (http .StatusInternalServerError , "SearchRepositoryIDs" , err .Error ())
565+ return nil , false
566+ }
567+ if len (repoIDs ) == 0 {
568+ // no repos found, don't let the indexer return all repos
569+ repoIDs = []int64 {0 }
570+ }
571+ return repoIDs , allPublic
572+ }
573+
571574// ListConversations list the conversations of a repository
572575func ListConversations (ctx * context.Context ) {
573576 before , since , err := context .GetQueryBeforeSince (ctx .Base )
0 commit comments