Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Show read-only mode banner to all users (#70529)

Ben Grabow21b67b2892fb
diff --git a/frontend/src/metabase/common/components/AppBanner/AppBanner.tsx b/frontend/src/metabase/common/components/AppBanner/AppBanner.tsx
index ff5b6d31526..77279b00183 100644
--- a/frontend/src/metabase/common/components/AppBanner/AppBanner.tsx
+++ b/frontend/src/metabase/common/components/AppBanner/AppBanner.tsx
@@ -41,7 +41,11 @@ export const AppBanner = () => {
// Most banners are only visible to admins, but DevModeBanner gets shown to all users
if (!isAdmin) {
- return isDevMode ? <DevModeBanner /> : null;
+ return migrateReadOnly ? (
+ <ReadOnlyBanner />
+ ) : isDevMode ? (
+ <DevModeBanner />
+ ) : null;
}
if (migrateReadOnly) {
diff --git a/frontend/src/metabase/common/components/AppBanner/AppBanner.unit.spec.tsx b/frontend/src/metabase/common/components/AppBanner/AppBanner.unit.spec.tsx
index 68175e06298..63083b6962f 100644
--- a/frontend/src/metabase/common/components/AppBanner/AppBanner.unit.spec.tsx
+++ b/frontend/src/metabase/common/components/AppBanner/AppBanner.unit.spec.tsx
@@ -137,12 +137,16 @@ describe("AppBanner", () => {
});
describe("ReadOnlyBanner", () => {
- it("should not render for non-admins", () => {
+ it("should render for non-admins", () => {
setup({
isAdmin: false,
isReadOnly: true,
});
- expect(screen.queryByTestId("app-banner")).not.toBeInTheDocument();
+ expect(
+ screen.getByText(
+ "Metabase is under maintenance and is operating in read-only mode. It should only take up to 30 minutes.",
+ ),
+ ).toBeInTheDocument();
});
it("should render if Metabase is in read-only mode", () => {
diff --git a/src/metabase/cloud_migration/settings.clj b/src/metabase/cloud_migration/settings.clj
index 43d925659cb..e92708af212 100644
--- a/src/metabase/cloud_migration/settings.clj
+++ b/src/metabase/cloud_migration/settings.clj
@@ -77,7 +77,7 @@
"Will take up to 1m to propagate to other Metabase instances in a cluster."
"Audit tables are excluded from read-only-mode mode."))
:type :boolean
- :visibility :admin
+ :visibility :admin-write-authed-read
:default false
:doc false
:export? false)
diff --git a/src/metabase/settings/models/setting.clj b/src/metabase/settings/models/setting.clj
index 12ac043e11b..10e59030aae 100644
--- a/src/metabase/settings/models/setting.clj
+++ b/src/metabase/settings/models/setting.clj
@@ -111,7 +111,7 @@
(contains? (set (keys (methods get-value-of-type))) a-type))])
(def ^:private Visibility
- [:enum :public :authenticated :settings-manager :admin :internal])
+ [:enum :public :authenticated :settings-manager :admin-write-authed-read :admin :internal])
(defmulti default-tag-for-type
"Type tag that will be included in the Setting's metadata, so that the getter function will not cause reflection
@@ -1240,13 +1240,14 @@
Controls where this setting is visible, and who can update it. Possible values are:
- Visibility | Who Can See It? | Who Can Update It?
- ---------------- | ---------------------------- | --------------------
- :public | The entire world | Admins and Settings Managers
- :authenticated | Logged-in Users | Admins and Settings Managers
- :settings-manager| Admins and Settings Managers | Admins and Settings Managers
- :admin | Admins | Admins
- :internal | Nobody | No one (usually for env-var-only settings)
+ Visibility | Who Can See It? | Who Can Update It?
+ ------------------------ | ---------------------------- | --------------------
+ :public | The entire world | Admins and Settings Managers
+ :authenticated | Logged-in Users | Admins and Settings Managers
+ :settings-manager | Admins and Settings Managers | Admins and Settings Managers
+ :admin-write-authed-read | Logged-in Users | Admins
+ :admin | Admins | Admins
+ :internal | Nobody | No one (usually for env-var-only settings)
'Settings Managers' are non-admin users with the 'settings' permission, which gives them access to the Settings page
in the Admin Panel.
@@ -1472,7 +1473,8 @@
[]
(set (concat [:public]
(when @api/*current-user*
- [:authenticated])
+ [:authenticated
+ :admin-write-authed-read])
(when (has-advanced-setting-access?)
[:settings-manager])
(when api/*is-superuser?*
@@ -1485,7 +1487,7 @@
(when (has-advanced-setting-access?)
[:settings-manager :authenticated :public])
(when api/*is-superuser?*
- [:admin]))))
+ [:admin :admin-write-authed-read]))))
(defn- user-facing-settings-matching
"Returns the user facing view of the registered settings satisfying the given predicate"
diff --git a/test/metabase/session/api_test.clj b/test/metabase/session/api_test.clj
index 5dab846c1ec..f8d764b0cdc 100644
--- a/test/metabase/session/api_test.clj
+++ b/test/metabase/session/api_test.clj
@@ -524,18 +524,18 @@
(testing "Authenticated normal user"
(mt/with-test-user :lucky
- (is (= (set (keys (setting/user-readable-values-map #{:public :authenticated})))
+ (is (= (set (keys (setting/user-readable-values-map #{:public :authenticated :admin-write-authed-read})))
(set (keys (mt/user-http-request :lucky :get 200 "session/properties")))))))
(testing "Authenticated settings manager"
(mt/with-test-user :lucky
(with-redefs [metabase.settings.models.setting/has-advanced-setting-access? (constantly true)]
- (is (= (set (keys (setting/user-readable-values-map #{:public :authenticated :settings-manager})))
+ (is (= (set (keys (setting/user-readable-values-map #{:public :authenticated :settings-manager :admin-write-authed-read})))
(set (keys (mt/user-http-request :lucky :get 200 "session/properties"))))))))
(testing "Authenticated super user"
(mt/with-test-user :crowberto
- (is (= (set (keys (setting/user-readable-values-map #{:public :authenticated :settings-manager :admin})))
+ (is (= (set (keys (setting/user-readable-values-map #{:public :authenticated :settings-manager :admin-write-authed-read :admin})))
(set (keys (mt/user-http-request :crowberto :get 200 "session/properties")))))))
(testing "Includes user-local settings"
diff --git a/test/metabase/settings_rest/api_test.clj b/test/metabase/settings_rest/api_test.clj
index 758ccb9fc67..4c2e118b1bb 100644
--- a/test/metabase/settings_rest/api_test.clj
+++ b/test/metabase/settings_rest/api_test.clj
@@ -37,6 +37,11 @@
:visibility :settings-manager
:encryption :when-encryption-key-set)
+(defsetting test-admin-write-authed-read-visibility
+ (deferred-tru "Setting to test the `:admin-write-authed-read` visibility level. This only shows up in dev.")
+ :visibility :admin-write-authed-read
+ :encryption :when-encryption-key-set)
+
;; ## Helper Fns
(defn- fetch-test-settings
"Fetch the provided settings using the API. Settings not present in the response are ignored."
@@ -103,6 +108,16 @@
:default nil}]
(fetch-test-settings :rasta [:test-setting-1 :test-settings-manager-visibility])))))
+ (testing "Check that authenticated users can read Settings with `:visibility :admin-write-authed-read` via session/properties"
+ (test-admin-write-authed-read-visibility! "VALUE")
+ (is (= "VALUE"
+ (get (mt/user-http-request :rasta :get 200 "session/properties")
+ :test-admin-write-authed-read-visibility)))
+ (testing "but non-admins cannot read them via GET /api/setting (the admin-only listing endpoint)"
+ (is (= "You don't have permissions to do that."
+ (mt/user-http-request :rasta :get 403 "setting"))))
+ (test-admin-write-authed-read-visibility! nil))
+
(testing "Check that non-admins are denied access"
(is (= "You don't have permissions to do that."
(mt/user-http-request :rasta :get 403 "setting")))))
@@ -182,6 +197,17 @@
(is (= "You don't have permissions to do that."
(mt/user-http-request :rasta :put 403 "setting/test-setting-1" {:value "NICE!"}))))
+ (testing "Check that :admin-write-authed-read settings are writable by admins but not non-admins"
+ (mt/user-http-request :crowberto :put 204 "setting/test-admin-write-authed-read-visibility" {:value "ADMIN_SET"})
+ (is (= "ADMIN_SET"
+ (test-admin-write-authed-read-visibility)))
+ (is (= "You don't have permissions to do that."
+ (mt/user-http-request :rasta :put 403 "setting/test-admin-write-authed-read-visibility" {:value "RASTA_SET"})))
+ (is (= "ADMIN_SET"
+ (test-admin-write-authed-read-visibility))
+ "Value should be unchanged after non-admin write attempt")
+ (test-admin-write-authed-read-visibility! nil))
+
(testing "Check that a generic 403 error is returned if a non-superuser tries to set a Setting that doesn't exist"
(is (= "You don't have permissions to do that."
(mt/user-http-request :rasta :put 403 "setting/bad-setting" {:value "NICE!"}))))))