Merge pull request #14428 from heww/fix-issue-14338

fix: search charts in the projects the user owned
This commit is contained in:
Wenkai Yin(尹文开) 2021-03-17 13:32:24 +08:00 committed by GitHub
commit cd15b4fbdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {