From bed5bfc672e0ff66a267fb8274c330bb753925a2 Mon Sep 17 00:00:00 2001
From: Alexander Polyankin <alexander.polyankin@metabase.com>
Date: Wed, 13 Jul 2022 18:41:54 +0300
Subject: [PATCH] Migrate whitelabel settings that were dependent on custom
 colors (#23890)

---
 .../metabase-enterprise/whitelabel/index.js   |  1 +
 src/metabase/public_settings.clj              | 44 +++++++++++++------
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/enterprise/frontend/src/metabase-enterprise/whitelabel/index.js b/enterprise/frontend/src/metabase-enterprise/whitelabel/index.js
index d8c49018562..4b2008850aa 100644
--- a/enterprise/frontend/src/metabase-enterprise/whitelabel/index.js
+++ b/enterprise/frontend/src/metabase-enterprise/whitelabel/index.js
@@ -89,6 +89,7 @@ if (hasPremiumFeature("whitelabel")) {
           key: "show-lighthouse-illustration",
           display_name: t`Lighthouse illustration`,
           type: "boolean",
+          defaultValue: true,
         },
       ],
     },
diff --git a/src/metabase/public_settings.clj b/src/metabase/public_settings.clj
index f65bff07db1..610f9e7140c 100644
--- a/src/metabase/public_settings.clj
+++ b/src/metabase/public_settings.clj
@@ -289,13 +289,6 @@
   :type       :keyword
   :default    :doing-science)
 
-(defsetting show-metabot
-  (deferred-tru "Enables Metabot character on the home page")
-  :visibility :public
-  :type       :boolean
-  :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
@@ -366,6 +359,36 @@
   :enabled?   premium-features/enable-whitelabeling?
   :default    "app/assets/img/favicon.ico")
 
+(defn has-custom-branding?
+  "Whether this instance has custom colors or logo set."
+  []
+  (or (not-empty (application-colors))
+      (not= (application-logo-url) "app/assets/img/logo.svg")))
+
+(defsetting show-metabot
+  (deferred-tru "Enables Metabot character on the home page")
+  :visibility :public
+  :type       :boolean
+  :enabled?   premium-features/enable-whitelabeling?
+  :getter     (fn []
+                (if-some [value (setting/get-value-of-type :boolean :show-metabot)]
+                  value
+                  (let [new-value (not (has-custom-branding?))]
+                    (setting/set-value-of-type! :boolean :show-metabot new-value)
+                    new-value))))
+
+(defsetting show-lighthouse-illustration
+  (deferred-tru "Display the lighthouse illustration on the home and login pages.")
+  :visibility :public
+  :type       :boolean
+  :enabled?   premium-features/enable-whitelabeling?
+  :getter     (fn []
+                (if-some [value (setting/get-value-of-type :boolean :show-lighthouse-illustration)]
+                  value
+                  (let [new-value (not (has-custom-branding?))]
+                    (setting/set-value-of-type! :boolean :show-lighthouse-illustration new-value)
+                    new-value))))
+
 (defsetting enable-password-login
   (deferred-tru "Allow logging in by email and password.")
   :visibility :public
@@ -430,13 +453,6 @@
   :default    true
   :visibility :authenticated)
 
-(defsetting show-lighthouse-illustration
-  (deferred-tru "Display the lighthouse illustration on the home and login pages.")
-  :visibility :public
-  :type       :boolean
-  :enabled?   premium-features/enable-whitelabeling?
-  :default    true)
-
 (defsetting source-address-header
   (deferred-tru "Identify the source of HTTP requests by this header's value, instead of its remote address.")
   :default "X-Forwarded-For"
-- 
GitLab