Skip to content
Snippets Groups Projects
Unverified Commit 0992b052 authored by metabase-bot[bot]'s avatar metabase-bot[bot] Committed by GitHub
Browse files

:robot: backported "Ignore internal user when initializing from config file" (#41111)

parent 19fd8383
No related branches found
No related tags found
No related merge requests found
(ns metabase-enterprise.advanced-config.file.users
(:require
[clojure.spec.alpha :as s]
[metabase-enterprise.advanced-config.file.interface :as advanced-config.file.i]
[metabase-enterprise.advanced-config.file.interface
:as advanced-config.file.i]
[metabase.models.user :refer [User]]
[metabase.setup :as setup]
[metabase.util :as u]
[metabase.util.i18n :as i18n :refer [trs]]
[metabase.util.log :as log]
......@@ -30,23 +32,16 @@
[_section]
(s/spec (s/* ::config-file-spec)))
(defn- init-from-config-file-is-first-user?
"For [[init-from-config-file!]]: `true` if this the first User being created for this instance. If so, we will ALWAYS
create that User as a superuser, regardless of what is specified in the config file. (It doesn't make sense to
create the first User as anything other than a superuser)."
[]
(zero? (t2/count User)))
(defn- init-from-config-file!
[user]
;; TODO -- if this is the FIRST user, we should probably make them a superuser, right?
(if-let [existing-user-id (t2/select-one-pk User :email (:email user))]
(do
(log/info (u/colorize :blue (trs "Updating User with email {0}" (pr-str (:email user)))))
(t2/update! User existing-user-id user))
;; create a new user. If they are the first User, force them to be an admin.
;; create a new user. If they are the first non-internal User, force them to be an admin.
(let [user (cond-> user
(init-from-config-file-is-first-user?) (assoc :is_superuser true))]
(not (setup/has-user-setup)) (assoc :is_superuser true))]
(log/info (u/colorize :green (trs "Creating the first User for this instance. The first user is always created as an admin.")))
(log/info (u/colorize :green (trs "Creating new User {0} with email {1}"
(pr-str (str (:first_name user) \space (:last_name user)))
......
......@@ -2,8 +2,8 @@
(:require
[clojure.test :refer :all]
[metabase-enterprise.advanced-config.file :as advanced-config.file]
[metabase-enterprise.advanced-config.file.users :as advanced-config.file.users]
[metabase.models :refer [User]]
[metabase.setup :as setup]
[metabase.test :as mt]
[metabase.util.password :as u.password]
[toucan2.core :as t2]))
......@@ -70,7 +70,7 @@
:email "cam+config-file-admin-test@metabase.com"
:password "2cans"
:is_superuser false}]}}]
(with-redefs [advanced-config.file.users/init-from-config-file-is-first-user? (constantly true)]
(with-redefs [setup/has-user-setup (constantly false)]
(is (= :ok
(advanced-config.file/initialize!)))
(is (partial= {:first_name "Cam"
......
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