Skip to content
Snippets Groups Projects
Commit d5dd71fa authored by Allen Gilliland's avatar Allen Gilliland
Browse files

add a new function for `(set-all [map])` in the settings model and add a new...

add a new function for `(set-all [map])` in the settings model and add a new api endpoint for PUT /api/setting/ which allows applying multiple settings in a single api call.
parent 09775d52
Branches
Tags
No related merge requests found
......@@ -5,11 +5,19 @@
(metabase.models [setting :as setting])))
(defendpoint GET "/"
"Get all `Settings` and their values. Superusers get all settings, normal users get public settings only."
"Get all `Settings` and their values. You must be a superuser to do this."
[]
(check-superuser)
(setting/all-with-descriptions))
(defendpoint PUT "/"
"Update multiple `Settings` values. You must be a superuser to do this."
[:as {settings :body}]
{settings [Required Dict]}
(check-superuser)
(setting/set-all settings)
(setting/all-with-descriptions))
(defendpoint GET "/:key"
"Fetch a single `Setting`. You must be a superuser to do this."
[key]
......@@ -19,7 +27,7 @@
(defendpoint PUT "/:key"
"Create/update a `Setting`. You must be a superuser to do this."
[key :as {{:keys [value]} :body}]
[key :as {{:keys [value]} :body}]
{key Required, value Required}
(check-superuser)
(setting/set (keyword key) value))
......
......@@ -81,6 +81,16 @@
(swap! cached-setting->value assoc k v)
v)
(defn set-all
"Set the value of a `Setting`.
(set :mandrill-api-key \"xyz123\")"
[settings]
{:pre [(map? settings)]}
(doseq [k (keys settings)]
(set k (clojure.core/get settings k)))
settings)
(defn delete
"Delete a `Setting`."
[k]
......
......@@ -31,6 +31,20 @@
((user->client :rasta) :get 403 "setting"))
;; ## PUT /api/setting
;; Check that we can update multiple Settings
(expect-eval-actual-first
[{:key "test-setting-1", :value "Jackpot!", :description "Test setting - this only shows up in dev (1)", :default "Using $MB_TEST_SETTING_1"}
{:key "test-setting-2", :value "Great gobs of goose shit!?", :description "Test setting - this only shows up in dev (2)", :default "[Default Value]"}]
(do ((user->client :crowberto) :put 200 "setting" {:test-setting-1 "Jackpot!"
:test-setting-2 "Great gobs of goose shit!?"})
(fetch-all-settings)))
;; Check that non-superusers are denied access
(expect "You don't have permissions to do that."
((user->client :rasta) :put 403 "setting" {:test-setting-1 "Something dangerous ..."}))
;; ## GET /api/setting/:key
;; Test that we can fetch a single setting
(expect-eval-actual-first
......
......@@ -70,6 +70,16 @@
(test-setting-2))
(db-fetch-setting :test-setting-2)])
;; Set multiple at one time
(expect-eval-actual-first
["I win!"
"For realz"]
(do
(setting/set-all {:test-setting-1 "I win!"
:test-setting-2 "For realz"})
[(db-fetch-setting :test-setting-1)
(db-fetch-setting :test-setting-2)]))
;; ## DELETE
;; Test defsetting delete w/o default value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment