From d39a6d4fe5f0f71df1889b29364cf75789c28322 Mon Sep 17 00:00:00 2001
From: Ngoc Khuat <qn.khuat@gmail.com>
Date: Tue, 11 Jul 2023 12:31:13 +0700
Subject: [PATCH] Expose new feature flags (#32250)

* expose new feature flags: :official_collections, :snippets_collections, :disable_password_login
---
 .../metabase_enterprise/api/session_test.clj  | 35 +++++++++++++++++++
 .../metabase_enterprise/api/session_test.lcj  |  8 +++++
 src/metabase/public_settings.clj              | 21 ++++++-----
 .../public_settings/premium_features.clj      | 15 ++++++--
 test/metabase/api/session_test.clj            |  1 -
 5 files changed, 68 insertions(+), 12 deletions(-)
 create mode 100644 enterprise/backend/test/metabase_enterprise/api/session_test.clj
 create mode 100644 enterprise/backend/test/metabase_enterprise/api/session_test.lcj

diff --git a/enterprise/backend/test/metabase_enterprise/api/session_test.clj b/enterprise/backend/test/metabase_enterprise/api/session_test.clj
new file mode 100644
index 00000000000..82773aa89ae
--- /dev/null
+++ b/enterprise/backend/test/metabase_enterprise/api/session_test.clj
@@ -0,0 +1,35 @@
+(ns metabase-enterprise.api.session-test
+  (:require
+   [clojure.test :refer :all]
+   [metabase.public-settings.premium-features-test :as premium-features-test]
+   [metabase.test :as mt]
+   [metabase.test.fixtures :as fixtures]))
+
+(use-fixtures :once (fixtures/initialize :db))
+
+(deftest properties-token-features-test
+  (premium-features-test/with-premium-features #{:audit-app
+                                                 :advanced-permissions
+                                                 :embedding
+                                                 :whitelabel
+                                                 :advanced-config
+                                                 :content-management
+                                                 :sso
+                                                 :hosting
+                                                 :sandboxes
+                                                 :snippet-collections
+                                                 :disable-password-login
+                                                 :official-collections}
+    (is (= {:advanced_config        true
+            :advanced_permissions   true
+            :audit_app              true
+            :content_management     true
+            :disable_password_login true
+            :embedding              true
+            :hosting                true
+            :official_collections   true
+            :sandboxes              true
+            :snippet_collections    true
+            :sso                    true
+            :whitelabel             true}
+          (:token-features (mt/user-http-request :crowberto :get 200 "session/properties"))))))
diff --git a/enterprise/backend/test/metabase_enterprise/api/session_test.lcj b/enterprise/backend/test/metabase_enterprise/api/session_test.lcj
new file mode 100644
index 00000000000..b152f63728d
--- /dev/null
+++ b/enterprise/backend/test/metabase_enterprise/api/session_test.lcj
@@ -0,0 +1,8 @@
+(ns metabase-enterprise.audit-app.api.user-test
+  (:require
+   [clojure.test :refer :all]
+   [metabase.models :refer [Card Dashboard DashboardCard Pulse PulseCard PulseChannel PulseChannelRecipient User]]
+   [metabase.public-settings.premium-features-test :as premium-features-test]
+   [metabase.test :as mt]
+   [toucan2.core :as t2]
+   [toucan2.tools.with-temp :as t2.with-temp]))
diff --git a/src/metabase/public_settings.clj b/src/metabase/public_settings.clj
index 9182a2c9ea0..ec880a91ed0 100644
--- a/src/metabase/public_settings.clj
+++ b/src/metabase/public_settings.clj
@@ -546,15 +546,18 @@
   "Features registered for this instance's token"
   :visibility :public
   :setter     :none
-  :getter     (fn [] {:embedding            (premium-features/hide-embed-branding?)
-                      :whitelabel           (premium-features/enable-whitelabeling?)
-                      :audit_app            (premium-features/enable-audit-app?)
-                      :sandboxes            (premium-features/enable-sandboxes?)
-                      :sso                  (premium-features/enable-sso?)
-                      :advanced_config      (premium-features/enable-advanced-config?)
-                      :advanced_permissions (premium-features/enable-advanced-permissions?)
-                      :content_management   (premium-features/enable-content-management?)
-                      :hosting              (premium-features/is-hosted?)})
+  :getter     (fn [] {:embedding              (premium-features/hide-embed-branding?)
+                      :whitelabel             (premium-features/enable-whitelabeling?)
+                      :audit_app              (premium-features/enable-audit-app?)
+                      :sandboxes              (premium-features/enable-sandboxes?)
+                      :sso                    (premium-features/enable-sso?)
+                      :advanced_config        (premium-features/enable-advanced-config?)
+                      :advanced_permissions   (premium-features/enable-advanced-permissions?)
+                      :content_management     (premium-features/enable-content-management?)
+                      :hosting                (premium-features/is-hosted?)
+                      :official_collections   (premium-features/enable-official-collections?)
+                      :snippet_collections    (premium-features/enable-snippet-collections?)
+                      :disable_password_login (premium-features/can-disable-password-login?)})
   :doc        false)
 
 (defsetting redirect-all-requests-to-https
diff --git a/src/metabase/public_settings/premium_features.clj b/src/metabase/public_settings/premium_features.clj
index 0283b2d7bc2..f109b4c94b5 100644
--- a/src/metabase/public_settings/premium_features.clj
+++ b/src/metabase/public_settings/premium_features.clj
@@ -292,6 +292,10 @@
   "Should we enable advanced SSO features (SAML and JWT authentication; role and group mapping)?"
   :sso)
 
+(define-premium-feature can-disable-password-login?
+  "Can we password login?"
+  :disable-password-login)
+
 (define-premium-feature ^{:added "0.41.0"} enable-advanced-config?
   "Should we enable knobs and levers for more complex orgs (granular caching controls, allow-lists email domains for
   notifications, more in the future)?"
@@ -303,10 +307,17 @@
   :advanced-permissions)
 
 (define-premium-feature ^{:added "0.41.0"} enable-content-management?
-  "Should we enable official Collections, Question verifications (and more in the future, like workflows, forking,
-  etc.)?"
+  "Should we enable Question verifications (and more in the future, like workflows, forking, etc.)?"
   :content-management)
 
+(define-premium-feature ^{:added "0.41.0"} enable-official-collections?
+  "Should we enable Official Collections?"
+  :official-collections)
+
+(define-premium-feature ^{:added "0.41.0"} enable-snippet-collections?
+  "Should we enable Snippet collections"
+  :snippet-collections)
+
 (define-premium-feature ^{:added "0.45.0"} enable-serialization?
   "Enable the v2 SerDes functionality"
   :serialization)
diff --git a/test/metabase/api/session_test.clj b/test/metabase/api/session_test.clj
index 5ea3fde6c4f..30582e5d9f8 100644
--- a/test/metabase/api/session_test.clj
+++ b/test/metabase/api/session_test.clj
@@ -383,7 +383,6 @@
                (-> (mt/user-http-request :crowberto :get 200 "session/properties")
                    :test-session-api-setting)))))))
 
-
 (deftest properties-i18n-test
   (testing "GET /session/properties"
     (testing "Setting the X-Metabase-Locale header should result give you properties in that locale"
-- 
GitLab