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

fix update and reset the logo #8211

Merged
merged 1 commit into from
Jan 16, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-upload-reset-logo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Updating and reset logo failed

We fixed a bug when admin tried to update or reset the logo.

https://github.com/owncloud/ocis/pull/8211
https://github.com/owncloud/ocis/issues/8101
29 changes: 16 additions & 13 deletions services/web/pkg/service/v0/branding.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,7 @@ func (p Web) getLogoPath(r io.Reader) (string, error) {
var m map[string]interface{}
_ = json.NewDecoder(r).Decode(&m)

webCfg, ok := m["clients"].(map[string]interface{})["web"].(map[string]interface{})
if !ok {
return "", errInvalidThemeConfig
}

logoCfg, ok := webCfg["defaults"].(map[string]interface{})["logo"].(map[string]interface{})
logoCfg, ok := extractMap(m, "clients", "web", "defaults", "logo")
if !ok {
return "", errInvalidThemeConfig
}
Expand All @@ -175,18 +170,13 @@ func (p Web) updateLogoThemeConfig(logoPath string) error {
_ = json.NewDecoder(f).Decode(&m)

// change logo in common part
commonCfg, ok := m["common"].(map[string]interface{})
commonCfg, ok := extractMap(m, "common")
if !ok {
return errInvalidThemeConfig
}
commonCfg["logo"] = logoPath

webCfg, ok := m["clients"].(map[string]interface{})["web"].(map[string]interface{})
if !ok {
return errInvalidThemeConfig
}

logoCfg, ok := webCfg["defaults"].(map[string]interface{})["logo"].(map[string]interface{})
logoCfg, ok := extractMap(m, "clients", "web", "defaults", "logo")
if !ok {
return errInvalidThemeConfig
}
Expand All @@ -209,3 +199,16 @@ func allowedFiletype(filename, mediatype string) bool {
mt, ok := _allowedExtensionMediatypes[ext]
return ok && mt == mediatype
}

// extractMap extracts embedded map[string]interface{} by the keys chain
func extractMap(data map[string]interface{}, keys ...string) (map[string]interface{}, bool) {
last := data
var ok bool
for _, key := range keys {
last, ok = last[key].(map[string]interface{})
if !ok {
return nil, false
}
}
return last, true
}