mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:37:31 +00:00
fix: make user creation errors helpful (#5382)
* fix: make user creation errors helpful * fix linting and unit testing errors * fix linting * make zitadel config reusable * fix human validations * translate ssr errors * make zitadel config reusable * cover more translations for ssr * handle email validation message centrally * fix unit tests * fix linting * align signatures * use more precise wording * handle phone validation message centrally * fix: return specific profile errors * docs: edit comments * fix unit tests --------- Co-authored-by: Silvan <silvan.reusser@gmail.com>
This commit is contained in:
@@ -342,7 +342,7 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
|
||||
handler.NewCol(HumanPreferredLanguageCol, &sql.NullString{String: e.PreferredLanguage.String(), Valid: !e.PreferredLanguage.IsRoot()}),
|
||||
handler.NewCol(HumanGenderCol, &sql.NullInt16{Int16: int16(e.Gender), Valid: e.Gender.Specified()}),
|
||||
handler.NewCol(HumanEmailCol, e.EmailAddress),
|
||||
handler.NewCol(HumanPhoneCol, &sql.NullString{String: e.PhoneNumber, Valid: e.PhoneNumber != ""}),
|
||||
handler.NewCol(HumanPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
@@ -351,7 +351,7 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
|
||||
handler.NewCol(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCol(NotifyLastEmailCol, e.EmailAddress),
|
||||
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: e.PhoneNumber, Valid: e.PhoneNumber != ""}),
|
||||
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
handler.NewCol(NotifyPasswordSetCol, e.Secret != nil),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
@@ -390,7 +390,7 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
|
||||
handler.NewCol(HumanPreferredLanguageCol, &sql.NullString{String: e.PreferredLanguage.String(), Valid: !e.PreferredLanguage.IsRoot()}),
|
||||
handler.NewCol(HumanGenderCol, &sql.NullInt16{Int16: int16(e.Gender), Valid: e.Gender.Specified()}),
|
||||
handler.NewCol(HumanEmailCol, e.EmailAddress),
|
||||
handler.NewCol(HumanPhoneCol, &sql.NullString{String: e.PhoneNumber, Valid: e.PhoneNumber != ""}),
|
||||
handler.NewCol(HumanPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
@@ -399,7 +399,7 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
|
||||
handler.NewCol(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCol(NotifyLastEmailCol, e.EmailAddress),
|
||||
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: e.PhoneNumber, Valid: e.PhoneNumber != ""}),
|
||||
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
handler.NewCol(NotifyPasswordSetCol, e.Secret != nil),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
@@ -660,7 +660,7 @@ func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handl
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: e.PhoneNumber, Valid: e.PhoneNumber != ""}),
|
||||
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
||||
@@ -786,7 +786,7 @@ func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handl
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(NotifyLastEmailCol, &sql.NullString{String: e.EmailAddress, Valid: e.EmailAddress != ""}),
|
||||
handler.NewCol(NotifyLastEmailCol, &sql.NullString{String: string(e.EmailAddress), Valid: e.EmailAddress != ""}),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
||||
|
@@ -75,7 +75,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
&sql.NullString{String: "display-name", Valid: true},
|
||||
&sql.NullString{String: "ch-DE", Valid: true},
|
||||
&sql.NullInt16{Int16: int16(domain.GenderFemale), Valid: true},
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
||||
},
|
||||
},
|
||||
@@ -84,7 +84,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
||||
false,
|
||||
},
|
||||
@@ -144,7 +144,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
&sql.NullString{String: "display-name", Valid: true},
|
||||
&sql.NullString{String: "ch-DE", Valid: true},
|
||||
&sql.NullInt16{Int16: int16(domain.GenderFemale), Valid: true},
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
||||
},
|
||||
},
|
||||
@@ -153,7 +153,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
||||
false,
|
||||
},
|
||||
@@ -208,7 +208,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
&sql.NullString{},
|
||||
&sql.NullString{String: "und", Valid: false},
|
||||
&sql.NullInt16{},
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{},
|
||||
},
|
||||
},
|
||||
@@ -217,7 +217,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "", Valid: false},
|
||||
false,
|
||||
},
|
||||
@@ -277,7 +277,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
&sql.NullString{String: "display-name", Valid: true},
|
||||
&sql.NullString{String: "ch-DE", Valid: true},
|
||||
&sql.NullInt16{Int16: int16(domain.GenderFemale), Valid: true},
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
||||
},
|
||||
},
|
||||
@@ -286,7 +286,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
||||
false,
|
||||
},
|
||||
@@ -346,7 +346,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
&sql.NullString{String: "display-name", Valid: true},
|
||||
&sql.NullString{String: "ch-DE", Valid: true},
|
||||
&sql.NullInt16{Int16: int16(domain.GenderFemale), Valid: true},
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
||||
},
|
||||
},
|
||||
@@ -355,7 +355,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
||||
false,
|
||||
},
|
||||
@@ -410,7 +410,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
&sql.NullString{},
|
||||
&sql.NullString{String: "und", Valid: false},
|
||||
&sql.NullInt16{},
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{},
|
||||
},
|
||||
},
|
||||
@@ -419,7 +419,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
&sql.NullString{String: "", Valid: false},
|
||||
false,
|
||||
},
|
||||
@@ -879,7 +879,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
{
|
||||
expectedStmt: "UPDATE projections.users8_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"+41 00 000 00 00",
|
||||
domain.PhoneNumber("+41 00 000 00 00"),
|
||||
false,
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -927,7 +927,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
{
|
||||
expectedStmt: "UPDATE projections.users8_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"+41 00 000 00 00",
|
||||
domain.PhoneNumber("+41 00 000 00 00"),
|
||||
false,
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -1157,7 +1157,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
{
|
||||
expectedStmt: "UPDATE projections.users8_humans SET (email, is_email_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
false,
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -1205,7 +1205,7 @@ func TestUserProjection_reduces(t *testing.T) {
|
||||
{
|
||||
expectedStmt: "UPDATE projections.users8_humans SET (email, is_email_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
"email@zitadel.com",
|
||||
domain.EmailAddress("email@zitadel.com"),
|
||||
false,
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
|
@@ -47,9 +47,9 @@ type Human struct {
|
||||
AvatarKey string
|
||||
PreferredLanguage language.Tag
|
||||
Gender domain.Gender
|
||||
Email string
|
||||
Email domain.EmailAddress
|
||||
IsEmailVerified bool
|
||||
Phone string
|
||||
Phone domain.PhoneNumber
|
||||
IsPhoneVerified bool
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ type Email struct {
|
||||
ChangeDate time.Time
|
||||
ResourceOwner string
|
||||
Sequence uint64
|
||||
Email string
|
||||
Email domain.EmailAddress
|
||||
IsVerified bool
|
||||
}
|
||||
|
||||
@@ -847,9 +847,9 @@ func prepareUserQuery(ctx context.Context, db prepareDatabase) (sq.SelectBuilder
|
||||
AvatarKey: avatarKey.String,
|
||||
PreferredLanguage: language.Make(preferredLanguage.String),
|
||||
Gender: domain.Gender(gender.Int32),
|
||||
Email: email.String,
|
||||
Email: domain.EmailAddress(email.String),
|
||||
IsEmailVerified: isEmailVerified.Bool,
|
||||
Phone: phone.String,
|
||||
Phone: domain.PhoneNumber(phone.String),
|
||||
IsPhoneVerified: isPhoneVerified.Bool,
|
||||
}
|
||||
} else if machineID.Valid {
|
||||
@@ -970,7 +970,7 @@ func prepareEmailQuery(ctx context.Context, db prepareDatabase) (sq.SelectBuilde
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "QUERY-pt7HY", "Errors.User.NotHuman")
|
||||
}
|
||||
|
||||
e.Email = email.String
|
||||
e.Email = domain.EmailAddress(email.String)
|
||||
e.IsVerified = isEmailVerified.Bool
|
||||
|
||||
return e, nil
|
||||
@@ -1318,9 +1318,9 @@ func prepareUsersQuery(ctx context.Context, db prepareDatabase) (sq.SelectBuilde
|
||||
AvatarKey: avatarKey.String,
|
||||
PreferredLanguage: language.Make(preferredLanguage.String),
|
||||
Gender: domain.Gender(gender.Int32),
|
||||
Email: email.String,
|
||||
Email: domain.EmailAddress(email.String),
|
||||
IsEmailVerified: isEmailVerified.Bool,
|
||||
Phone: phone.String,
|
||||
Phone: domain.PhoneNumber(phone.String),
|
||||
IsPhoneVerified: isPhoneVerified.Bool,
|
||||
}
|
||||
} else if machineID.Valid {
|
||||
|
Reference in New Issue
Block a user