🐛 Forward email when adding user to Nitrate organization

This commit is contained in:
Juanfran 2026-04-15 09:58:12 +02:00
parent 431056404c
commit f5591ed22e
5 changed files with 31 additions and 25 deletions

View File

@ -250,9 +250,11 @@
schema:team params))) schema:team params)))
(defn- add-profile-to-org-api (defn- add-profile-to-org-api
[cfg {:keys [profile-id org-id team-id] :as params}] [cfg {:keys [profile-id org-id team-id email] :as params}]
(let [baseuri (cf/get :nitrate-backend-uri) (let [baseuri (cf/get :nitrate-backend-uri)
params (assoc params :request-params {:user-id profile-id :team-id team-id})] request-params (cond-> {:user-id profile-id :team-id team-id}
(some? email) (assoc :email email))
params (assoc params :request-params request-params)]
(request-to-nitrate cfg :post (request-to-nitrate cfg :post
(str baseuri (str baseuri
"/api/organizations/" "/api/organizations/"

View File

@ -542,26 +542,29 @@
(defn initialize-user-in-nitrate-org (defn initialize-user-in-nitrate-org
"If needed, create a default team for the user on the organization, "If needed, create a default team for the user on the organization,
and notify Nitrate that an user has been added to an org." and notify Nitrate that an user has been added to an org."
[cfg profile-id org-id] ([cfg profile-id org-id]
(assert (db/connection-map? cfg) (initialize-user-in-nitrate-org cfg profile-id org-id nil))
"expected cfg with valid connection") ([cfg profile-id org-id email]
(when (contains? cf/flags :nitrate) (assert (db/connection-map? cfg)
(db/tx-run! "expected cfg with valid connection")
cfg (when (contains? cf/flags :nitrate)
(fn [{:keys [::db/conn] :as tx-cfg}] (db/tx-run!
(let [org-id org-id cfg
default-team (create-default-org-team (assoc tx-cfg ::db/conn conn) profile-id org-id) (fn [{:keys [::db/conn] :as tx-cfg}]
default-team-id (:id default-team) (let [org-id org-id
result (nitrate/call tx-cfg :add-profile-to-org {:profile-id profile-id default-team (create-default-org-team (assoc tx-cfg ::db/conn conn) profile-id org-id)
:team-id default-team-id default-team-id (:id default-team)
:org-id org-id})] result (nitrate/call tx-cfg :add-profile-to-org (cond-> {:profile-id profile-id
(when (not (:is-member result)) :team-id default-team-id
(ex/raise :type :internal :org-id org-id}
:code :failed-add-profile-org-nitrate (some? email) (assoc :email email)))]
:context {:profile-id profile-id (when (not (:is-member result))
:org-id org-id (ex/raise :type :internal
:default-team-id default-team-id})) :code :failed-add-profile-org-nitrate
default-team-id))))) :context {:profile-id profile-id
:org-id org-id
:default-team-id default-team-id}))
default-team-id))))))
(defn add-profile-to-team! (defn add-profile-to-team!
([cfg params] ([cfg params]

View File

@ -137,7 +137,7 @@
(if organization (if organization
;; Insert the invited member to the org ;; Insert the invited member to the org
(when (contains? cf/flags :nitrate) (when (contains? cf/flags :nitrate)
(teams/initialize-user-in-nitrate-org cfg (:id member) (:id organization))) (teams/initialize-user-in-nitrate-org cfg (:id member) (:id organization) email))
;; Insert the invited member to the team ;; Insert the invited member to the team
(teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true})) (teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true}))

View File

@ -111,7 +111,7 @@
accepted-team-id (if org-id accepted-team-id (if org-id
;; Insert the invited member to the org ;; Insert the invited member to the org
(when (contains? cf/flags :nitrate) (when (contains? cf/flags :nitrate)
(teams/initialize-user-in-nitrate-org cfg id-member org-id)) (teams/initialize-user-in-nitrate-org cfg id-member org-id member-email))
;; Insert the invited member to the team ;; Insert the invited member to the team
(do (teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true}) (do (teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true})
team-id))] team-id))]

View File

@ -57,7 +57,8 @@
(let [href (dm/str "/control-center/org/" (let [href (dm/str "/control-center/org/"
(u/percent-encode organization-slug) (u/percent-encode organization-slug)
"/" "/"
(u/percent-encode (str organization-id)))] (u/percent-encode (str organization-id))
"/people/")]
(st/emit! (rt/nav-raw :href href))) (st/emit! (rt/nav-raw :href href)))
(st/emit! (rt/nav-raw :href "/control-center/"))))) (st/emit! (rt/nav-raw :href "/control-center/")))))