Skip to content
Snippets Groups Projects
Unverified Commit 4bfd682f authored by adam-james's avatar adam-james Committed by GitHub
Browse files

application-colors have new keys that may be added via the getter (#23493)

* application-colors have new keys that may be added via the getter

Some colors previously had multiple usage contexts. For example, `accent1` was used both in charts and other parts of
the summarize UI. Now, those notions are being separated, so `accent1` remains a valid key, and `summarize` is a new
valid key. To make sure behaviour remains the same for existing whitelabel users who may have set these keys, when
such a key exists, it is 'split' by the getter.

For example, if the existing application-colors json contains `accent1`, the getter will add a new key `summarize`
with the same value as `accent1`, but only if `accent1` already exists, otherwise it does nothing. This is also true
for keys `brand`, which adds `accent0`, and `accent7`, which adds `filter`

* Make application colors getter make change only once

* Premium feature flag for test
parent defd866e
No related branches found
No related tags found
No related merge requests found
(ns metabase-enterprise.public-settings-test
(:require [clojure.test :refer :all]
[metabase.public-settings :as public-settings]
[metabase.public-settings.premium-features-test :as premium-features-test]
[metabase.test.fixtures :as fixtures]
[metabase.test.util :as tu]))
......@@ -14,3 +15,54 @@
(public-settings/enable-password-login! false)
(is (= false
(public-settings/enable-password-login)))))
(deftest application-colors-adds-correct-keys
(testing "application-colors getter"
(premium-features-test/with-premium-features #{:whitelabel}
(tu/with-temporary-setting-values [application-colors {:brand "#f00"
:accent1 "#0f0"
:accent7 "#00f"}
application-colors-migrated false]
(testing "sets `accent0` to value `brand`, `summarize` to value `accent1`, and `filter` to `accent7`"
(is (= {:brand "#f00"
:accent0 "#f00"
:accent1 "#0f0"
:summarize "#0f0"
:accent7 "#00f"
:filter "#00f"}
(public-settings/application-colors)))
(testing "and sets `application-colors-migrated` to `true`"
(is (public-settings/application-colors-migrated)))))
(tu/with-temporary-setting-values [application-colors {:brand "#f00"
:accent1 "#0f0"
:accent7 "#00f"}
application-colors-migrated true]
(testing "returns the colors as-is if `application-colors-migrated` is `true`"
(is (= {:brand "#f00"
:accent1 "#0f0"
:accent7 "#00f"}
(public-settings/application-colors)))
(testing "and sets `application-colors-migrated` to `true`"
(is (public-settings/application-colors-migrated)))))
(tu/with-temporary-setting-values [application-colors-migrated false]
(testing "does not set `brand`, `accent1`, or `accent7` if they are not already part of the input"
(public-settings/application-colors! {:accent0 "#f00"
:summarize "#0f0"
:filter "#00f"})
(is (= #{:accent0 :summarize :filter}
(set (keys (public-settings/application-colors)))))))
(tu/with-temporary-setting-values [application-colors-migrated false]
(testing "respects given values if `accent0`, `summarize`, and `filter` keys are part of the input"
(public-settings/application-colors! {:brand "#f00"
:accent0 "#fa0a0a"
:accent1 "#0f0"
:summarize "#0afa0a"
:accent7 "#00f"
:filter "#0a0afa"})
(is (= {:brand "#f00"
:accent0 "#fa0a0a"
:accent1 "#0f0"
:summarize "#0afa0a"
:accent7 "#00f"
:filter "#0a0afa"}
(public-settings/application-colors))))))))
......@@ -301,6 +301,13 @@
:enabled? premium-features/enable-whitelabeling?
:default true)
(defsetting application-colors-migrated
"Stores whether the `application-colors` setting has been migrated to 0.44 expectations"
:visibility :internal
:type :boolean
:enabled? premium-features/enable-whitelabeling?
:default false)
(defsetting application-colors
(deferred-tru
(str "These are the primary colors used in charts and throughout Metabase. "
......@@ -308,7 +315,19 @@
:visibility :public
:type :json
:enabled? premium-features/enable-whitelabeling?
:default {})
:default {}
:getter (fn []
(let [current-colors (setting/get-value-of-type :json :application-colors)]
(if (application-colors-migrated)
current-colors
(let [{:keys [accent0 brand summarize accent1 filter accent7]} current-colors
new-colors (cond-> current-colors
(and brand (not accent0)) (assoc :accent0 brand)
(and accent1 (not summarize)) (assoc :summarize accent1)
(and accent7 (not filter)) (assoc :filter accent7))]
(setting/set-value-of-type! :json :application-colors new-colors)
(application-colors-migrated! true)
new-colors)))))
(defsetting application-font
(deferred-tru
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment