Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXCDT-549: Add logic to save branding data that gets sent by the web app #872

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions internal/cli/universal_login_customize.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type (
Template *management.BrandingUniversalLogin `json:"template"`
Theme *management.BrandingTheme `json:"theme"`
Tenant *tenantData `json:"tenant"`
Prompt *promptData `json:"prompt"`
Prompts []*promptData `json:"prompts"`
}

tenantData struct {
Expand All @@ -43,9 +43,9 @@ type (
}

promptData struct {
Language string `json:"language"`
Prompt string `json:"prompt"`
CustomText map[string]map[string]interface{} `json:"custom_text,omitempty"`
Language string `json:"language"`
Prompt string `json:"prompt"`
CustomText map[string]interface{} `json:"custom_text,omitempty"`
}

webSocketHandler struct {
Expand Down Expand Up @@ -168,7 +168,7 @@ func fetchUniversalLoginBrandingData(
EnabledLocales: tenant.GetEnabledLocales(),
Domain: tenantDomain,
},
Prompt: prompt,
Prompts: []*promptData{prompt},
}, nil
}

Expand Down Expand Up @@ -269,10 +269,15 @@ func fetchPromptCustomTextWithDefaults(

brandingTextTranslations := mergeBrandingTextTranslations(defaultTranslations, customTranslations)

customText := make(map[string]interface{}, 0)
for key, value := range brandingTextTranslations {
customText[key] = value
}

return &promptData{
Language: language,
Prompt: promptName,
CustomText: brandingTextTranslations,
CustomText: customText,
}, nil
}

Expand Down Expand Up @@ -405,7 +410,16 @@ func (h *webSocketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
continue
}
case saveBrandingMessageType:
h.display.Warnf("not yet implemented")
var saveBrandingMsg universalLoginBrandingData
if err := json.Unmarshal(message.Payload, &saveBrandingMsg); err != nil {
h.display.Errorf("failed to unmarshal save branding data payload: %v", err)
continue
}

if err := saveUniversalLoginBrandingData(r.Context(), h.api, &saveBrandingMsg); err != nil {
h.display.Errorf("failed to save branding data: %v", err)
continue
}
}
}
}
Expand All @@ -423,3 +437,35 @@ func checkOriginFunc(r *http.Request) bool {

return originURL.String() == webAppURL
}

func saveUniversalLoginBrandingData(ctx context.Context, api *auth0.API, data *universalLoginBrandingData) error {
group, ctx := errgroup.WithContext(ctx)

group.Go(func() (err error) {
return api.Branding.Update(ctx, data.Settings)
})

group.Go(func() (err error) {
return api.Branding.SetUniversalLogin(ctx, data.Template)
})

group.Go(func() (err error) {
themeID := data.Theme.GetID()
if themeID != "" {
data.Theme.ID = nil
return api.BrandingTheme.Update(ctx, themeID, data.Theme)
}

return api.BrandingTheme.Create(ctx, data.Theme)
})

for _, prompt := range data.Prompts {
prompt := prompt

group.Go(func() (err error) {
return api.Prompt.SetCustomText(ctx, prompt.Prompt, prompt.Language, prompt.CustomText)
})
}

return group.Wait()
}
Loading
Loading