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
This commit is contained in:
Stefan Benz 2022-12-01 12:31:46 +00:00 committed by GitHub
parent 9fbd1034c2
commit 9626897834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 88 additions and 32 deletions

View File

@ -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)

View File

@ -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),

View File

@ -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)

View File

@ -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,
}
}

View File

@ -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)
}

View File

@ -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 = ""

View File

@ -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",

View File

@ -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",

View File

@ -334,7 +334,7 @@ type CustomLoginText struct {
ExternalRegistrationUserOverview ExternalRegistrationUserOverviewScreenText
RegistrationOrg RegistrationOrgScreenText
LinkingUsersDone LinkingUserDoneScreenText
ExternalNotFoundOption ExternalUserNotFoundScreenText
ExternalNotFound ExternalUserNotFoundScreenText
LoginSuccess SuccessLoginScreenText
LogoutDone LogoutDoneScreenText
Footer FooterText

View File

@ -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
}
}