mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:37:31 +00:00
feat: New user (#1153)
* fix: use pointer in events * fix: change user requests to command side * fix: org policy * fix: profile
This commit is contained in:
@@ -60,48 +60,48 @@ func (s *Server) CreateUser(ctx context.Context, in *management.CreateUserReques
|
||||
}
|
||||
|
||||
func (s *Server) DeactivateUser(ctx context.Context, in *management.UserID) (*management.UserResponse, error) {
|
||||
user, err := s.user.DeactivateUser(ctx, in.Id)
|
||||
user, err := s.command.DeactivateUser(ctx, in.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userFromModel(user), nil
|
||||
return userFromDomain(user), nil
|
||||
}
|
||||
|
||||
func (s *Server) ReactivateUser(ctx context.Context, in *management.UserID) (*management.UserResponse, error) {
|
||||
user, err := s.user.ReactivateUser(ctx, in.Id)
|
||||
user, err := s.command.ReactivateUser(ctx, in.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userFromModel(user), nil
|
||||
return userFromDomain(user), nil
|
||||
}
|
||||
|
||||
func (s *Server) LockUser(ctx context.Context, in *management.UserID) (*management.UserResponse, error) {
|
||||
user, err := s.user.LockUser(ctx, in.Id)
|
||||
user, err := s.command.LockUser(ctx, in.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userFromModel(user), nil
|
||||
return userFromDomain(user), nil
|
||||
}
|
||||
|
||||
func (s *Server) UnlockUser(ctx context.Context, in *management.UserID) (*management.UserResponse, error) {
|
||||
user, err := s.user.UnlockUser(ctx, in.Id)
|
||||
user, err := s.command.UnlockUser(ctx, in.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userFromModel(user), nil
|
||||
return userFromDomain(user), nil
|
||||
}
|
||||
|
||||
func (s *Server) DeleteUser(ctx context.Context, in *management.UserID) (*empty.Empty, error) {
|
||||
err := s.user.RemoveUser(ctx, in.Id)
|
||||
err := s.command.RemoveUser(ctx, in.Id)
|
||||
return &empty.Empty{}, err
|
||||
}
|
||||
|
||||
func (s *Server) UpdateUserMachine(ctx context.Context, in *management.UpdateMachineRequest) (*management.MachineResponse, error) {
|
||||
machine, err := s.user.ChangeMachine(ctx, updateMachineToModel(in))
|
||||
machine, err := s.command.ChangeMachine(ctx, updateMachineToDomain(in))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return machineFromModel(machine), nil
|
||||
return machineFromDomain(machine), nil
|
||||
}
|
||||
|
||||
func (s *Server) GetUserProfile(ctx context.Context, in *management.UserID) (*management.UserProfileView, error) {
|
||||
@@ -117,11 +117,11 @@ func (s *Server) ChangeUserUserName(ctx context.Context, request *management.Upd
|
||||
}
|
||||
|
||||
func (s *Server) UpdateUserProfile(ctx context.Context, request *management.UpdateUserProfileRequest) (*management.UserProfile, error) {
|
||||
profile, err := s.user.ChangeProfile(ctx, updateProfileToModel(request))
|
||||
profile, err := s.command.ChangeHumanProfile(ctx, updateProfileToDomain(request))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return profileFromModel(profile), nil
|
||||
return profileFromDomain(profile), nil
|
||||
}
|
||||
|
||||
func (s *Server) GetUserEmail(ctx context.Context, in *management.UserID) (*management.UserEmailView, error) {
|
||||
@@ -133,11 +133,11 @@ func (s *Server) GetUserEmail(ctx context.Context, in *management.UserID) (*mana
|
||||
}
|
||||
|
||||
func (s *Server) ChangeUserEmail(ctx context.Context, request *management.UpdateUserEmailRequest) (*management.UserEmail, error) {
|
||||
email, err := s.user.ChangeEmail(ctx, updateEmailToModel(request))
|
||||
email, err := s.command.ChangeHumanEmail(ctx, updateEmailToDomain(request))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return emailFromModel(email), nil
|
||||
return emailFromDomain(email), nil
|
||||
}
|
||||
|
||||
func (s *Server) ResendEmailVerificationMail(ctx context.Context, in *management.UserID) (*empty.Empty, error) {
|
||||
@@ -180,11 +180,11 @@ func (s *Server) GetUserAddress(ctx context.Context, in *management.UserID) (*ma
|
||||
}
|
||||
|
||||
func (s *Server) UpdateUserAddress(ctx context.Context, request *management.UpdateUserAddressRequest) (*management.UserAddress, error) {
|
||||
address, err := s.user.ChangeAddress(ctx, updateAddressToModel(request))
|
||||
address, err := s.command.ChangeHumanAddress(ctx, updateAddressToDomain(request))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return addressFromModel(address), nil
|
||||
return addressFromDomain(address), nil
|
||||
}
|
||||
|
||||
func (s *Server) SendSetPasswordNotification(ctx context.Context, request *management.SetPasswordNotificationRequest) (*empty.Empty, error) {
|
||||
|
@@ -43,32 +43,6 @@ func userFromDomain(user *domain.User) *management.UserResponse {
|
||||
return userResp
|
||||
}
|
||||
|
||||
func userFromModel(user *usr_model.User) *management.UserResponse {
|
||||
creationDate, err := ptypes.TimestampProto(user.CreationDate)
|
||||
logging.Log("GRPC-8duwe").OnError(err).Debug("unable to parse timestamp")
|
||||
|
||||
changeDate, err := ptypes.TimestampProto(user.ChangeDate)
|
||||
logging.Log("GRPC-ckoe3d").OnError(err).Debug("unable to parse timestamp")
|
||||
|
||||
userResp := &management.UserResponse{
|
||||
Id: user.AggregateID,
|
||||
State: management.UserState(user.State),
|
||||
CreationDate: creationDate,
|
||||
ChangeDate: changeDate,
|
||||
Sequence: user.Sequence,
|
||||
UserName: user.UserName,
|
||||
}
|
||||
|
||||
if user.Machine != nil {
|
||||
userResp.User = &management.UserResponse_Machine{Machine: machineFromModel(user.Machine)}
|
||||
}
|
||||
if user.Human != nil {
|
||||
userResp.User = &management.UserResponse_Human{Human: humanFromModel(user.Human)}
|
||||
}
|
||||
|
||||
return userResp
|
||||
}
|
||||
|
||||
func userCreateToDomain(user *management.CreateUserRequest) *domain.User {
|
||||
var human *domain.Human
|
||||
var machine *domain.Machine
|
||||
@@ -232,7 +206,7 @@ func userMembershipSearchKeyToModel(key management.UserMembershipSearchKey) usr_
|
||||
}
|
||||
}
|
||||
|
||||
func profileFromModel(profile *usr_model.Profile) *management.UserProfile {
|
||||
func profileFromDomain(profile *domain.Profile) *management.UserProfile {
|
||||
creationDate, err := ptypes.TimestampProto(profile.CreationDate)
|
||||
logging.Log("GRPC-dkso3").OnError(err).Debug("unable to parse timestamp")
|
||||
|
||||
@@ -276,21 +250,21 @@ func profileViewFromModel(profile *usr_model.Profile) *management.UserProfileVie
|
||||
}
|
||||
}
|
||||
|
||||
func updateProfileToModel(u *management.UpdateUserProfileRequest) *usr_model.Profile {
|
||||
func updateProfileToDomain(u *management.UpdateUserProfileRequest) *domain.Profile {
|
||||
preferredLanguage, err := language.Parse(u.PreferredLanguage)
|
||||
logging.Log("GRPC-d8k2s").OnError(err).Debug("language malformed")
|
||||
|
||||
return &usr_model.Profile{
|
||||
return &domain.Profile{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: u.Id},
|
||||
FirstName: u.FirstName,
|
||||
LastName: u.LastName,
|
||||
NickName: u.NickName,
|
||||
PreferredLanguage: preferredLanguage,
|
||||
Gender: usr_model.Gender(u.Gender),
|
||||
Gender: genderToDomain(u.Gender),
|
||||
}
|
||||
}
|
||||
|
||||
func emailFromModel(email *usr_model.Email) *management.UserEmail {
|
||||
func emailFromDomain(email *domain.Email) *management.UserEmail {
|
||||
creationDate, err := ptypes.TimestampProto(email.CreationDate)
|
||||
logging.Log("GRPC-d9ow2").OnError(err).Debug("unable to parse timestamp")
|
||||
|
||||
@@ -324,8 +298,8 @@ func emailViewFromModel(email *usr_model.Email) *management.UserEmailView {
|
||||
}
|
||||
}
|
||||
|
||||
func updateEmailToModel(e *management.UpdateUserEmailRequest) *usr_model.Email {
|
||||
return &usr_model.Email{
|
||||
func updateEmailToDomain(e *management.UpdateUserEmailRequest) *domain.Email {
|
||||
return &domain.Email{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: e.Id},
|
||||
EmailAddress: e.Email,
|
||||
IsEmailVerified: e.IsEmailVerified,
|
||||
@@ -373,7 +347,7 @@ func updatePhoneToModel(e *management.UpdateUserPhoneRequest) *usr_model.Phone {
|
||||
}
|
||||
}
|
||||
|
||||
func addressFromModel(address *usr_model.Address) *management.UserAddress {
|
||||
func addressFromDomain(address *domain.Address) *management.UserAddress {
|
||||
creationDate, err := ptypes.TimestampProto(address.CreationDate)
|
||||
logging.Log("GRPC-ud8w7").OnError(err).Debug("unable to parse timestamp")
|
||||
|
||||
@@ -413,8 +387,8 @@ func addressViewFromModel(address *usr_model.Address) *management.UserAddressVie
|
||||
}
|
||||
}
|
||||
|
||||
func updateAddressToModel(address *management.UpdateUserAddressRequest) *usr_model.Address {
|
||||
return &usr_model.Address{
|
||||
func updateAddressToDomain(address *management.UpdateUserAddressRequest) *domain.Address {
|
||||
return &domain.Address{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: address.Id},
|
||||
Country: address.Country,
|
||||
StreetAddress: address.StreetAddress,
|
||||
|
@@ -20,9 +20,10 @@ func machineCreateToDomain(machine *management.CreateMachineRequest) *domain.Mac
|
||||
}
|
||||
}
|
||||
|
||||
func updateMachineToModel(machine *management.UpdateMachineRequest) *usr_model.Machine {
|
||||
return &usr_model.Machine{
|
||||
func updateMachineToDomain(machine *management.UpdateMachineRequest) *domain.Machine {
|
||||
return &domain.Machine{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: machine.Id},
|
||||
Name: machine.Name,
|
||||
Description: machine.Description,
|
||||
}
|
||||
}
|
||||
@@ -34,13 +35,6 @@ func machineFromDomain(account *domain.Machine) *management.MachineResponse {
|
||||
}
|
||||
}
|
||||
|
||||
func machineFromModel(account *usr_model.Machine) *management.MachineResponse {
|
||||
return &management.MachineResponse{
|
||||
Name: account.Name,
|
||||
Description: account.Description,
|
||||
}
|
||||
}
|
||||
|
||||
func machineViewFromModel(machine *usr_model.MachineView) *management.MachineView {
|
||||
lastKeyAdded, err := ptypes.TimestampProto(machine.LastKeyAdded)
|
||||
logging.Log("MANAG-wGcAQ").OnError(err).Debug("unable to parse date")
|
||||
|
Reference in New Issue
Block a user