mirror of
https://github.com/zitadel/zitadel.git
synced 2025-10-18 09:12:18 +00:00
feat: Import user and hide loginname suffix (#1464)
* fix: import user * fix: label policy * fix: label policy * fix: label policy * fix: migrations * fix: migrations * fix: migrations * fix: label policy * loginSuffix in login ui * suffix * fix cursor on disabled user selection Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
||||
|
||||
func labelPolicyToModel(policy *admin.DefaultLabelPolicyUpdate) *iam_model.LabelPolicy {
|
||||
return &iam_model.LabelPolicy{
|
||||
PrimaryColor: policy.PrimaryColor,
|
||||
SecondaryColor: policy.SecondaryColor,
|
||||
PrimaryColor: policy.PrimaryColor,
|
||||
SecondaryColor: policy.SecondaryColor,
|
||||
HideLoginNameSuffix: policy.HideLoginNameSuffix,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +23,11 @@ func labelPolicyFromModel(policy *iam_model.LabelPolicy) *admin.DefaultLabelPoli
|
||||
logging.Log("ADMIN-mAgcI").OnError(err).Debug("date parse failed")
|
||||
|
||||
return &admin.DefaultLabelPolicy{
|
||||
PrimaryColor: policy.PrimaryColor,
|
||||
SecondaryColor: policy.SecondaryColor,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
PrimaryColor: policy.PrimaryColor,
|
||||
SecondaryColor: policy.SecondaryColor,
|
||||
HideLoginNameSuffix: policy.HideLoginNameSuffix,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +39,10 @@ func labelPolicyViewFromModel(policy *iam_model.LabelPolicyView) *admin.DefaultL
|
||||
logging.Log("ADMIN-Vhvfp").OnError(err).Debug("date parse failed")
|
||||
|
||||
return &admin.DefaultLabelPolicyView{
|
||||
PrimaryColor: policy.PrimaryColor,
|
||||
SecondaryColor: policy.SecondaryColor,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
PrimaryColor: policy.PrimaryColor,
|
||||
SecondaryColor: policy.SecondaryColor,
|
||||
HideLoginNameSuffix: policy.HideLoginNameSuffix,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
}
|
||||
}
|
||||
|
45
internal/api/grpc/management/label_policy.go
Normal file
45
internal/api/grpc/management/label_policy.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package management
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/pkg/grpc/management"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
)
|
||||
|
||||
func (s *Server) GetLabelPolicy(ctx context.Context, _ *empty.Empty) (*management.LabelPolicyView, error) {
|
||||
result, err := s.org.GetLabelPolicy(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return labelPolicyViewFromModel(result), nil
|
||||
}
|
||||
|
||||
func (s *Server) GetDefaultLabelPolicy(ctx context.Context, _ *empty.Empty) (*management.LabelPolicyView, error) {
|
||||
result, err := s.org.GetLabelPolicy(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return labelPolicyViewFromModel(result), nil
|
||||
}
|
||||
|
||||
func (s *Server) CreateLabelPolicy(ctx context.Context, policy *management.LabelPolicyRequest) (*management.LabelPolicy, error) {
|
||||
result, err := s.org.AddLabelPolicy(ctx, labelPolicyRequestToModel(policy))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return labelPolicyFromModel(result), nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateLabelPolicy(ctx context.Context, policy *management.LabelPolicyRequest) (*management.LabelPolicy, error) {
|
||||
result, err := s.org.ChangeLabelPolicy(ctx, labelPolicyRequestToModel(policy))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return labelPolicyFromModel(result), nil
|
||||
}
|
||||
|
||||
func (s *Server) RemoveLabelPolicy(ctx context.Context, _ *empty.Empty) (*empty.Empty, error) {
|
||||
err := s.org.RemoveLabelPolicy(ctx)
|
||||
return &empty.Empty{}, err
|
||||
}
|
50
internal/api/grpc/management/label_policy_converter.go
Normal file
50
internal/api/grpc/management/label_policy_converter.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package management
|
||||
|
||||
import (
|
||||
"github.com/caos/logging"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
"github.com/caos/zitadel/pkg/grpc/management"
|
||||
)
|
||||
|
||||
func labelPolicyRequestToModel(policy *management.LabelPolicyRequest) *iam_model.LabelPolicy {
|
||||
return &iam_model.LabelPolicy{
|
||||
SecondaryColor: policy.SecondaryColor,
|
||||
PrimaryColor: policy.PrimaryColor,
|
||||
HideLoginNameSuffix: policy.HideLoginNameSuffix,
|
||||
}
|
||||
}
|
||||
|
||||
func labelPolicyFromModel(policy *iam_model.LabelPolicy) *management.LabelPolicy {
|
||||
creationDate, err := ptypes.TimestampProto(policy.CreationDate)
|
||||
logging.Log("GRPC-2Fsm8").OnError(err).Debug("date parse failed")
|
||||
|
||||
changeDate, err := ptypes.TimestampProto(policy.ChangeDate)
|
||||
logging.Log("GRPC-3Flo0").OnError(err).Debug("date parse failed")
|
||||
|
||||
return &management.LabelPolicy{
|
||||
SecondaryColor: policy.SecondaryColor,
|
||||
PrimaryColor: policy.PrimaryColor,
|
||||
HideLoginNameSuffix: policy.HideLoginNameSuffix,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
}
|
||||
}
|
||||
|
||||
func labelPolicyViewFromModel(policy *iam_model.LabelPolicyView) *management.LabelPolicyView {
|
||||
creationDate, err := ptypes.TimestampProto(policy.CreationDate)
|
||||
logging.Log("GRPC-5Tsm8").OnError(err).Debug("date parse failed")
|
||||
|
||||
changeDate, err := ptypes.TimestampProto(policy.ChangeDate)
|
||||
logging.Log("GRPC-8dJgs").OnError(err).Debug("date parse failed")
|
||||
|
||||
return &management.LabelPolicyView{
|
||||
Default: policy.Default,
|
||||
SecondaryColor: policy.SecondaryColor,
|
||||
PrimaryColor: policy.PrimaryColor,
|
||||
HideLoginNameSuffix: policy.HideLoginNameSuffix,
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
}
|
||||
}
|
@@ -59,6 +59,14 @@ func (s *Server) CreateUser(ctx context.Context, in *management.CreateUserReques
|
||||
return userFromModel(user), nil
|
||||
}
|
||||
|
||||
func (s *Server) ImportHuman(ctx context.Context, in *management.ImportHumanRequest) (*management.UserResponse, error) {
|
||||
user, err := s.user.ImportUser(ctx, humanImportToModel(in), in.PasswordChangeRequired)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userFromModel(user), nil
|
||||
}
|
||||
|
||||
func (s *Server) DeactivateUser(ctx context.Context, in *management.UserID) (*management.UserResponse, error) {
|
||||
user, err := s.user.DeactivateUser(ctx, in.Id)
|
||||
if err != nil {
|
||||
|
@@ -60,6 +60,42 @@ func userCreateToModel(user *management.CreateUserRequest) *usr_model.User {
|
||||
}
|
||||
}
|
||||
|
||||
func humanImportToModel(user *management.ImportHumanRequest) *usr_model.User {
|
||||
preferredLanguage, err := language.Parse(user.PreferredLanguage)
|
||||
logging.Log("GRPC-cK5k2").OnError(err).Debug("language malformed")
|
||||
|
||||
human := &usr_model.Human{
|
||||
Profile: &usr_model.Profile{
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
||||
NickName: user.NickName,
|
||||
PreferredLanguage: preferredLanguage,
|
||||
Gender: genderToModel(user.Gender),
|
||||
},
|
||||
Email: &usr_model.Email{
|
||||
EmailAddress: user.Email,
|
||||
IsEmailVerified: user.IsEmailVerified,
|
||||
},
|
||||
Address: &usr_model.Address{
|
||||
Country: user.Country,
|
||||
Locality: user.Locality,
|
||||
PostalCode: user.PostalCode,
|
||||
Region: user.Region,
|
||||
StreetAddress: user.StreetAddress,
|
||||
},
|
||||
}
|
||||
if user.Password != "" {
|
||||
human.Password = &usr_model.Password{SecretString: user.Password}
|
||||
}
|
||||
if user.Phone != "" {
|
||||
human.Phone = &usr_model.Phone{PhoneNumber: user.Phone, IsPhoneVerified: user.IsPhoneVerified}
|
||||
}
|
||||
return &usr_model.User{
|
||||
UserName: user.UserName,
|
||||
Human: human,
|
||||
}
|
||||
}
|
||||
|
||||
func passwordRequestToModel(r *management.PasswordRequest) *usr_model.Password {
|
||||
return &usr_model.Password{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: r.Id},
|
||||
|
Reference in New Issue
Block a user