Skip to content

Commit

Permalink
Add last_name to ApiKey users
Browse files Browse the repository at this point in the history
When we generate a `:common_name` on Users, we check for the presence of
both `first_name` and `last_name`. If either is `nil`, we don't generate
a `common_name`.

ApiKey users only have one name (the name of the ApiKey itself) but we
should set the `last_name` to an empty string. This way, the common name
will still be generated.
  • Loading branch information
johnswanson committed Jan 3, 2024
1 parent 0ef5af2 commit 8e25122
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/metabase/api/api_key.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
(t2/with-transaction [_conn]
(let [user (user/insert-new-user! {:email email
:first_name name
:last_name ""
:type :api-key})]
(user/set-permissions-groups! user [(perms-group/all-users) group_id])
(let [api-key (-> (t2/insert-returning-instance! :model/ApiKey
Expand Down Expand Up @@ -93,7 +94,8 @@
(user/set-permissions-groups! user [(perms-group/all-users) {:id group_id}])))
(when name
;; A bit of a pain to keep these in sync, but oh well.
(t2/update! :model/User (:user_id api-key-before) {:first_name name})
(t2/update! :model/User (:user_id api-key-before) {:first_name name
:last_name ""})
(t2/update! :model/ApiKey id (with-updated-by {:name name}))))
(let [updated-api-key (-> (t2/select-one :model/ApiKey :id id)
(t2/hydrate :group :updated_by))]
Expand Down

0 comments on commit 8e25122

Please sign in to comment.