未验证 提交 ea2e8769 编写于 作者: K KubeSphere CI Bot 提交者: GitHub

Merge pull request #2126 from junotx/master

fix events search
......@@ -303,20 +303,7 @@ func (t *tenantOperator) listIntersectedNamespaces(user user.Info,
iNamespaces []*corev1.Namespace
)
// When user can list all namespaces, the namespaces which do not belong to any workspace should be considered
listNs := authorizer.AttributesRecord{
User: user,
Verb: "list",
APIGroup: "",
APIVersion: "v1",
Resource: "namespaces",
ResourceRequest: true,
}
decision, _, err := t.authorizer.Authorize(listNs)
if err != nil {
return nil, err
}
includeNsWithoutWs := len(workspaceSet) == 0 && len(workspaceSubstrs) == 0 && decision == authorizer.DecisionAllow
includeNsWithoutWs := len(workspaceSet) == 0 && len(workspaceSubstrs) == 0
roleBindings, err := t.am.ListRoleBindings(user.GetName(), "")
if err != nil {
......
......@@ -226,6 +226,7 @@ func parseToQueryPart(f *events.Filter) interface{} {
Filter []map[string]interface{} `json:"filter,omitempty"`
Should []map[string]interface{} `json:"should,omitempty"`
MinimumShouldMatch *int `json:"minimum_should_match,omitempty"`
MustNot []map[string]interface{} `json:"must_not,omitempty"`
}
var mini = 1
b := BoolBody{}
......@@ -236,6 +237,15 @@ func parseToQueryPart(f *events.Filter) interface{} {
if len(f.InvolvedObjectNamespaceMap) > 0 {
bi := BoolBody{MinimumShouldMatch: &mini}
for k, v := range f.InvolvedObjectNamespaceMap {
if k == "" {
bi.Should = append(bi.Should, map[string]interface{}{
"bool": &BoolBody{
MustNot: []map[string]interface{}{{
"exists": map[string]string{"field": "involvedObject.namespace"},
}},
},
})
} else {
bi.Should = append(bi.Should, map[string]interface{}{
"bool": &BoolBody{
Filter: []map[string]interface{}{{
......@@ -250,6 +260,7 @@ func parseToQueryPart(f *events.Filter) interface{} {
},
})
}
}
if len(bi.Should) > 0 {
b.Filter = append(b.Filter, map[string]interface{}{"bool": &bi})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册