💄 Unify naming on nitrate-api

This commit is contained in:
Pablo Alba 2026-04-20 12:23:51 +02:00 committed by Pablo Alba
parent 81faa5a728
commit ad974f4047
17 changed files with 240 additions and 232 deletions

View File

@ -205,7 +205,7 @@
</tr> </tr>
</table> </table>
<span style="display:inline-block; vertical-align: middle;padding-left:5px;height:20px;line-height: 20px;"> <span style="display:inline-block; vertical-align: middle;padding-left:5px;height:20px;line-height: 20px;">
“{{ org-name|abbreviate:25 }}” “{{ organization-name|abbreviate:25 }}”
</span> </span>
</div> </div>
</td> </td>

View File

@ -1 +1 @@
{{invited-by|abbreviate:25}} has invited you to join the organization “{{ org-name|abbreviate:25 }}” {{invited-by|abbreviate:25}} has invited you to join the organization “{{ organization-name|abbreviate:25 }}”

View File

@ -1,6 +1,6 @@
Hello! Hello!
{{invited-by|abbreviate:25}} has invited you to join the organization “{{ org-name|abbreviate:25 }}”. {{invited-by|abbreviate:25}} has invited you to join the organization “{{ organization-name|abbreviate:25 }}”.
Accept invitation using this link: Accept invitation using this link:

View File

@ -415,7 +415,7 @@
(def ^:private schema:invite-to-org (def ^:private schema:invite-to-org
[:map [:map
[:invited-by ::sm/text] [:invited-by ::sm/text]
[:org-name ::sm/text] [:organization-name ::sm/text]
[:org-initials ::sm/text] [:org-initials ::sm/text]
[:org-logo ::sm/uri] [:org-logo ::sm/uri]
[:user-name [:maybe ::sm/text]] [:user-name [:maybe ::sm/text]]

View File

@ -223,12 +223,12 @@
schema:organization params))) schema:organization params)))
(defn- get-org-membership-api (defn- get-org-membership-api
[cfg {:keys [profile-id org-id] :as params}] [cfg {:keys [profile-id organization-id] :as params}]
(let [baseuri (cf/get :nitrate-backend-uri)] (let [baseuri (cf/get :nitrate-backend-uri)]
(request-to-nitrate cfg :get (request-to-nitrate cfg :get
(str baseuri (str baseuri
"/api/organizations/" "/api/organizations/"
org-id organization-id
"/members/" "/members/"
profile-id) profile-id)
schema:profile-org params))) schema:profile-org params)))
@ -246,12 +246,12 @@
(defn- get-org-summary-api (defn- get-org-summary-api
[cfg {:keys [org-id] :as params}] [cfg {:keys [organization-id] :as params}]
(let [baseuri (cf/get :nitrate-backend-uri)] (let [baseuri (cf/get :nitrate-backend-uri)]
(request-to-nitrate cfg :get (request-to-nitrate cfg :get
(str baseuri (str baseuri
"/api/organizations/" "/api/organizations/"
org-id organization-id
"/summary") "/summary")
schema:org-summary params))) schema:org-summary params)))
@ -269,7 +269,7 @@
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 email] :as params}] [cfg {:keys [profile-id organization-id team-id email] :as params}]
(let [baseuri (cf/get :nitrate-backend-uri) (let [baseuri (cf/get :nitrate-backend-uri)
request-params (cond-> {:user-id profile-id :team-id team-id} request-params (cond-> {:user-id profile-id :team-id team-id}
(some? email) (assoc :email email)) (some? email) (assoc :email email))
@ -277,18 +277,18 @@
(request-to-nitrate cfg :post (request-to-nitrate cfg :post
(str baseuri (str baseuri
"/api/organizations/" "/api/organizations/"
org-id organization-id
"/add-user") "/add-user")
schema:profile-org params))) schema:profile-org params)))
(defn- remove-profile-from-org-api (defn- remove-profile-from-org-api
[cfg {:keys [profile-id org-id] :as params}] [cfg {:keys [profile-id organization-id] :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})] params (assoc params :request-params {:user-id profile-id})]
(request-to-nitrate cfg :post (request-to-nitrate cfg :post
(str baseuri (str baseuri
"/api/organizations/" "/api/organizations/"
org-id organization-id
"/remove-user") "/remove-user")
nil params))) nil params)))

View File

