From 01b3994f59691551b472fab3d7993086542d4134 Mon Sep 17 00:00:00 2001 From: He Weiwei Date: Fri, 12 Mar 2021 07:03:00 +0000 Subject: [PATCH] fix: search charts in the projects the user owned Closes #14338 Signed-off-by: He Weiwei --- src/core/api/search.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/api/search.go b/src/core/api/search.go index 9735d650c..553074b20 100644 --- a/src/core/api/search.go +++ b/src/core/api/search.go @@ -16,6 +16,7 @@ package api import ( "fmt" + "strings" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/dao" @@ -53,10 +54,6 @@ func (s *SearchAPI) Get() { query := q.New(q.KeyWords{}) query.Sorting = "name" - if keyword != "" { - query.Keywords["name"] = &q.FuzzyMatchValue{Value: keyword} - } - if !s.SecurityCtx.IsSysAdmin() { if sc, ok := s.SecurityCtx.(*local.SecurityContext); ok && sc.IsAuthenticated() { user := sc.User() @@ -82,6 +79,10 @@ func (s *SearchAPI) Get() { for _, p := range projects { proNames = append(proNames, p.Name) + if keyword != "" && !strings.Contains(p.Name, keyword) { + continue + } + if sc, ok := s.SecurityCtx.(*local.SecurityContext); ok && sc.IsAuthenticated() { roles, err := s.ProjectCtl.ListRoles(s.Context(), p.ProjectID, sc.User()) if err != nil {