💄 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>
</table>
<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>
</div>
</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!
{{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:

View File

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

View File

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

View File

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

View File

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

View File

@ -50,15 +50,15 @@
returning *")
(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
{:iss :team-invitation
:exp valid-until
:profile-id profile-id
:role role
:team-id team-id
:org-id org-id
:org-name org-name
:organization-id organization-id
:organization-name organization-name
:member-email member-email
:member-id member-id}))
@ -178,8 +178,8 @@
:invitation-id (:id invitation)
:valid-until expire
:team-id (:id team)
:org-id (:id organization)
:org-name (:name organization)
:organization-id (:id organization)
:organization-name (:name organization)
:member-email (:email-to invitation)
:member-id (:id member)
:role role}
@ -210,7 +210,7 @@
:to email
:invited-by (:fullname profile)
:user-name (:fullname member)
:org-name (:name organization)
:organization-name (:name organization)
:org-logo (:logo organization)
:org-initials (d/get-initials (:name organization))
:token itoken

View File

@ -89,7 +89,7 @@
(defn- accept-invitation
[{: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
role (or (some-> invitation :role keyword) role)
id-member (:id member)]
@ -109,10 +109,10 @@
:profile-id id-member}
(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
(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
(do (teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true})
team-id))]
@ -134,7 +134,7 @@
(db/delete! conn :team-invitation
(cond-> {:email-to member-email}
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)
(when team-id
@ -151,11 +151,11 @@
[:profile-id ::sm/uuid]
[:role types.team/schema:role]
[:team-id {:optional true} ::sm/uuid]
[:org-id {:optional true} ::sm/uuid]
[:organization-id {:optional true} ::sm/uuid]
[:member-email ::sm/email]
[:member-id {:optional true} ::sm/uuid]]
[:fn {:error/message "team-id or org-id must be present"}
(fn [m] (or (:team-id m) (:org-id m)))]])
[:fn {:error/message "team-id or organization-id must be present"}
(fn [m] (or (:team-id m) (:organization-id m)))]])
(def valid-team-invitation-claims?
(sm/lazy-validator schema:team-invitation-claims))
@ -163,7 +163,7 @@
(defmethod process-token :team-invitation
[{:keys [::db/conn] :as cfg}
{: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)
(ex/raise :type :validation
@ -173,16 +173,16 @@
(let [invitation (db/get* conn :team-invitation
(cond-> {:email-to member-email}
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
{:id profile-id}
{:columns [:id :email :default-team-id]})
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?
(nitrate/call cfg :get-org-membership {:profile-id profile-id
:org-id org-id}))]
:organization-id organization-id}))]
(if profile
(do
@ -240,7 +240,7 @@
(cond-> (assoc claims :state :created)
;; when the invitation is to an org, instead of a team, add the
;; accepted-team-id as :org-team-id
(:org-id claims)
(:organization-id claims)
(assoc :org-team-id accepted-team-id)))))
;; 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
[:map
[:org-name ::sm/text]
[:organization-name ::sm/text]
[:teams [:vector ::sm/uuid]]])
(sv/defmethod ::notify-org-deletion
@ -225,9 +225,9 @@ RETURNING id, name;")
of the deletion to the connected users"
{::doc/added "2.15"
::sm/params schema:notify-org-deletion}
[cfg {:keys [teams org-name]}]
[cfg {:keys [teams organization-name]}]
(when (seq teams)
(let [org-prefix (str "[" (d/sanitize-string org-name) "] ")]
(let [org-prefix (str "[" (d/sanitize-string organization-name) "] ")]
(db/tx-run!
cfg
(fn [{:keys [::db/conn] :as cfg}]
@ -237,7 +237,7 @@ RETURNING id, name;")
;; Notify users
(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
@ -373,24 +373,26 @@ RETURNING id, name;")
{::doc/added "2.16"
::sm/params [:map
[:profile-id ::sm/uuid]
[:org-id ::sm/uuid]
[:org-name ::sm/text]
[:organization-id ::sm/uuid]
[:organization-name ::sm/text]
[:default-team-id ::sm/uuid]]
::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
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)
valid-teams-to-leave (into valid-teams-to-exit
(map add-reassign-to valid-teams-to-transfer))]
(cnit/leave-org cfg (assoc params
:id organization-id
:name organization-name
:teams-to-delete valid-teams-to-delete-ids
:teams-to-leave valid-teams-to-leave
: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))
;; API: get-remove-from-org-summary
@ -407,15 +409,15 @@ RETURNING id, name;")
{::doc/added "2.16"
::sm/params [:map
[:profile-id ::sm/uuid]
[:org-id ::sm/uuid]
[:organization-id ::sm/uuid]
[:default-team-id ::sm/uuid]]
::sm/result schema:get-remove-from-org-summary-result
::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
valid-teams-to-transfer
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
(ex/raise :type :validation
:code :not-valid-teams))

View File

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

View File

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

View File

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

View File

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

View File

@ -43,14 +43,14 @@
(st/emit! (da/login-from-token tdata)))
(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
:created
(if org-team-id
(st/emit!
(du/refresh-profile)
(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!
(du/refresh-profile)
(dcm/go-to-dashboard-recent :team-id team-id)

View File

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

View File

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