@ -34,7 +34,7 @@
(defn assert-membership [cfg profile-id organization-id] (defn assert-membership [cfg profile-id organization-id]
(let [membership (nitrate/call cfg :get-org-membership {:profile-id profile-id (let [membership (nitrate/call cfg :get-org-membership {:profile-id profile-id
:org-id organization-id})] :organization-id organization-id})]
(when-not (:organization-id membership) (when-not (:organization-id membership)
(ex/raise :type :validation (ex/raise :type :validation
:code :organization-doesnt-exists)) :code :organization-doesnt-exists))
@ -83,8 +83,8 @@
(def ^:private schema:leave-org (def ^:private schema:leave-org
[:map [:map
[:org-id ::sm/uuid] [:id ::sm/uuid]
[:org-name ::sm/text] [:name ::sm/text]
[:default-team-id ::sm/uuid] [:default-team-id ::sm/uuid]
[:teams-to-delete [:teams-to-delete
[:vector ::sm/uuid]] [:vector ::sm/uuid]]
@ -130,13 +130,13 @@
:valid-teams-to-exit valid-teams-to-exit :valid-teams-to-exit valid-teams-to-exit
:valid-default-team valid-default-team}))) :valid-default-team valid-default-team})))
(defn get-valid-teams [cfg org-id profile-id default-team-id] (defn get-valid-teams [cfg organization-id profile-id default-team-id]
(let [org-summary (nitrate/call cfg :get-org-summary {:org-id org-id}) (let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
org-teams (get-organization-teams-for-user cfg org-summary profile-id)] org-teams (get-organization-teams-for-user cfg org-summary profile-id)]
(calculate-valid-teams org-teams default-team-id))) (calculate-valid-teams org-teams default-team-id)))
(defn- assert-valid-teams [cfg profile-id org-id default-team-id teams-to-delete teams-to-leave] (defn- assert-valid-teams [cfg profile-id organization-id default-team-id teams-to-delete teams-to-leave]
(let [org-summary (nitrate/call cfg :get-org-summary {:org-id org-id}) (let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
org-teams (get-organization-teams-for-user cfg org-summary profile-id) org-teams (get-organization-teams-for-user cfg org-summary profile-id)
{:keys [valid-teams-to-delete-ids {:keys [valid-teams-to-delete-ids
valid-teams-to-transfer valid-teams-to-transfer
@ -184,8 +184,8 @@
(defn leave-org (defn leave-org
[{:keys [::db/conn] :as cfg} {:keys [profile-id org-id org-name default-team-id teams-to-delete teams-to-leave skip-validation] :as params}] [{:keys [::db/conn] :as cfg} {:keys [profile-id id name default-team-id teams-to-delete teams-to-leave skip-validation] :as params}]
(let [org-prefix (str "[" (d/sanitize-string org-name) "] ") (let [org-prefix (str "[" (d/sanitize-string name) "] ")
default-team-files-count (-> (db/exec-one! conn [sql:get-team-files-count default-team-id]) default-team-files-count (-> (db/exec-one! conn [sql:get-team-files-count default-team-id])
:total) :total)
@ -196,9 +196,9 @@
;; assert that the received teams are valid, checking the different constraints ;; assert that the received teams are valid, checking the different constraints
(when-not skip-validation (when-not skip-validation
(assert-valid-teams cfg profile-id org-id default-team-id teams-to-delete teams-to-leave)) (assert-valid-teams cfg profile-id id default-team-id teams-to-delete teams-to-leave))
(assert-membership cfg profile-id org-id) (assert-membership cfg profile-id id)
;; delete the teams-to-delete ;; delete the teams-to-delete
(doseq [id teams-to-delete] (doseq [id teams-to-delete]
@ -216,7 +216,7 @@
(db/exec! conn [sql:prefix-team-name-and-unset-default org-prefix default-team-id])) (db/exec! conn [sql:prefix-team-name-and-unset-default org-prefix default-team-id]))
;; Api call to nitrate ;; Api call to nitrate
(nitrate/call cfg :remove-profile-from-org {:profile-id profile-id :org-id org-id}) (nitrate/call cfg :remove-profile-from-org {:profile-id profile-id :organization-id id})
nil)) nil))

View File

@ -542,9 +542,9 @@
(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 organization-id]
(initialize-user-in-nitrate-org cfg profile-id org-id nil)) (initialize-user-in-nitrate-org cfg profile-id organization-id nil))
([cfg profile-id org-id email] ([cfg profile-id organization-id email]
(assert (db/connection-map? cfg) (assert (db/connection-map? cfg)
"expected cfg with valid connection") "expected cfg with valid connection")
(when (contains? cf/flags :nitrate) (when (contains? cf/flags :nitrate)
@ -553,25 +553,25 @@
(fn [{:keys [::db/conn] :as tx-cfg}] (fn [{:keys [::db/conn] :as tx-cfg}]
(let [membership (nitrate/call cfg :get-org-membership {:profile-id profile-id (let [membership (nitrate/call cfg :get-org-membership {:profile-id profile-id
:org-id org-id})] :organization-id organization-id})]
;; Only when the user doesn't belong to the organization yet ;; Only when the user doesn't belong to the organization yet
(when (and (when (and
(some? (:organization-id membership)) ;; the organization exists (some? (:organization-id membership)) ;; the organization exists
(not (:is-member membership))) ;; the user is not a member of the org yet (not (:is-member membership))) ;; the user is not a member of the org yet
(let [org-id org-id (let [organization-id organization-id
default-team (create-default-org-team (assoc tx-cfg ::db/conn conn) profile-id org-id) default-team (create-default-org-team (assoc tx-cfg ::db/conn conn) profile-id organization-id)
default-team-id (:id default-team) default-team-id (:id default-team)
result (nitrate/call tx-cfg :add-profile-to-org (cond-> {:profile-id profile-id result (nitrate/call tx-cfg :add-profile-to-org (cond-> {:profile-id profile-id
:team-id default-team-id :team-id default-team-id
:org-id org-id} :organization-id organization-id}
(some? email) (assoc :email email)))] (some? email) (assoc :email email)))]
(when (not (:is-member result)) (when (not (:is-member result))
(ex/raise :type :internal (ex/raise :type :internal
:code :failed-add-profile-org-nitrate :code :failed-add-profile-org-nitrate
:context {:profile-id profile-id :context {:profile-id profile-id
:org-id org-id :organization-id organization-id
:default-team-id default-team-id})) :default-team-id default-team-id}))
default-team-id)))))))) default-team-id))))))))

View File

@ -50,15 +50,15 @@
returning *") returning *")
(defn- create-invitation-token (defn- create-invitation-token
[cfg {:keys [profile-id valid-until org-id org-name team-id member-id member-email role]}] [cfg {:keys [profile-id valid-until organization-id organization-name team-id member-id member-email role]}]
(tokens/generate cfg (tokens/generate cfg
{:iss :team-invitation {:iss :team-invitation
:exp valid-until :exp valid-until
:profile-id profile-id :profile-id profile-id
:role role :role role
:team-id team-id :team-id team-id
:org-id org-id :organization-id organization-id
:org-name org-name :organization-name organization-name
:member-email member-email :member-email member-email
:member-id member-id})) :member-id member-id}))
@ -178,8 +178,8 @@
:invitation-id (:id invitation) :invitation-id (:id invitation)
:valid-until expire :valid-until expire
:team-id (:id team) :team-id (:id team)
:org-id (:id organization) :organization-id (:id organization)
:org-name (:name organization) :organization-name (:name organization)
:member-email (:email-to invitation) :member-email (:email-to invitation)
:member-id (:id member) :member-id (:id member)
:role role} :role role}
@ -210,7 +210,7 @@
:to email :to email
:invited-by (:fullname profile) :invited-by (:fullname profile)
:user-name (:fullname member) :user-name (:fullname member)
:org-name (:name organization) :organization-name (:name organization)
:org-logo (:logo organization) :org-logo (:logo organization)
:org-initials (d/get-initials (:name organization)) :org-initials (d/get-initials (:name organization))
:token itoken :token itoken

View File

@ -89,7 +89,7 @@
(defn- accept-invitation (defn- accept-invitation
[{:keys [::db/conn] :as cfg} [{:keys [::db/conn] :as cfg}
{:keys [team-id org-id role member-email] :as claims} invitation member] {:keys [team-id organization-id role member-email] :as claims} invitation member]
(let [;; Update the role if there is an invitation (let [;; Update the role if there is an invitation
role (or (some-> invitation :role keyword) role) role (or (some-> invitation :role keyword) role)
id-member (:id member)] id-member (:id member)]
@ -109,10 +109,10 @@
:profile-id id-member} :profile-id id-member}
(get types.team/permissions-for-role role)) (get types.team/permissions-for-role role))
accepted-team-id (if org-id accepted-team-id (if organization-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 member-email)) (teams/initialize-user-in-nitrate-org cfg id-member organization-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))]
@ -134,7 +134,7 @@
(db/delete! conn :team-invitation (db/delete! conn :team-invitation
(cond-> {:email-to member-email} (cond-> {:email-to member-email}
team-id (assoc :team-id team-id) team-id (assoc :team-id team-id)
org-id (assoc :org-id org-id))) organization-id (assoc :organization-id organization-id)))
;; Delete any request (only applicable for team invitations) ;; Delete any request (only applicable for team invitations)
(when team-id (when team-id
@ -151,11 +151,11 @@
[:profile-id ::sm/uuid] [:profile-id ::sm/uuid]
[:role types.team/schema:role] [:role types.team/schema:role]
[:team-id {:optional true} ::sm/uuid] [:team-id {:optional true} ::sm/uuid]
[:org-id {:optional true} ::sm/uuid] [:organization-id {:optional true} ::sm/uuid]
[:member-email ::sm/email] [:member-email ::sm/email]
[:member-id {:optional true} ::sm/uuid]] [:member-id {:optional true} ::sm/uuid]]
[:fn {:error/message "team-id or org-id must be present"} [:fn {:error/message "team-id or organization-id must be present"}
(fn [m] (or (:team-id m) (:org-id m)))]]) (fn [m] (or (:team-id m) (:organization-id m)))]])
(def valid-team-invitation-claims? (def valid-team-invitation-claims?
(sm/lazy-validator schema:team-invitation-claims)) (sm/lazy-validator schema:team-invitation-claims))
@ -163,7 +163,7 @@
(defmethod process-token :team-invitation (defmethod process-token :team-invitation
[{:keys [::db/conn] :as cfg} [{:keys [::db/conn] :as cfg}
{:keys [::rpc/profile-id token] :as params} {:keys [::rpc/profile-id token] :as params}
{:keys [member-id team-id org-id member-email] :as claims}] {:keys [member-id team-id organization-id member-email] :as claims}]
(when-not (valid-team-invitation-claims? claims) (when-not (valid-team-invitation-claims? claims)
(ex/raise :type :validation (ex/raise :type :validation
@ -173,16 +173,16 @@
(let [invitation (db/get* conn :team-invitation (let [invitation (db/get* conn :team-invitation
(cond-> {:email-to member-email} (cond-> {:email-to member-email}
team-id (assoc :team-id team-id) team-id (assoc :team-id team-id)
org-id (assoc :org-id org-id))) organization-id (assoc :organization-id organization-id)))
profile (db/get* conn :profile profile (db/get* conn :profile
{:id profile-id} {:id profile-id}
{:columns [:id :email :default-team-id]}) {:columns [:id :email :default-team-id]})
registration-disabled? (not (contains? cf/flags :registration)) registration-disabled? (not (contains? cf/flags :registration))
org-invitation? (and (contains? cf/flags :nitrate) org-id) org-invitation? (and (contains? cf/flags :nitrate) organization-id)
membership (when org-invitation? membership (when org-invitation?
(nitrate/call cfg :get-org-membership {:profile-id profile-id (nitrate/call cfg :get-org-membership {:profile-id profile-id
:org-id org-id}))] :organization-id organization-id}))]
(if profile (if profile
(do (do
@ -240,7 +240,7 @@
(cond-> (assoc claims :state :created) (cond-> (assoc claims :state :created)
;; when the invitation is to an org, instead of a team, add the ;; when the invitation is to an org, instead of a team, add the
;; accepted-team-id as :org-team-id ;; accepted-team-id as :org-team-id
(:org-id claims) (:organization-id claims)
(assoc :org-team-id accepted-team-id))))) (assoc :org-team-id accepted-team-id)))))
;; If we have not logged-in user, and invitation comes with member-id we ;; If we have not logged-in user, and invitation comes with member-id we

View File

@ -217,7 +217,7 @@ RETURNING id, name;")
(def ^:private schema:notify-org-deletion (def ^:private schema:notify-org-deletion
[:map [:map
[:org-name ::sm/text] [:organization-name ::sm/text]
[:teams [:vector ::sm/uuid]]]) [:teams [:vector ::sm/uuid]]])
(sv/defmethod ::notify-org-deletion (sv/defmethod ::notify-org-deletion
@ -225,9 +225,9 @@ RETURNING id, name;")
of the deletion to the connected users" of the deletion to the connected users"
{::doc/added "2.15" {::doc/added "2.15"
::sm/params schema:notify-org-deletion} ::sm/params schema:notify-org-deletion}
[cfg {:keys [teams org-name]}] [cfg {:keys [teams organization-name]}]
(when (seq teams) (when (seq teams)
(let [org-prefix (str "[" (d/sanitize-string org-name) "] ")] (let [org-prefix (str "[" (d/sanitize-string organization-name) "] ")]
(db/tx-run! (db/tx-run!
cfg cfg
(fn [{:keys [::db/conn] :as cfg}] (fn [{:keys [::db/conn] :as cfg}]
@ -237,7 +237,7 @@ RETURNING id, name;")
;; Notify users ;; Notify users
(doseq [team updated-teams] (doseq [team updated-teams]
(notifications/notify-team-change cfg (:id team) (:name team) nil org-name "dashboard.org-deleted")))))))) (notifications/notify-team-change cfg (:id team) (:name team) nil organization-name "dashboard.org-deleted"))))))))
;; ---- API: get-profile-by-email ;; ---- API: get-profile-by-email
@ -373,24 +373,26 @@ RETURNING id, name;")
{::doc/added "2.16" {::doc/added "2.16"
::sm/params [:map ::sm/params [:map
[:profile-id ::sm/uuid] [:profile-id ::sm/uuid]
[:org-id ::sm/uuid] [:organization-id ::sm/uuid]
[:org-name ::sm/text] [:organization-name ::sm/text]
[:default-team-id ::sm/uuid]] [:default-team-id ::sm/uuid]]
::db/transaction true} ::db/transaction true}
[cfg {:keys [profile-id org-id org-name default-team-id] :as params}] [cfg {:keys [profile-id organization-id organization-name default-team-id] :as params}]
(let [{:keys [valid-teams-to-delete-ids (let [{:keys [valid-teams-to-delete-ids
valid-teams-to-transfer valid-teams-to-transfer
valid-teams-to-exit]} (cnit/get-valid-teams cfg org-id profile-id default-team-id) valid-teams-to-exit]} (cnit/get-valid-teams cfg organization-id profile-id default-team-id)
add-reassign-to (partial add-reassign-to cfg profile-id) add-reassign-to (partial add-reassign-to cfg profile-id)
valid-teams-to-leave (into valid-teams-to-exit valid-teams-to-leave (into valid-teams-to-exit
(map add-reassign-to valid-teams-to-transfer))] (map add-reassign-to valid-teams-to-transfer))]
(cnit/leave-org cfg (assoc params (cnit/leave-org cfg (assoc params
:id organization-id
:name organization-name
:teams-to-delete valid-teams-to-delete-ids :teams-to-delete valid-teams-to-delete-ids
:teams-to-leave valid-teams-to-leave :teams-to-leave valid-teams-to-leave
:skip-validation true)) :skip-validation true))
(notifications/notify-user-removed-from-org cfg profile-id org-id org-name "dashboard.user-no-longer-belong-org") (notifications/notify-user-org-change cfg profile-id organization-id organization-name "dashboard.user-no-longer-belong-org")
nil)) nil))
;; API: get-remove-from-org-summary ;; API: get-remove-from-org-summary
@ -407,15 +409,15 @@ RETURNING id, name;")
{::doc/added "2.16" {::doc/added "2.16"
::sm/params [:map ::sm/params [:map
[:profile-id ::sm/uuid] [:profile-id ::sm/uuid]
[:org-id ::sm/uuid] [:organization-id ::sm/uuid]
[:default-team-id ::sm/uuid]] [:default-team-id ::sm/uuid]]
::sm/result schema:get-remove-from-org-summary-result ::sm/result schema:get-remove-from-org-summary-result
::db/transaction true} ::db/transaction true}
[cfg {:keys [profile-id org-id default-team-id]}] [cfg {:keys [profile-id organization-id default-team-id]}]
(let [{:keys [valid-teams-to-delete-ids (let [{:keys [valid-teams-to-delete-ids
valid-teams-to-transfer valid-teams-to-transfer
valid-teams-to-exit valid-teams-to-exit
valid-default-team]} (cnit/get-valid-teams cfg org-id profile-id default-team-id)] valid-default-team]} (cnit/get-valid-teams cfg organization-id profile-id default-team-id)]
(when-not valid-default-team (when-not valid-default-team
(ex/raise :type :validation (ex/raise :type :validation
:code :not-valid-teams)) :code :not-valid-teams))

View File

@ -24,7 +24,7 @@
:notification notification}))) :notification notification})))
(defn notify-user-removed-from-org (defn notify-user-org-change
[cfg profile-id organization-id organization-name notification] [cfg profile-id organization-id organization-name notification]
(let [msgbus (::mbus/msgbus cfg)] (let [msgbus (::mbus/msgbus cfg)]
(mbus/pub! msgbus (mbus/pub! msgbus

View File

@ -162,8 +162,8 @@
extra-team (th/create-team* 1 {:profile-id (:id profile)}) extra-team (th/create-team* 1 {:profile-id (:id profile)})
default-team (th/db-get :team {:id (:default-team-id profile)}) default-team (th/db-get :team {:id (:default-team-id profile)})
teams [(:id default-team) (:id extra-team)] teams [(:id default-team) (:id extra-team)]
org-name "Acme / Design" organization-name "Acme / Design"
expected-start (str "[" (d/sanitize-string org-name) "] ") expected-start (str "[" (d/sanitize-string organization-name) "] ")
calls (atom []) calls (atom [])
out (with-redefs [mbus/pub! (fn [_cfg & {:keys [topic message]}] out (with-redefs [mbus/pub! (fn [_cfg & {:keys [topic message]}]
(swap! calls conj {:topic topic (swap! calls conj {:topic topic
@ -171,7 +171,7 @@
(management-command-with-nitrate! {::th/type :notify-org-deletion (management-command-with-nitrate! {::th/type :notify-org-deletion
::rpc/profile-id (:id profile) ::rpc/profile-id (:id profile)
:teams teams :teams teams
:org-name org-name})) :organization-name organization-name}))
updated (map #(th/db-get :team {:id %} {::db/remove-deleted false}) teams)] updated (map #(th/db-get :team {:id %} {::db/remove-deleted false}) teams)]
(t/is (th/success? out)) (t/is (th/success? out))
(t/is (= 2 (count @calls))) (t/is (= 2 (count @calls)))
@ -181,7 +181,7 @@
(doseq [call @calls] (doseq [call @calls]
(t/is (= uuid/zero (:topic call))) (t/is (= uuid/zero (:topic call)))
(t/is (= :team-org-change (-> call :message :type))) (t/is (= :team-org-change (-> call :message :type)))
(t/is (= org-name (-> call :message :organization-name))) (t/is (= organization-name (-> call :message :organization-name)))
(t/is (= "dashboard.org-deleted" (-> call :message :notification)))))) (t/is (= "dashboard.org-deleted" (-> call :message :notification))))))
(t/deftest get-profile-by-email-success-and-not-found (t/deftest get-profile-by-email-success-and-not-found
@ -225,10 +225,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- make-org-summary (defn- make-org-summary
[& {:keys [org-id org-name owner-id your-penpot-teams org-teams] [& {:keys [organization-id organization-name owner-id your-penpot-teams org-teams]
:or {your-penpot-teams [] org-teams []}}] :or {your-penpot-teams [] org-teams []}}]
{:id org-id {:id organization-id
:name org-name :name organization-name
:owner-id owner-id :owner-id owner-id
:teams (into :teams (into
(mapv (fn [id] {:id id :is-your-penpot true}) your-penpot-teams) (mapv (fn [id] {:id id :is-your-penpot true}) your-penpot-teams)
@ -254,10 +254,10 @@
:team-id (:id org-team)}) :team-id (:id org-team)})
_ (th/create-file* 1 {:profile-id (:id user) _ (th/create-file* 1 {:profile-id (:id user)
:project-id (:id project)}) :project-id (:id project)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams []) :org-teams [])
@ -269,8 +269,8 @@
{::th/type :remove-from-org {::th/type :remove-from-org
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (th/success? out)) (t/is (th/success? out))
(t/is (nil? (:result out))) (t/is (nil? (:result out)))
@ -285,7 +285,7 @@
(let [msg (-> @calls first :message)] (let [msg (-> @calls first :message)]
(t/is (= :user-org-change (:type msg))) (t/is (= :user-org-change (:type msg)))
(t/is (= (:id user) (:topic msg))) (t/is (= (:id user) (:topic msg)))
(t/is (= org-id (:organization-id msg))) (t/is (= organization-id (:organization-id msg)))
(t/is (= "Acme Org" (:organization-name msg))) (t/is (= "Acme Org" (:organization-name msg)))
(t/is (= "dashboard.user-no-longer-belong-org" (:notification msg)))))) (t/is (= "dashboard.user-no-longer-belong-org" (:notification msg))))))
@ -294,10 +294,10 @@
(let [org-owner (th/create-profile* 1 {:is-active true}) (let [org-owner (th/create-profile* 1 {:is-active true})
user (th/create-profile* 2 {:is-active true}) user (th/create-profile* 2 {:is-active true})
org-team (th/create-team* 2 {:profile-id (:id user)}) org-team (th/create-team* 2 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams []) :org-teams [])
@ -307,8 +307,8 @@
{::th/type :remove-from-org {::th/type :remove-from-org
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (th/success? out)) (t/is (th/success? out))
(let [team (th/db-get :team {:id (:id org-team)} {::db/remove-deleted false})] (let [team (th/db-get :team {:id (:id org-team)} {::db/remove-deleted false})]
@ -320,10 +320,10 @@
user (th/create-profile* 2 {:is-active true}) user (th/create-profile* 2 {:is-active true})
extra-team (th/create-team* 3 {:profile-id (:id user)}) extra-team (th/create-team* 3 {:profile-id (:id user)})
org-team (th/create-team* 99 {:profile-id (:id user)}) org-team (th/create-team* 99 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams [(:id extra-team)]) :org-teams [(:id extra-team)])
@ -333,8 +333,8 @@
{::th/type :remove-from-org {::th/type :remove-from-org
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (th/success? out)) (t/is (th/success? out))
(let [team (th/db-get :team {:id (:id extra-team)} {::db/remove-deleted false})] (let [team (th/db-get :team {:id (:id extra-team)} {::db/remove-deleted false})]
@ -351,10 +351,10 @@
:profile-id (:id candidate) :profile-id (:id candidate)
:role :editor}) :role :editor})
org-team (th/create-team* 99 {:profile-id (:id user)}) org-team (th/create-team* 99 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams [(:id extra-team)]) :org-teams [(:id extra-team)])
@ -364,8 +364,8 @@
{::th/type :remove-from-org {::th/type :remove-from-org
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (th/success? out)) (t/is (th/success? out))
;; user no longer in extra-team ;; user no longer in extra-team
@ -384,10 +384,10 @@
:profile-id (:id user) :profile-id (:id user)
:role :editor}) :role :editor})
org-team (th/create-team* 99 {:profile-id (:id user)}) org-team (th/create-team* 99 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams [(:id extra-team)]) :org-teams [(:id extra-team)])
@ -397,8 +397,8 @@
{::th/type :remove-from-org {::th/type :remove-from-org
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (th/success? out)) (t/is (th/success? out))
;; user no longer a member of extra-team ;; user no longer a member of extra-team
@ -422,10 +422,10 @@
{:is-owner true :is-admin false} {:is-owner true :is-admin false}
{:team-id (:id extra-team) :profile-id (:id other-owner)}) {:team-id (:id extra-team) :profile-id (:id other-owner)})
org-team (th/create-team* 99 {:profile-id (:id user)}) org-team (th/create-team* 99 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id other-owner) :owner-id (:id other-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams [(:id extra-team)]) :org-teams [(:id extra-team)])
@ -435,8 +435,8 @@
{::th/type :remove-from-org {::th/type :remove-from-org
::rpc/profile-id (:id other-owner) ::rpc/profile-id (:id other-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (not (th/success? out))) (t/is (not (th/success? out)))
(t/is (= :validation (th/ex-type (:error out)))) (t/is (= :validation (th/ex-type (:error out))))
@ -450,10 +450,10 @@
(let [org-owner (th/create-profile* 1 {:is-active true}) (let [org-owner (th/create-profile* 1 {:is-active true})
user (th/create-profile* 2 {:is-active true}) user (th/create-profile* 2 {:is-active true})
org-team (th/create-team* 1 {:profile-id (:id user)}) org-team (th/create-team* 1 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams []) :org-teams [])
@ -462,7 +462,7 @@
{::th/type :get-remove-from-org-summary {::th/type :get-remove-from-org-summary
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (th/success? out)) (t/is (th/success? out))
(t/is (= {:teams-to-delete 0 (t/is (= {:teams-to-delete 0
@ -476,10 +476,10 @@
user (th/create-profile* 2 {:is-active true}) user (th/create-profile* 2 {:is-active true})
extra-team (th/create-team* 3 {:profile-id (:id user)}) extra-team (th/create-team* 3 {:profile-id (:id user)})
org-team (th/create-team* 99 {:profile-id (:id user)}) org-team (th/create-team* 99 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams [(:id extra-team)]) :org-teams [(:id extra-team)])
@ -488,7 +488,7 @@
{::th/type :get-remove-from-org-summary {::th/type :get-remove-from-org-summary
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (th/success? out)) (t/is (th/success? out))
(t/is (= {:teams-to-delete 1 (t/is (= {:teams-to-delete 1
@ -506,10 +506,10 @@
:profile-id (:id candidate) :profile-id (:id candidate)
:role :editor}) :role :editor})
org-team (th/create-team* 99 {:profile-id (:id user)}) org-team (th/create-team* 99 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams [(:id extra-team)]) :org-teams [(:id extra-team)])
@ -518,7 +518,7 @@
{::th/type :get-remove-from-org-summary {::th/type :get-remove-from-org-summary
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (th/success? out)) (t/is (th/success? out))
(t/is (= {:teams-to-delete 0 (t/is (= {:teams-to-delete 0
@ -535,10 +535,10 @@
:profile-id (:id user) :profile-id (:id user)
:role :editor}) :role :editor})
org-team (th/create-team* 99 {:profile-id (:id user)}) org-team (th/create-team* 99 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams [(:id extra-team)]) :org-teams [(:id extra-team)])
@ -547,7 +547,7 @@
{::th/type :get-remove-from-org-summary {::th/type :get-remove-from-org-summary
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
(t/is (th/success? out)) (t/is (th/success? out))
(t/is (= {:teams-to-delete 0 (t/is (= {:teams-to-delete 0
@ -561,10 +561,10 @@
user (th/create-profile* 2 {:is-active true}) user (th/create-profile* 2 {:is-active true})
extra-team (th/create-team* 6 {:profile-id (:id user)}) extra-team (th/create-team* 6 {:profile-id (:id user)})
org-team (th/create-team* 99 {:profile-id (:id user)}) org-team (th/create-team* 99 {:profile-id (:id user)})
org-id (uuid/random) organization-id (uuid/random)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Acme Org" :organization-name "Acme Org"
:owner-id (:id org-owner) :owner-id (:id org-owner)
:your-penpot-teams [(:id org-team)] :your-penpot-teams [(:id org-team)]
:org-teams [(:id extra-team)]) :org-teams [(:id extra-team)])
@ -573,7 +573,7 @@
{::th/type :get-remove-from-org-summary {::th/type :get-remove-from-org-summary
::rpc/profile-id (:id org-owner) ::rpc/profile-id (:id org-owner)
:profile-id (:id user) :profile-id (:id user)
:org-id org-id :organization-id organization-id
:default-team-id (:id org-team)}))] :default-team-id (:id org-team)}))]
;; Both teams must still exist and be undeleted ;; Both teams must still exist and be undeleted
(let [t1 (th/db-get :team {:id (:id org-team)})] (let [t1 (th/db-get :team {:id (:id org-team)})]

View File

@ -23,10 +23,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- make-org-summary (defn- make-org-summary
[& {:keys [org-id org-name owner-id your-penpot-teams org-teams] [& {:keys [organization-id organization-name owner-id your-penpot-teams org-teams]
:or {your-penpot-teams [] org-teams []}}] :or {your-penpot-teams [] org-teams []}}]
{:id org-id {:id organization-id
:name org-name :name organization-name
:owner-id owner-id :owner-id owner-id
:teams (into :teams (into
(mapv (fn [id] {:id id :is-your-penpot true}) your-penpot-teams) (mapv (fn [id] {:id id :is-your-penpot true}) your-penpot-teams)
@ -58,13 +58,13 @@
_ (th/create-file* 99 {:profile-id (:id profile-user) _ (th/create-file* 99 {:profile-id (:id profile-user)
:project-id (:id project)}) :project-id (:id project)})
org-id (uuid/random) organization-id (uuid/random)
;; The user's personal penpot team in the org context ;; The user's personal penpot team in the org context
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [])] :org-teams [])]
@ -72,8 +72,8 @@
(with-redefs [nitrate/call (nitrate-call-mock org-summary)] (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave []} :teams-to-leave []}
@ -94,12 +94,12 @@
profile-user (th/create-profile* 2 {:is-active true}) profile-user (th/create-profile* 2 {:is-active true})
org-default-team (th/create-team* 98 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 98 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [])] :org-teams [])]
@ -107,8 +107,8 @@
(with-redefs [nitrate/call (nitrate-call-mock org-summary)] (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave []} :teams-to-leave []}
@ -129,12 +129,12 @@
_ (th/create-file* 97 {:profile-id (:id profile-user) _ (th/create-file* 97 {:profile-id (:id profile-user)
:project-id (:id project)}) :project-id (:id project)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [])] :org-teams [])]
@ -142,8 +142,8 @@
(with-redefs [nitrate/call (nitrate-call-mock org-summary)] (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave []} :teams-to-leave []}
@ -164,12 +164,12 @@
team1 (th/create-team* 1 {:profile-id (:id profile-user)}) team1 (th/create-team* 1 {:profile-id (:id profile-user)})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1)])] :org-teams [(:id team1)])]
@ -177,8 +177,8 @@
(with-redefs [nitrate/call (nitrate-call-mock org-summary)] (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [(:id team1)] :teams-to-delete [(:id team1)]
:teams-to-leave []} :teams-to-leave []}
@ -201,12 +201,12 @@
:role :editor}) :role :editor})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1)])] :org-teams [(:id team1)])]
@ -214,8 +214,8 @@
(with-redefs [nitrate/call (nitrate-call-mock org-summary)] (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave [{:id (:id team1) :reassign-to (:id profile-owner)}]} :teams-to-leave [{:id (:id team1) :reassign-to (:id profile-owner)}]}
@ -246,12 +246,12 @@
:role :editor}) :role :editor})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1)])] :org-teams [(:id team1)])]
@ -259,8 +259,8 @@
(with-redefs [nitrate/call (nitrate-call-mock org-summary)] (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave [{:id (:id team1)}]} :teams-to-leave [{:id (:id team1)}]}
@ -282,13 +282,13 @@
(t/deftest leave-org-error-org-owner-cannot-leave (t/deftest leave-org-error-org-owner-cannot-leave
(let [profile-owner (th/create-profile* 1 {:is-active true}) (let [profile-owner (th/create-profile* 1 {:is-active true})
org-default-team (th/create-team* 99 {:profile-id (:id profile-owner)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-owner)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
;; profile-owner IS the org owner in the org-summary ;; profile-owner IS the org owner in the org-summary
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [])] :org-teams [])]
@ -296,8 +296,8 @@
(with-redefs [nitrate/call (nitrate-call-mock org-summary)] (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-owner) ::rpc/profile-id (:id profile-owner)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave []} :teams-to-leave []}
@ -311,12 +311,12 @@
(let [profile-owner (th/create-profile* 1 {:is-active true}) (let [profile-owner (th/create-profile* 1 {:is-active true})
profile-user (th/create-profile* 2 {:is-active true}) profile-user (th/create-profile* 2 {:is-active true})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [])] :org-teams [])]
@ -325,8 +325,8 @@
;; Pass a random UUID that is not in the your-penpot-teams list ;; Pass a random UUID that is not in the your-penpot-teams list
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id (uuid/random) :default-team-id (uuid/random)
:teams-to-delete [] :teams-to-delete []
:teams-to-leave []} :teams-to-leave []}
@ -435,12 +435,12 @@
:role :editor}) :role :editor})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1) (:id team2) (:id team3)])] :org-teams [(:id team1) (:id team2) (:id team3)])]
@ -448,8 +448,8 @@
(with-redefs [nitrate/call (nitrate-call-mock org-summary)] (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [(:id team1)] :teams-to-delete [(:id team1)]
:teams-to-leave [{:id (:id team2) :reassign-to (:id profile-owner)} :teams-to-leave [{:id (:id team2) :reassign-to (:id profile-owner)}
@ -485,12 +485,12 @@
team2 (th/create-team* 2 {:profile-id (:id profile-user)}) team2 (th/create-team* 2 {:profile-id (:id profile-user)})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1) (:id team2)])] :org-teams [(:id team1) (:id team2)])]
@ -499,8 +499,8 @@
;; Only team1 is listed; team2 is also a sole-owner team and must be included ;; Only team1 is listed; team2 is also a sole-owner team and must be included
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [(:id team1)] :teams-to-delete [(:id team1)]
:teams-to-leave []} :teams-to-leave []}
@ -520,12 +520,12 @@
:role :editor}) :role :editor})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1)])] :org-teams [(:id team1)])]
@ -534,8 +534,8 @@
;; team1 has 2 members so it is not a valid deletion candidate ;; team1 has 2 members so it is not a valid deletion candidate
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [(:id team1)] :teams-to-delete [(:id team1)]
:teams-to-leave []} :teams-to-leave []}
@ -555,12 +555,12 @@
:role :editor}) :role :editor})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1)])] :org-teams [(:id team1)])]
@ -569,8 +569,8 @@
;; team1 must be transferred (owner + multiple members) but is absent ;; team1 must be transferred (owner + multiple members) but is absent
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave []} :teams-to-leave []}
@ -589,12 +589,12 @@
:role :editor}) :role :editor})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1)])] :org-teams [(:id team1)])]
@ -603,8 +603,8 @@
;; reassign-to points to the profile that is leaving — not allowed ;; reassign-to points to the profile that is leaving — not allowed
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave [{:id (:id team1) :reassign-to (:id profile-user)}]} :teams-to-leave [{:id (:id team1) :reassign-to (:id profile-user)}]}
@ -625,12 +625,12 @@
:role :editor}) :role :editor})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1)])] :org-teams [(:id team1)])]
@ -639,8 +639,8 @@
;; profile-other is not a member of team1 ;; profile-other is not a member of team1
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave [{:id (:id team1) :reassign-to (:id profile-other)}]} :teams-to-leave [{:id (:id team1) :reassign-to (:id profile-other)}]}
@ -660,12 +660,12 @@
:role :editor}) :role :editor})
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)}) org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
org-id (uuid/random) organization-id (uuid/random)
your-penpot-id (:id org-default-team) your-penpot-id (:id org-default-team)
org-summary (make-org-summary org-summary (make-org-summary
:org-id org-id :organization-id organization-id
:org-name "Test Org" :organization-name "Test Org"
:owner-id (:id profile-owner) :owner-id (:id profile-owner)
:your-penpot-teams [your-penpot-id] :your-penpot-teams [your-penpot-id]
:org-teams [(:id team1)])] :org-teams [(:id team1)])]
@ -674,8 +674,8 @@
;; profile-user is not the owner so providing reassign-to is invalid ;; profile-user is not the owner so providing reassign-to is invalid
(let [data {::th/type :leave-org (let [data {::th/type :leave-org
::rpc/profile-id (:id profile-user) ::rpc/profile-id (:id profile-user)
:org-id org-id :id organization-id
:org-name "Test Org" :name "Test Org"
:default-team-id your-penpot-id :default-team-id your-penpot-id
:teams-to-delete [] :teams-to-delete []
:teams-to-leave [{:id (:id team1) :reassign-to (:id profile-owner)}]} :teams-to-leave [{:id (:id team1) :reassign-to (:id profile-owner)}]}

View File

@ -91,14 +91,14 @@
(dm/get-in profile [:subscription :status])))) (dm/get-in profile [:subscription :status]))))
(defn leave-org (defn leave-org
[{:keys [id org-name default-team-id teams-to-delete teams-to-leave on-error] :as params}] [{:keys [id name default-team-id teams-to-delete teams-to-leave on-error] :as params}]
(ptk/reify ::leave-org (ptk/reify ::leave-org
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [profile-team-id (dm/get-in state [:profile :default-team-id])] (let [profile-team-id (dm/get-in state [:profile :default-team-id])]
(->> (rp/cmd! ::leave-org {:org-id id (->> (rp/cmd! ::leave-org {:id id
:org-name org-name :name name
:default-team-id default-team-id :default-team-id default-team-id
:teams-to-delete teams-to-delete :teams-to-delete teams-to-delete
:teams-to-leave teams-to-leave}) :teams-to-leave teams-to-leave})
@ -108,7 +108,7 @@
(dt/fetch-teams) (dt/fetch-teams)
(dcm/go-to-dashboard-recent :team-id profile-team-id) (dcm/go-to-dashboard-recent :team-id profile-team-id)
(modal/hide) (modal/hide)
(ntf/show {:content (tr "dasboard.leave-org.toast" org-name) (ntf/show {:content (tr "dasboard.leave-org.toast" name)
:type :toast :type :toast
:level :success})))) :level :success}))))
(rx/catch on-error)))))) (rx/catch on-error))))))

