add group filter for user api

Signed-off-by: Roland.Ma <rolandma@yunify.com>
This commit is contained in:
Roland.Ma
2020-11-25 09:41:26 +00:00
parent f6186a39c3
commit 30216c411b
2 changed files with 7 additions and 0 deletions

View File

@@ -65,6 +65,8 @@ const (
IdentifyProviderLabel = "iam.kubesphere.io/identify-provider"
PasswordEncryptedAnnotation = "iam.kubesphere.io/password-encrypted"
FieldEmail = "email"
InGroup = "ingroup"
NotInGroup = "notingroup"
AggregateTo = "aggregateTo"
ScopeWorkspace = "workspace"
ScopeCluster = "cluster"

View File

@@ -28,6 +28,7 @@ import (
"kubesphere.io/kubesphere/pkg/apiserver/query"
ksinformers "kubesphere.io/kubesphere/pkg/client/informers/externalversions"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
)
type usersGetter struct {
@@ -107,6 +108,10 @@ func (d *usersGetter) filter(object runtime.Object, filter query.Filter) bool {
switch filter.Field {
case iamv1alpha2.FieldEmail:
return user.Spec.Email == string(filter.Value)
case iamv1alpha2.InGroup:
return sliceutil.HasString(user.Spec.Groups, string(filter.Value))
case iamv1alpha2.NotInGroup:
return !sliceutil.HasString(user.Spec.Groups, string(filter.Value))
default:
return v1alpha3.DefaultObjectMetaFilter(user.ObjectMeta, filter)
}