2020-05-11 08:16:27 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
2020-06-15 14:50:09 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
2020-05-11 08:16:27 +00:00
|
|
|
"github.com/caos/logging"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
usr_model "github.com/caos/zitadel/internal/user/model"
|
2020-07-08 07:48:11 +00:00
|
|
|
"github.com/caos/zitadel/pkg/message"
|
|
|
|
|
2020-05-11 08:16:27 +00:00
|
|
|
"github.com/golang/protobuf/ptypes"
|
|
|
|
"golang.org/x/text/language"
|
2020-06-15 14:50:09 +00:00
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
|
|
"google.golang.org/protobuf/types/known/structpb"
|
2020-05-11 08:16:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func userFromModel(user *usr_model.User) *User {
|
|
|
|
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")
|
|
|
|
|
|
|
|
converted := &User{
|
|
|
|
Id: user.AggregateID,
|
|
|
|
State: userStateFromModel(user.State),
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: user.Sequence,
|
|
|
|
UserName: user.UserName,
|
|
|
|
FirstName: user.FirstName,
|
|
|
|
LastName: user.LastName,
|
|
|
|
DisplayName: user.DisplayName,
|
|
|
|
NickName: user.NickName,
|
|
|
|
PreferredLanguage: user.PreferredLanguage.String(),
|
|
|
|
Gender: genderFromModel(user.Gender),
|
|
|
|
}
|
|
|
|
if user.Email != nil {
|
|
|
|
converted.Email = user.EmailAddress
|
|
|
|
converted.IsEmailVerified = user.IsEmailVerified
|
|
|
|
}
|
|
|
|
if user.Phone != nil {
|
|
|
|
converted.Phone = user.PhoneNumber
|
|
|
|
converted.IsPhoneVerified = user.IsPhoneVerified
|
|
|
|
}
|
|
|
|
if user.Address != nil {
|
|
|
|
converted.Country = user.Country
|
|
|
|
converted.Locality = user.Locality
|
|
|
|
converted.PostalCode = user.PostalCode
|
|
|
|
converted.Region = user.Region
|
|
|
|
converted.StreetAddress = user.StreetAddress
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
|
|
|
func userCreateToModel(u *CreateUserRequest) *usr_model.User {
|
|
|
|
preferredLanguage, err := language.Parse(u.PreferredLanguage)
|
|
|
|
logging.Log("GRPC-cK5k2").OnError(err).Debug("language malformed")
|
|
|
|
|
|
|
|
user := &usr_model.User{
|
|
|
|
Profile: &usr_model.Profile{
|
|
|
|
UserName: u.UserName,
|
|
|
|
FirstName: u.FirstName,
|
|
|
|
LastName: u.LastName,
|
|
|
|
NickName: u.NickName,
|
|
|
|
PreferredLanguage: preferredLanguage,
|
|
|
|
Gender: genderToModel(u.Gender),
|
|
|
|
},
|
|
|
|
Email: &usr_model.Email{
|
|
|
|
EmailAddress: u.Email,
|
|
|
|
IsEmailVerified: u.IsEmailVerified,
|
|
|
|
},
|
|
|
|
Address: &usr_model.Address{
|
|
|
|
Country: u.Country,
|
|
|
|
Locality: u.Locality,
|
|
|
|
PostalCode: u.PostalCode,
|
|
|
|
Region: u.Region,
|
|
|
|
StreetAddress: u.StreetAddress,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if u.Password != "" {
|
|
|
|
user.Password = &usr_model.Password{SecretString: u.Password}
|
|
|
|
}
|
|
|
|
if u.Phone != "" {
|
|
|
|
user.Phone = &usr_model.Phone{PhoneNumber: u.Phone, IsPhoneVerified: u.IsPhoneVerified}
|
|
|
|
}
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
|
|
|
|
func passwordRequestToModel(r *PasswordRequest) *usr_model.Password {
|
|
|
|
return &usr_model.Password{
|
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: r.Id},
|
|
|
|
SecretString: r.Password,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 04:30:53 +00:00
|
|
|
func userSearchRequestsToModel(project *UserSearchRequest) *usr_model.UserSearchRequest {
|
|
|
|
return &usr_model.UserSearchRequest{
|
|
|
|
Offset: project.Offset,
|
|
|
|
Limit: project.Limit,
|
|
|
|
Queries: userSearchQueriesToModel(project.Queries),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func userSearchQueriesToModel(queries []*UserSearchQuery) []*usr_model.UserSearchQuery {
|
|
|
|
converted := make([]*usr_model.UserSearchQuery, len(queries))
|
|
|
|
for i, q := range queries {
|
|
|
|
converted[i] = userSearchQueryToModel(q)
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
|
|
|
func userSearchQueryToModel(query *UserSearchQuery) *usr_model.UserSearchQuery {
|
|
|
|
return &usr_model.UserSearchQuery{
|
|
|
|
Key: userSearchKeyToModel(query.Key),
|
|
|
|
Method: searchMethodToModel(query.Method),
|
|
|
|
Value: query.Value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func userSearchKeyToModel(key UserSearchKey) usr_model.UserSearchKey {
|
|
|
|
switch key {
|
|
|
|
case UserSearchKey_USERSEARCHKEY_USER_NAME:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.UserSearchKeyUserName
|
2020-05-12 04:30:53 +00:00
|
|
|
case UserSearchKey_USERSEARCHKEY_FIRST_NAME:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.UserSearchKeyFirstName
|
2020-05-12 04:30:53 +00:00
|
|
|
case UserSearchKey_USERSEARCHKEY_LAST_NAME:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.UserSearchKeyLastName
|
2020-05-12 04:30:53 +00:00
|
|
|
case UserSearchKey_USERSEARCHKEY_NICK_NAME:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.UserSearchKeyNickName
|
2020-05-12 04:30:53 +00:00
|
|
|
case UserSearchKey_USERSEARCHKEY_DISPLAY_NAME:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.UserSearchKeyDisplayName
|
2020-05-12 04:30:53 +00:00
|
|
|
case UserSearchKey_USERSEARCHKEY_EMAIL:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.UserSearchKeyEmail
|
2020-05-12 04:30:53 +00:00
|
|
|
case UserSearchKey_USERSEARCHKEY_STATE:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.UserSearchKeyState
|
2020-05-12 04:30:53 +00:00
|
|
|
default:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.UserSearchKeyUnspecified
|
2020-05-12 04:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:16:27 +00:00
|
|
|
func profileFromModel(profile *usr_model.Profile) *UserProfile {
|
|
|
|
creationDate, err := ptypes.TimestampProto(profile.CreationDate)
|
|
|
|
logging.Log("GRPC-dkso3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(profile.ChangeDate)
|
|
|
|
logging.Log("GRPC-ski8d").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &UserProfile{
|
|
|
|
Id: profile.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: profile.Sequence,
|
|
|
|
UserName: profile.UserName,
|
|
|
|
FirstName: profile.FirstName,
|
|
|
|
LastName: profile.LastName,
|
|
|
|
DisplayName: profile.DisplayName,
|
|
|
|
NickName: profile.NickName,
|
|
|
|
PreferredLanguage: profile.PreferredLanguage.String(),
|
|
|
|
Gender: genderFromModel(profile.Gender),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 05:25:04 +00:00
|
|
|
func profileViewFromModel(profile *usr_model.Profile) *UserProfileView {
|
|
|
|
creationDate, err := ptypes.TimestampProto(profile.CreationDate)
|
|
|
|
logging.Log("GRPC-sk8sk").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(profile.ChangeDate)
|
|
|
|
logging.Log("GRPC-s30Ks'").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &UserProfileView{
|
|
|
|
Id: profile.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: profile.Sequence,
|
|
|
|
UserName: profile.UserName,
|
|
|
|
FirstName: profile.FirstName,
|
|
|
|
LastName: profile.LastName,
|
|
|
|
DisplayName: profile.DisplayName,
|
|
|
|
NickName: profile.NickName,
|
|
|
|
PreferredLanguage: profile.PreferredLanguage.String(),
|
|
|
|
Gender: genderFromModel(profile.Gender),
|
|
|
|
LoginNames: profile.LoginNames,
|
|
|
|
PreferredLoginName: profile.PreferredLoginName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:16:27 +00:00
|
|
|
func updateProfileToModel(u *UpdateUserProfileRequest) *usr_model.Profile {
|
|
|
|
preferredLanguage, err := language.Parse(u.PreferredLanguage)
|
|
|
|
logging.Log("GRPC-d8k2s").OnError(err).Debug("language malformed")
|
|
|
|
|
|
|
|
return &usr_model.Profile{
|
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: u.Id},
|
|
|
|
FirstName: u.FirstName,
|
|
|
|
LastName: u.LastName,
|
|
|
|
NickName: u.NickName,
|
|
|
|
PreferredLanguage: preferredLanguage,
|
|
|
|
Gender: genderToModel(u.Gender),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func emailFromModel(email *usr_model.Email) *UserEmail {
|
|
|
|
creationDate, err := ptypes.TimestampProto(email.CreationDate)
|
|
|
|
logging.Log("GRPC-d9ow2").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(email.ChangeDate)
|
|
|
|
logging.Log("GRPC-s0dkw").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &UserEmail{
|
|
|
|
Id: email.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: email.Sequence,
|
|
|
|
Email: email.EmailAddress,
|
|
|
|
IsEmailVerified: email.IsEmailVerified,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 05:25:04 +00:00
|
|
|
func emailViewFromModel(email *usr_model.Email) *UserEmailView {
|
|
|
|
creationDate, err := ptypes.TimestampProto(email.CreationDate)
|
|
|
|
logging.Log("GRPC-sKefs").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(email.ChangeDate)
|
|
|
|
logging.Log("GRPC-0isjD").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &UserEmailView{
|
|
|
|
Id: email.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: email.Sequence,
|
|
|
|
Email: email.EmailAddress,
|
|
|
|
IsEmailVerified: email.IsEmailVerified,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:16:27 +00:00
|
|
|
func updateEmailToModel(e *UpdateUserEmailRequest) *usr_model.Email {
|
|
|
|
return &usr_model.Email{
|
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: e.Id},
|
|
|
|
EmailAddress: e.Email,
|
|
|
|
IsEmailVerified: e.IsEmailVerified,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func phoneFromModel(phone *usr_model.Phone) *UserPhone {
|
|
|
|
creationDate, err := ptypes.TimestampProto(phone.CreationDate)
|
|
|
|
logging.Log("GRPC-ps9ws").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(phone.ChangeDate)
|
|
|
|
logging.Log("GRPC-09ewq").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &UserPhone{
|
|
|
|
Id: phone.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: phone.Sequence,
|
|
|
|
Phone: phone.PhoneNumber,
|
|
|
|
IsPhoneVerified: phone.IsPhoneVerified,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 05:25:04 +00:00
|
|
|
func phoneViewFromModel(phone *usr_model.Phone) *UserPhoneView {
|
|
|
|
creationDate, err := ptypes.TimestampProto(phone.CreationDate)
|
|
|
|
logging.Log("GRPC-6gSj").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(phone.ChangeDate)
|
|
|
|
logging.Log("GRPC-lKs8f").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &UserPhoneView{
|
|
|
|
Id: phone.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: phone.Sequence,
|
|
|
|
Phone: phone.PhoneNumber,
|
|
|
|
IsPhoneVerified: phone.IsPhoneVerified,
|
|
|
|
}
|
|
|
|
}
|
2020-05-11 08:16:27 +00:00
|
|
|
func updatePhoneToModel(e *UpdateUserPhoneRequest) *usr_model.Phone {
|
|
|
|
return &usr_model.Phone{
|
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: e.Id},
|
|
|
|
PhoneNumber: e.Phone,
|
|
|
|
IsPhoneVerified: e.IsPhoneVerified,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func addressFromModel(address *usr_model.Address) *UserAddress {
|
|
|
|
creationDate, err := ptypes.TimestampProto(address.CreationDate)
|
|
|
|
logging.Log("GRPC-ud8w7").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(address.ChangeDate)
|
|
|
|
logging.Log("GRPC-si9ws").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &UserAddress{
|
|
|
|
Id: address.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: address.Sequence,
|
|
|
|
Country: address.Country,
|
|
|
|
StreetAddress: address.StreetAddress,
|
|
|
|
Region: address.Region,
|
|
|
|
PostalCode: address.PostalCode,
|
|
|
|
Locality: address.Locality,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 05:25:04 +00:00
|
|
|
func addressViewFromModel(address *usr_model.Address) *UserAddressView {
|
|
|
|
creationDate, err := ptypes.TimestampProto(address.CreationDate)
|
|
|
|
logging.Log("GRPC-67stC").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(address.ChangeDate)
|
|
|
|
logging.Log("GRPC-0jSfs").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &UserAddressView{
|
|
|
|
Id: address.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: address.Sequence,
|
|
|
|
Country: address.Country,
|
|
|
|
StreetAddress: address.StreetAddress,
|
|
|
|
Region: address.Region,
|
|
|
|
PostalCode: address.PostalCode,
|
|
|
|
Locality: address.Locality,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:16:27 +00:00
|
|
|
func updateAddressToModel(address *UpdateUserAddressRequest) *usr_model.Address {
|
|
|
|
return &usr_model.Address{
|
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: address.Id},
|
|
|
|
Country: address.Country,
|
|
|
|
StreetAddress: address.StreetAddress,
|
|
|
|
Region: address.Region,
|
|
|
|
PostalCode: address.PostalCode,
|
|
|
|
Locality: address.Locality,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 04:30:53 +00:00
|
|
|
func userSearchResponseFromModel(response *usr_model.UserSearchResponse) *UserSearchResponse {
|
|
|
|
return &UserSearchResponse{
|
|
|
|
Offset: response.Offset,
|
|
|
|
Limit: response.Limit,
|
|
|
|
TotalResult: response.TotalResult,
|
|
|
|
Result: userViewsFromModel(response.Result),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func userViewsFromModel(users []*usr_model.UserView) []*UserView {
|
|
|
|
converted := make([]*UserView, len(users))
|
|
|
|
for i, user := range users {
|
|
|
|
converted[i] = userViewFromModel(user)
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
|
|
|
func userViewFromModel(user *usr_model.UserView) *UserView {
|
|
|
|
creationDate, err := ptypes.TimestampProto(user.CreationDate)
|
|
|
|
logging.Log("GRPC-dl9we").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(user.ChangeDate)
|
|
|
|
logging.Log("GRPC-lpsg5").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
lastLogin, err := ptypes.TimestampProto(user.LastLogin)
|
|
|
|
logging.Log("GRPC-dksi3").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
passwordChanged, err := ptypes.TimestampProto(user.PasswordChanged)
|
|
|
|
logging.Log("GRPC-dl9ws").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &UserView{
|
2020-06-17 05:25:04 +00:00
|
|
|
Id: user.ID,
|
|
|
|
State: userStateFromModel(user.State),
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
LastLogin: lastLogin,
|
|
|
|
PasswordChanged: passwordChanged,
|
|
|
|
UserName: user.UserName,
|
|
|
|
FirstName: user.FirstName,
|
|
|
|
LastName: user.LastName,
|
2020-06-17 14:43:53 +00:00
|
|
|
DisplayName: user.DisplayName,
|
2020-06-17 05:25:04 +00:00
|
|
|
NickName: user.NickName,
|
2020-06-17 14:43:53 +00:00
|
|
|
PreferredLanguage: user.PreferredLanguage,
|
|
|
|
Gender: genderFromModel(user.Gender),
|
2020-06-17 05:25:04 +00:00
|
|
|
Email: user.Email,
|
|
|
|
IsEmailVerified: user.IsEmailVerified,
|
|
|
|
Phone: user.Phone,
|
|
|
|
IsPhoneVerified: user.IsPhoneVerified,
|
|
|
|
Country: user.Country,
|
|
|
|
Locality: user.Locality,
|
|
|
|
PostalCode: user.PostalCode,
|
2020-06-17 14:43:53 +00:00
|
|
|
Region: user.Region,
|
2020-06-17 05:25:04 +00:00
|
|
|
StreetAddress: user.StreetAddress,
|
2020-06-17 14:43:53 +00:00
|
|
|
Sequence: user.Sequence,
|
|
|
|
ResourceOwner: user.ResourceOwner,
|
2020-06-17 05:25:04 +00:00
|
|
|
LoginNames: user.LoginNames,
|
|
|
|
PreferredLoginName: user.PreferredLoginName,
|
2020-05-12 04:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func mfasFromModel(mfas []*usr_model.MultiFactor) []*MultiFactor {
|
|
|
|
converted := make([]*MultiFactor, len(mfas))
|
|
|
|
for i, mfa := range mfas {
|
|
|
|
converted[i] = mfaFromModel(mfa)
|
|
|
|
}
|
|
|
|
return converted
|
|
|
|
}
|
|
|
|
|
|
|
|
func mfaFromModel(mfa *usr_model.MultiFactor) *MultiFactor {
|
|
|
|
return &MultiFactor{
|
|
|
|
State: mfaStateFromModel(mfa.State),
|
|
|
|
Type: mfaTypeFromModel(mfa.Type),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:16:27 +00:00
|
|
|
func notifyTypeToModel(state NotificationType) usr_model.NotificationType {
|
|
|
|
switch state {
|
|
|
|
case NotificationType_NOTIFICATIONTYPE_EMAIL:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.NotificationTypeEmail
|
2020-05-11 08:16:27 +00:00
|
|
|
case NotificationType_NOTIFICATIONTYPE_SMS:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.NotificationTypeSms
|
2020-05-11 08:16:27 +00:00
|
|
|
default:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.NotificationTypeEmail
|
2020-05-11 08:16:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func userStateFromModel(state usr_model.UserState) UserState {
|
|
|
|
switch state {
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.UserStateActive:
|
2020-05-11 08:16:27 +00:00
|
|
|
return UserState_USERSTATE_ACTIVE
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.UserStateInactive:
|
2020-05-11 08:16:27 +00:00
|
|
|
return UserState_USERSTATE_INACTIVE
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.UserStateLocked:
|
2020-05-11 08:16:27 +00:00
|
|
|
return UserState_USERSTATE_LOCKED
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.UserStateInitial:
|
2020-06-11 11:27:25 +00:00
|
|
|
return UserState_USERSTATE_INITIAL
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.UserStateSuspend:
|
2020-06-11 11:27:25 +00:00
|
|
|
return UserState_USERSTATE_SUSPEND
|
2020-05-11 08:16:27 +00:00
|
|
|
default:
|
|
|
|
return UserState_USERSTATE_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func genderFromModel(gender usr_model.Gender) Gender {
|
|
|
|
switch gender {
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.GenderFemale:
|
2020-05-11 08:16:27 +00:00
|
|
|
return Gender_GENDER_FEMALE
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.GenderMale:
|
2020-05-11 08:16:27 +00:00
|
|
|
return Gender_GENDER_MALE
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.GenderDiverse:
|
2020-05-11 08:16:27 +00:00
|
|
|
return Gender_GENDER_DIVERSE
|
|
|
|
default:
|
|
|
|
return Gender_GENDER_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func genderToModel(gender Gender) usr_model.Gender {
|
|
|
|
switch gender {
|
|
|
|
case Gender_GENDER_FEMALE:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.GenderFemale
|
2020-05-11 08:16:27 +00:00
|
|
|
case Gender_GENDER_MALE:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.GenderMale
|
2020-05-11 08:16:27 +00:00
|
|
|
case Gender_GENDER_DIVERSE:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.GenderDiverse
|
2020-05-11 08:16:27 +00:00
|
|
|
default:
|
2020-06-23 12:47:47 +00:00
|
|
|
return usr_model.GenderUnspecified
|
2020-05-11 08:16:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-12 04:30:53 +00:00
|
|
|
|
2020-06-23 12:47:47 +00:00
|
|
|
func mfaTypeFromModel(mfatype usr_model.MfaType) MfaType {
|
2020-05-12 04:30:53 +00:00
|
|
|
switch mfatype {
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.MfaTypeOTP:
|
2020-05-12 04:30:53 +00:00
|
|
|
return MfaType_MFATYPE_OTP
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.MfaTypeSMS:
|
2020-05-12 04:30:53 +00:00
|
|
|
return MfaType_MFATYPE_SMS
|
|
|
|
default:
|
|
|
|
return MfaType_MFATYPE_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func mfaStateFromModel(state usr_model.MfaState) MFAState {
|
|
|
|
switch state {
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.MfaStateReady:
|
2020-05-12 04:30:53 +00:00
|
|
|
return MFAState_MFASTATE_READY
|
2020-06-23 12:47:47 +00:00
|
|
|
case usr_model.MfaStateNotReady:
|
2020-05-12 04:30:53 +00:00
|
|
|
return MFAState_MFASTATE_NOT_READY
|
|
|
|
default:
|
|
|
|
return MFAState_MFASTATE_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 14:50:09 +00:00
|
|
|
|
|
|
|
func userChangesToResponse(response *usr_model.UserChanges, offset uint64, limit uint64) (_ *Changes) {
|
|
|
|
return &Changes{
|
|
|
|
Limit: limit,
|
|
|
|
Offset: offset,
|
|
|
|
Changes: userChangesToMgtAPI(response),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func userChangesToMgtAPI(changes *usr_model.UserChanges) (_ []*Change) {
|
|
|
|
result := make([]*Change, len(changes.Changes))
|
|
|
|
|
|
|
|
for i, change := range changes.Changes {
|
2020-07-01 05:18:05 +00:00
|
|
|
var data *structpb.Struct
|
|
|
|
changedData, err := json.Marshal(change.Data)
|
|
|
|
if err == nil {
|
|
|
|
data = new(structpb.Struct)
|
|
|
|
err = protojson.Unmarshal(changedData, data)
|
|
|
|
logging.Log("GRPC-a7F54").OnError(err).Debug("unable to marshal changed data to struct")
|
2020-06-15 14:50:09 +00:00
|
|
|
}
|
2020-07-01 05:18:05 +00:00
|
|
|
|
2020-06-15 14:50:09 +00:00
|
|
|
result[i] = &Change{
|
|
|
|
ChangeDate: change.ChangeDate,
|
2020-07-08 07:48:11 +00:00
|
|
|
EventType: message.NewLocalizedEventType(change.EventType),
|
2020-06-15 14:50:09 +00:00
|
|
|
Sequence: change.Sequence,
|
|
|
|
Data: data,
|
2020-06-29 07:37:10 +00:00
|
|
|
EditorId: change.ModifierId,
|
|
|
|
Editor: change.ModifierName,
|
2020-06-15 14:50:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|