View File

@ -43,14 +43,14 @@
(st/emit! (da/login-from-token tdata))) (st/emit! (da/login-from-token tdata)))
(defmethod handle-token :team-invitation (defmethod handle-token :team-invitation
[{:keys [state team-id org-team-id org-name invitation-token] :as tdata}] [{:keys [state team-id org-team-id organization-name invitation-token] :as tdata}]
(case state (case state
:created :created
(if org-team-id (if org-team-id
(st/emit! (st/emit!
(du/refresh-profile) (du/refresh-profile)
(dcm/go-to-dashboard-recent :team-id org-team-id) (dcm/go-to-dashboard-recent :team-id org-team-id)
(ntf/success (tr "auth.notifications.org-invitation-accepted" org-name))) (ntf/success (tr "auth.notifications.org-invitation-accepted" organization-name)))
(st/emit! (st/emit!
(du/refresh-profile) (du/refresh-profile)
(dcm/go-to-dashboard-recent :team-id team-id) (dcm/go-to-dashboard-recent :team-id team-id)

View File

@ -7,9 +7,12 @@
@use "refactor/common-refactor.scss" as deprecated; @use "refactor/common-refactor.scss" as deprecated;
@use "ds/typography.scss" as t; @use "ds/typography.scss" as t;
@use "ds/_sizes.scss" as *; @use "ds/_sizes.scss" as *;
@use "ds/z-index.scss" as *;
.modal-overlay { .modal-overlay {
@extend %modal-overlay-base; @extend %modal-overlay-base;
z-index: var(--z-index-notifications);
} }
.modal-container { .modal-container {

View File

@ -640,7 +640,9 @@
(concat teams-to-transfer)) (concat teams-to-transfer))
teams-to-delete (map :id teams-to-delete)] teams-to-delete (map :id teams-to-delete)]
(st/emit! (dnt/leave-org {:id (:id organization) (st/emit! (dnt/leave-org {:id (:id organization)
:name (:name organization)
:default-team-id default-team-id :default-team-id default-team-id
:teams-to-delete teams-to-delete :teams-to-delete teams-to-delete
:teams-to-leave teams-to-leave :teams-to-leave teams-to-leave
@ -649,32 +651,33 @@
on-leave-clicked on-leave-clicked
(mf/use-fn (mf/use-fn
(mf/deps leave-fn profile organization teams-to-transfer num-teams-to-leave num-teams-to-delete num-teams-to-transfer) (mf/deps leave-fn profile organization teams-to-transfer num-teams-to-leave num-teams-to-delete num-teams-to-transfer)
(cond (fn []
(and (pos? num-teams-to-delete) (cond
(zero? num-teams-to-transfer)) (and (pos? num-teams-to-delete)
#(st/emit! (modal/show (zero? num-teams-to-transfer))
{:type :confirm (st/emit! (modal/show
:title (tr "modals.before-leave-org.title" (:name organization)) {:type :confirm
:message (tr "modals.before-leave-org.message") :title (tr "modals.before-leave-org.title" (:name organization))
:accept-label (tr "modals.leave-org-confirm.accept") :message (tr "modals.before-leave-org.message")
:on-accept leave-fn :accept-label (tr "modals.leave-org-confirm.accept")
:error-msg (tr "modals.before-leave-org.warning")})) :on-accept leave-fn
(pos? num-teams-to-transfer) :error-msg (tr "modals.before-leave-org.warning")}))
#(st/emit! (pos? num-teams-to-transfer)
(modal/show (st/emit!
{:type :leave-and-reassign-org (modal/show
:profile profile {:type :leave-and-reassign-org
:teams-to-transfer teams-to-transfer :profile profile
:num-teams-to-delete num-teams-to-delete :teams-to-transfer teams-to-transfer
:accept leave-fn})) :num-teams-to-delete num-teams-to-delete
:accept leave-fn}))
:else :else
#(st/emit! (modal/show (st/emit! (modal/show
{:type :confirm {:type :confirm
:title (tr "modals.leave-org-confirm.title" (:name organization)) :title (tr "modals.leave-org-confirm.title" (:name organization))
:message (tr "modals.leave-org-confirm.message") :message (tr "modals.leave-org-confirm.message")
:accept-label (tr "modals.leave-org-confirm.accept") :accept-label (tr "modals.leave-org-confirm.accept")
:on-accept leave-fn}))))] :on-accept leave-fn})))))]
(mf/use-effect (mf/use-effect
(fn [] (fn []
;; We need all the team members of the owned teams ;; We need all the team members of the owned teams
@ -817,10 +820,10 @@
(mf/defc sidebar-team-switch* (mf/defc sidebar-team-switch*
[{:keys [team profile]}] [{:keys [team profile]}]
(let [nitrate? (contains? cf/flags :nitrate) (let [nitrate? (contains? cf/flags :nitrate)
org-id (when nitrate? (:organization-id team)) organization-id (when nitrate? (:organization-id team))
teams (cond->> (mf/deref refs/teams) teams (cond->> (mf/deref refs/teams)
nitrate? nitrate?
(filter #(= (-> % val :organization-id) org-id)) (filter #(= (-> % val :organization-id) organization-id))
nitrate? nitrate?
(into {})) (into {}))