From 9626897834c152653a116342b4091197c6293dab Mon Sep 17 00:00:00 2001 From: Stefan Benz <46600784+stebenz@users.noreply.github.com> Date: Thu, 1 Dec 2022 12:31:46 +0000 Subject: [PATCH] fix(logintexts): fix several custom text attributes for get and set (#4733) * fix(logintexts): fix several custom text attributes for get and set * fix(logintexts): fix externalUserNotFound attribute for json unmarshalling and reduce for customTexts * fix: correct imports for linting --- .../api/grpc/admin/custom_text_converter.go | 2 +- internal/api/grpc/admin/export.go | 2 +- .../grpc/management/custom_text_converter.go | 3 +- internal/api/grpc/text/custom_text.go | 3 +- internal/command/custom_login_text.go | 18 ++--- internal/command/custom_message_text_model.go | 4 +- .../instance_custom_login_text_test.go | 8 +-- .../command/org_custom_login_text_test.go | 6 +- internal/domain/custom_login_text.go | 2 +- internal/query/custom_text.go | 72 ++++++++++++++++--- 10 files changed, 88 insertions(+), 32 deletions(-) diff --git a/internal/api/grpc/admin/custom_text_converter.go b/internal/api/grpc/admin/custom_text_converter.go index ed9775f391..3622243765 100644 --- a/internal/api/grpc/admin/custom_text_converter.go +++ b/internal/api/grpc/admin/custom_text_converter.go @@ -134,7 +134,7 @@ func SetLoginTextToDomain(req *admin_pb.SetCustomLoginTextsRequest) *domain.Cust result.ExternalRegistrationUserOverview = text.ExternalRegistrationUserOverviewScreenTextPbToDomain(req.ExternalRegistrationUserOverviewText) result.RegistrationOrg = text.RegistrationOrgScreenTextPbToDomain(req.RegistrationOrgText) result.LinkingUsersDone = text.LinkingUserDoneScreenTextPbToDomain(req.LinkingUserDoneText) - result.ExternalNotFoundOption = text.ExternalUserNotFoundScreenTextPbToDomain(req.ExternalUserNotFoundText) + result.ExternalNotFound = text.ExternalUserNotFoundScreenTextPbToDomain(req.ExternalUserNotFoundText) result.LoginSuccess = text.SuccessLoginScreenTextPbToDomain(req.SuccessLoginText) result.LogoutDone = text.LogoutDoneScreenTextPbToDomain(req.LogoutText) result.Footer = text.FooterTextPbToDomain(req.FooterText) diff --git a/internal/api/grpc/admin/export.go b/internal/api/grpc/admin/export.go index 784bd05c2b..70ec2ca578 100644 --- a/internal/api/grpc/admin/export.go +++ b/internal/api/grpc/admin/export.go @@ -1047,7 +1047,7 @@ func (s *Server) getCustomLoginTexts(ctx context.Context, org string, languages ExternalRegistrationUserOverviewText: text_grpc.ExternalRegistrationUserOverviewScreenTextToPb(text.ExternalRegistrationUserOverview), RegistrationOrgText: text_grpc.RegistrationOrgScreenTextToPb(text.RegistrationOrg), LinkingUserDoneText: text_grpc.LinkingUserDoneScreenTextToPb(text.LinkingUsersDone), - ExternalUserNotFoundText: text_grpc.ExternalUserNotFoundScreenTextToPb(text.ExternalNotFoundOption), + ExternalUserNotFoundText: text_grpc.ExternalUserNotFoundScreenTextToPb(text.ExternalNotFound), SuccessLoginText: text_grpc.SuccessLoginScreenTextToPb(text.LoginSuccess), LogoutText: text_grpc.LogoutDoneScreenTextToPb(text.LogoutDone), FooterText: text_grpc.FooterTextToPb(text.Footer), diff --git a/internal/api/grpc/management/custom_text_converter.go b/internal/api/grpc/management/custom_text_converter.go index 705d9007bc..4ff3b389bc 100644 --- a/internal/api/grpc/management/custom_text_converter.go +++ b/internal/api/grpc/management/custom_text_converter.go @@ -122,6 +122,7 @@ func SetLoginCustomTextToDomain(req *mgmt_pb.SetCustomLoginTextsRequest) *domain result.VerifyMFAOTP = text.VerifyMFAOTPScreenTextPbToDomain(req.VerifyMfaOtpText) result.VerifyMFAU2F = text.VerifyMFAU2FScreenTextPbToDomain(req.VerifyMfaU2FText) result.Passwordless = text.PasswordlessScreenTextPbToDomain(req.PasswordlessText) + result.PasswordlessPrompt = text.PasswordlessPromptScreenTextPbToDomain(req.PasswordlessPromptText) result.PasswordlessRegistration = text.PasswordlessRegistrationScreenTextPbToDomain(req.PasswordlessRegistrationText) result.PasswordlessRegistrationDone = text.PasswordlessRegistrationDoneScreenTextPbToDomain(req.PasswordlessRegistrationDoneText) result.PasswordChange = text.PasswordChangeScreenTextPbToDomain(req.PasswordChangeText) @@ -132,7 +133,7 @@ func SetLoginCustomTextToDomain(req *mgmt_pb.SetCustomLoginTextsRequest) *domain result.ExternalRegistrationUserOverview = text.ExternalRegistrationUserOverviewScreenTextPbToDomain(req.ExternalRegistrationUserOverviewText) result.RegistrationOrg = text.RegistrationOrgScreenTextPbToDomain(req.RegistrationOrgText) result.LinkingUsersDone = text.LinkingUserDoneScreenTextPbToDomain(req.LinkingUserDoneText) - result.ExternalNotFoundOption = text.ExternalUserNotFoundScreenTextPbToDomain(req.ExternalUserNotFoundText) + result.ExternalNotFound = text.ExternalUserNotFoundScreenTextPbToDomain(req.ExternalUserNotFoundText) result.LoginSuccess = text.SuccessLoginScreenTextPbToDomain(req.SuccessLoginText) result.LogoutDone = text.LogoutDoneScreenTextPbToDomain(req.LogoutText) result.Footer = text.FooterTextPbToDomain(req.FooterText) diff --git a/internal/api/grpc/text/custom_text.go b/internal/api/grpc/text/custom_text.go index ad4d4ae975..f57d6c0394 100644 --- a/internal/api/grpc/text/custom_text.go +++ b/internal/api/grpc/text/custom_text.go @@ -65,7 +65,7 @@ func CustomLoginTextToPb(text *domain.CustomLoginText) *text_pb.LoginCustomText ExternalRegistrationUserOverviewText: ExternalRegistrationUserOverviewScreenTextToPb(text.ExternalRegistrationUserOverview), RegistrationOrgText: RegistrationOrgScreenTextToPb(text.RegistrationOrg), LinkingUserDoneText: LinkingUserDoneScreenTextToPb(text.LinkingUsersDone), - ExternalUserNotFoundText: ExternalUserNotFoundScreenTextToPb(text.ExternalNotFoundOption), + ExternalUserNotFoundText: ExternalUserNotFoundScreenTextToPb(text.ExternalNotFound), SuccessLoginText: SuccessLoginScreenTextToPb(text.LoginSuccess), LogoutText: LogoutDoneScreenTextToPb(text.LogoutDone), FooterText: FooterTextToPb(text.Footer), @@ -761,6 +761,7 @@ func PasswordlessRegistrationDoneScreenTextPbToDomain(text *text_pb.Passwordless Description: text.Description, DescriptionClose: text.DescriptionClose, NextButtonText: text.NextButtonText, + CancelButtonText: text.CancelButtonText, } } diff --git a/internal/command/custom_login_text.go b/internal/command/custom_login_text.go index b4fd4910ae..e433e2c5f0 100644 --- a/internal/command/custom_login_text.go +++ b/internal/command/custom_login_text.go @@ -998,39 +998,39 @@ func (c *Commands) createLinkingUserEvents(ctx context.Context, agg *eventstore. func (c *Commands) createExternalUserNotFoundEvents(ctx context.Context, agg *eventstore.Aggregate, existingText *CustomLoginTextReadModel, text *domain.CustomLoginText, defaultText bool) []eventstore.Command { events := make([]eventstore.Command, 0) - event := c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTitle, existingText.ExternalUserNotFoundTitle, text.ExternalNotFoundOption.Title, text.Language, defaultText) + event := c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTitle, existingText.ExternalUserNotFoundTitle, text.ExternalNotFound.Title, text.Language, defaultText) if event != nil { events = append(events, event) } - event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundDescription, existingText.ExternalUserNotFoundDescription, text.ExternalNotFoundOption.Description, text.Language, defaultText) + event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundDescription, existingText.ExternalUserNotFoundDescription, text.ExternalNotFound.Description, text.Language, defaultText) if event != nil { events = append(events, event) } - event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundLinkButtonText, existingText.ExternalUserNotFoundLinkButtonText, text.ExternalNotFoundOption.LinkButtonText, text.Language, defaultText) + event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundLinkButtonText, existingText.ExternalUserNotFoundLinkButtonText, text.ExternalNotFound.LinkButtonText, text.Language, defaultText) if event != nil { events = append(events, event) } - event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundAutoRegisterButtonText, existingText.ExternalUserNotFoundAutoRegisterButtonText, text.ExternalNotFoundOption.AutoRegisterButtonText, text.Language, defaultText) + event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundAutoRegisterButtonText, existingText.ExternalUserNotFoundAutoRegisterButtonText, text.ExternalNotFound.AutoRegisterButtonText, text.Language, defaultText) if event != nil { events = append(events, event) } - event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTOSAndPrivacyLabel, existingText.ExternalUserNotFoundTOSAndPrivacyLabel, text.ExternalNotFoundOption.TOSAndPrivacyLabel, text.Language, defaultText) + event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTOSAndPrivacyLabel, existingText.ExternalUserNotFoundTOSAndPrivacyLabel, text.ExternalNotFound.TOSAndPrivacyLabel, text.Language, defaultText) if event != nil { events = append(events, event) } - event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTOSConfirm, existingText.ExternalUserNotFoundTOSConfirm, text.ExternalNotFoundOption.TOSConfirm, text.Language, defaultText) + event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTOSConfirm, existingText.ExternalUserNotFoundTOSConfirm, text.ExternalNotFound.TOSConfirm, text.Language, defaultText) if event != nil { events = append(events, event) } - event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTOSLinkText, existingText.ExternalUserNotFoundTOSLinkText, text.ExternalNotFoundOption.TOSLinkText, text.Language, defaultText) + event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTOSLinkText, existingText.ExternalUserNotFoundTOSLinkText, text.ExternalNotFound.TOSLinkText, text.Language, defaultText) if event != nil { events = append(events, event) } - event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTOSConfirmAnd, existingText.ExternalUserNotFoundTOSConfirmAnd, text.ExternalNotFoundOption.TOSConfirmAnd, text.Language, defaultText) + event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundTOSConfirmAnd, existingText.ExternalUserNotFoundTOSConfirmAnd, text.ExternalNotFound.TOSConfirmAnd, text.Language, defaultText) if event != nil { events = append(events, event) } - event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundPrivacyLinkText, existingText.ExternalUserNotFoundPrivacyLinkText, text.ExternalNotFoundOption.PrivacyLinkText, text.Language, defaultText) + event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyExternalNotFoundPrivacyLinkText, existingText.ExternalUserNotFoundPrivacyLinkText, text.ExternalNotFound.PrivacyLinkText, text.Language, defaultText) if event != nil { events = append(events, event) } diff --git a/internal/command/custom_message_text_model.go b/internal/command/custom_message_text_model.go index e3a3211faf..bac931b476 100644 --- a/internal/command/custom_message_text_model.go +++ b/internal/command/custom_message_text_model.go @@ -54,7 +54,7 @@ func (wm *CustomMessageTextReadModel) Reduce() error { } wm.State = domain.PolicyStateActive case *policy.CustomTextRemovedEvent: - if e.Key != wm.MessageTextType || wm.Language != e.Language { + if e.Template != wm.MessageTextType || wm.Language != e.Language { continue } if e.Key == domain.MessageSubject { @@ -79,7 +79,7 @@ func (wm *CustomMessageTextReadModel) Reduce() error { wm.FooterText = "" } case *policy.CustomTextTemplateRemovedEvent: - if wm.Language != e.Language { + if e.Template != wm.MessageTextType || wm.Language != e.Language { continue } wm.Subject = "" diff --git a/internal/command/instance_custom_login_text_test.go b/internal/command/instance_custom_login_text_test.go index d3a12c6893..4b97283e86 100644 --- a/internal/command/instance_custom_login_text_test.go +++ b/internal/command/instance_custom_login_text_test.go @@ -5,9 +5,9 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/zitadel/zitadel/internal/api/authz" "golang.org/x/text/language" + "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/domain" caos_errs "github.com/zitadel/zitadel/internal/errors" "github.com/zitadel/zitadel/internal/eventstore" @@ -1631,7 +1631,7 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) { CancelButtonText: "CancelButtonText", NextButtonText: "NextButtonText", }, - ExternalNotFoundOption: domain.ExternalUserNotFoundScreenText{ + ExternalNotFound: domain.ExternalUserNotFoundScreenText{ Title: "Title", Description: "Description", LinkButtonText: "LinkButtonText", @@ -4329,7 +4329,7 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) { ExternalRegistrationUserOverview: domain.ExternalRegistrationUserOverviewScreenText{}, RegistrationOrg: domain.RegistrationOrgScreenText{}, LinkingUsersDone: domain.LinkingUserDoneScreenText{}, - ExternalNotFoundOption: domain.ExternalUserNotFoundScreenText{}, + ExternalNotFound: domain.ExternalUserNotFoundScreenText{}, LoginSuccess: domain.SuccessLoginScreenText{}, LogoutDone: domain.LogoutDoneScreenText{}, Footer: domain.FooterText{}, @@ -8543,7 +8543,7 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) { CancelButtonText: "CancelButtonText", NextButtonText: "NextButtonText", }, - ExternalNotFoundOption: domain.ExternalUserNotFoundScreenText{ + ExternalNotFound: domain.ExternalUserNotFoundScreenText{ Title: "Title", Description: "Description", LinkButtonText: "LinkButtonText", diff --git a/internal/command/org_custom_login_text_test.go b/internal/command/org_custom_login_text_test.go index 0d225e70cb..132b16ca07 100644 --- a/internal/command/org_custom_login_text_test.go +++ b/internal/command/org_custom_login_text_test.go @@ -1429,7 +1429,7 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) { CancelButtonText: "CancelButtonText", NextButtonText: "NextButtonText", }, - ExternalNotFoundOption: domain.ExternalUserNotFoundScreenText{ + ExternalNotFound: domain.ExternalUserNotFoundScreenText{ Title: "Title", Description: "Description", LinkButtonText: "LinkButtonText", @@ -3692,7 +3692,7 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) { RegistrationUser: domain.RegistrationUserScreenText{}, RegistrationOrg: domain.RegistrationOrgScreenText{}, LinkingUsersDone: domain.LinkingUserDoneScreenText{}, - ExternalNotFoundOption: domain.ExternalUserNotFoundScreenText{}, + ExternalNotFound: domain.ExternalUserNotFoundScreenText{}, LoginSuccess: domain.SuccessLoginScreenText{}, LogoutDone: domain.LogoutDoneScreenText{}, Footer: domain.FooterText{}, @@ -7251,7 +7251,7 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) { CancelButtonText: "CancelButtonText", NextButtonText: "NextButtonText", }, - ExternalNotFoundOption: domain.ExternalUserNotFoundScreenText{ + ExternalNotFound: domain.ExternalUserNotFoundScreenText{ Title: "Title", Description: "Description", LinkButtonText: "LinkButtonText", diff --git a/internal/domain/custom_login_text.go b/internal/domain/custom_login_text.go index e60cca8eb0..258c704f16 100644 --- a/internal/domain/custom_login_text.go +++ b/internal/domain/custom_login_text.go @@ -334,7 +334,7 @@ type CustomLoginText struct { ExternalRegistrationUserOverview ExternalRegistrationUserOverviewScreenText RegistrationOrg RegistrationOrgScreenText LinkingUsersDone LinkingUserDoneScreenText - ExternalNotFoundOption ExternalUserNotFoundScreenText + ExternalNotFound ExternalUserNotFoundScreenText LoginSuccess SuccessLoginScreenText LogoutDone LogoutDoneScreenText Footer FooterText diff --git a/internal/query/custom_text.go b/internal/query/custom_text.go index 4511d70ebd..8b6be3bda1 100644 --- a/internal/query/custom_text.go +++ b/internal/query/custom_text.go @@ -400,6 +400,9 @@ func CustomTextsToLoginDomain(instanceID, aggregateID, lang string, texts *Custo if strings.HasPrefix(text.Key, domain.LoginKeyRegistrationUser) { registrationUserKeyToDomain(text, result) } + if strings.HasPrefix(text.Key, domain.LoginKeyExternalRegistrationUserOverview) { + externalRegistrationUserKeyToDomain(text, result) + } if strings.HasPrefix(text.Key, domain.LoginKeyRegistrationOrg) { registrationOrgKeyToDomain(text, result) } @@ -938,6 +941,57 @@ func registrationOptionKeyToDomain(text *CustomText, result *domain.CustomLoginT } } +func externalRegistrationUserKeyToDomain(text *CustomText, result *domain.CustomLoginText) { + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewBackButtonText { + result.ExternalRegistrationUserOverview.BackButtonText = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewDescription { + result.ExternalRegistrationUserOverview.Description = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewEmailLabel { + result.ExternalRegistrationUserOverview.EmailLabel = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewFirstnameLabel { + result.ExternalRegistrationUserOverview.FirstnameLabel = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewLanguageLabel { + result.ExternalRegistrationUserOverview.LanguageLabel = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewLastnameLabel { + result.ExternalRegistrationUserOverview.LastnameLabel = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewNextButtonText { + result.ExternalRegistrationUserOverview.NextButtonText = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewNicknameLabel { + result.ExternalRegistrationUserOverview.NicknameLabel = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewPhoneLabel { + result.ExternalRegistrationUserOverview.PhoneLabel = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewPrivacyLinkText { + result.ExternalRegistrationUserOverview.PrivacyLinkText = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewTitle { + result.ExternalRegistrationUserOverview.Title = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewTOSAndPrivacyLabel { + result.ExternalRegistrationUserOverview.TOSAndPrivacyLabel = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewTOSConfirm { + result.ExternalRegistrationUserOverview.TOSConfirm = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewTOSConfirmAnd { + result.ExternalRegistrationUserOverview.TOSConfirmAnd = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewTOSLinkText { + result.ExternalRegistrationUserOverview.TOSLinkText = text.Text + } + if text.Key == domain.LoginKeyExternalRegistrationUserOverviewUsernameLabel { + result.ExternalRegistrationUserOverview.UsernameLabel = text.Text + } +} + func registrationUserKeyToDomain(text *CustomText, result *domain.CustomLoginText) { if text.Key == domain.LoginKeyRegistrationUserTitle { result.RegistrationUser.Title = text.Text @@ -1060,31 +1114,31 @@ func linkingUserKeyToDomain(text *CustomText, result *domain.CustomLoginText) { func externalUserNotFoundKeyToDomain(text *CustomText, result *domain.CustomLoginText) { if text.Key == domain.LoginKeyExternalNotFoundTitle { - result.ExternalNotFoundOption.Title = text.Text + result.ExternalNotFound.Title = text.Text } if text.Key == domain.LoginKeyExternalNotFoundDescription { - result.ExternalNotFoundOption.Description = text.Text + result.ExternalNotFound.Description = text.Text } if text.Key == domain.LoginKeyExternalNotFoundLinkButtonText { - result.ExternalNotFoundOption.LinkButtonText = text.Text + result.ExternalNotFound.LinkButtonText = text.Text } if text.Key == domain.LoginKeyExternalNotFoundAutoRegisterButtonText { - result.ExternalNotFoundOption.AutoRegisterButtonText = text.Text + result.ExternalNotFound.AutoRegisterButtonText = text.Text } if text.Key == domain.LoginKeyExternalNotFoundTOSAndPrivacyLabel { - result.ExternalNotFoundOption.TOSAndPrivacyLabel = text.Text + result.ExternalNotFound.TOSAndPrivacyLabel = text.Text } if text.Key == domain.LoginKeyExternalNotFoundTOSConfirm { - result.ExternalNotFoundOption.TOSConfirm = text.Text + result.ExternalNotFound.TOSConfirm = text.Text } if text.Key == domain.LoginKeyExternalNotFoundTOSLinkText { - result.ExternalNotFoundOption.TOSLinkText = text.Text + result.ExternalNotFound.TOSLinkText = text.Text } if text.Key == domain.LoginKeyExternalNotFoundTOSConfirmAnd { - result.ExternalNotFoundOption.TOSConfirmAnd = text.Text + result.ExternalNotFound.TOSConfirmAnd = text.Text } if text.Key == domain.LoginKeyExternalNotFoundPrivacyLinkText { - result.ExternalNotFoundOption.PrivacyLinkText = text.Text + result.ExternalNotFound.PrivacyLinkText = text.Text } }