Fix cannot change user status to disabled

This commit is contained in:
hongming
2022-03-01 11:36:17 +08:00
parent 970780993e
commit 4457f61a22
7 changed files with 38 additions and 38 deletions

View File

@@ -18,6 +18,7 @@ package im
import (
"context"
"fmt"
"time"
"kubesphere.io/kubesphere/pkg/apiserver/authentication"
@@ -70,7 +71,13 @@ func (im *imOperator) UpdateUser(new *iamv1alpha2.User) (*iamv1alpha2.User, erro
}
// keep encrypted password and user status
new.Spec.EncryptedPassword = old.Spec.EncryptedPassword
new.Status = old.Status
status := old.Status
// only support enable or disable
if new.Status.State == iamv1alpha2.UserDisabled || new.Status.State == iamv1alpha2.UserActive {
status.State = new.Status.State
status.LastTransitionTime = &metav1.Time{Time: time.Now()}
}
new.Status = status
updated, err := im.ksClient.IamV1alpha2().Users().Update(context.Background(), new, metav1.UpdateOptions{})
if err != nil {
klog.Error(err)