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

Merge pull request #1111 from wansir/master

feat: support user-facing role filter
...@@ -58,7 +58,7 @@ func (*clusterRoleSearcher) match(match map[string]string, item *rbac.ClusterRol ...@@ -58,7 +58,7 @@ func (*clusterRoleSearcher) match(match map[string]string, item *rbac.ClusterRol
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
case "userfacing": case UserFacing:
if v == "true" { if v == "true" {
if !isUserFacingClusterRole(item) { if !isUserFacingClusterRole(item) {
return false return false
...@@ -145,6 +145,7 @@ func (s *clusterRoleSearcher) search(namespace string, conditions *params.Condit ...@@ -145,6 +145,7 @@ func (s *clusterRoleSearcher) search(namespace string, conditions *params.Condit
return r, nil return r, nil
} }
// cluster role created by user from kubesphere dashboard
func isUserFacingClusterRole(role *rbac.ClusterRole) bool { func isUserFacingClusterRole(role *rbac.ClusterRole) bool {
if role.Annotations[constants.CreatorAnnotationKey] != "" && role.Labels[constants.WorkspaceLabelKey] == "" { if role.Annotations[constants.CreatorAnnotationKey] != "" && role.Labels[constants.WorkspaceLabelKey] == "" {
return true return true
......
...@@ -74,6 +74,7 @@ const ( ...@@ -74,6 +74,7 @@ const (
release = "release" release = "release"
annotation = "annotation" annotation = "annotation"
Keyword = "keyword" Keyword = "keyword"
UserFacing = "userfacing"
Status = "status" Status = "status"
includeCronJob = "includeCronJob" includeCronJob = "includeCronJob"
storageClassName = "storageClassName" storageClassName = "storageClassName"
......
...@@ -49,6 +49,12 @@ func (*roleSearcher) match(match map[string]string, item *rbac.Role) bool { ...@@ -49,6 +49,12 @@ func (*roleSearcher) match(match map[string]string, item *rbac.Role) bool {
if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) { if !strings.Contains(item.Name, v) && !searchFuzzy(item.Labels, "", v) && !searchFuzzy(item.Annotations, "", v) {
return false return false
} }
case UserFacing:
if v == "true" {
if !isUserFacingRole(item) {
return false
}
}
default: default:
// label not exist or value not equal // label not exist or value not equal
if val, ok := item.Labels[k]; !ok || val != v { if val, ok := item.Labels[k]; !ok || val != v {
...@@ -129,3 +135,11 @@ func (s *roleSearcher) search(namespace string, conditions *params.Conditions, o ...@@ -129,3 +135,11 @@ func (s *roleSearcher) search(namespace string, conditions *params.Conditions, o
} }
return r, nil return r, nil
} }
// role created by user from kubesphere dashboard
func isUserFacingRole(role *rbac.Role) bool {
if role.Annotations[constants.CreatorAnnotationKey] != "" {
return true
}
return false
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册