Skip to content

Commit

Permalink
fix update and reset the logo
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Jan 16, 2024
1 parent 774816a commit d704640
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-upload-reset-logo.md
@@ -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
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
}

0 comments on commit d704640

Please sign in to comment.