mirror of
https://github.com/penpot/penpot.git
synced 2026-09-07 04:29:31 +00:00
🐛 Fix nitrate lookups to use nested organization
* 🐛 Fix nitrate lookups to use nested organization * 📎 Code review
This commit is contained in:
parent
639a457c69
commit
5a3d5f86af
@ -187,9 +187,9 @@
|
|||||||
(rx/mapcat
|
(rx/mapcat
|
||||||
(fn [teams]
|
(fn [teams]
|
||||||
(let [all-orgs (map dt/team->organization
|
(let [all-orgs (map dt/team->organization
|
||||||
(filter #(and (:is-default %) (:organization-id %)) teams))
|
(filter #(and (:is-default %) (:organization %)) teams))
|
||||||
orgs (filter (fn [org]
|
orgs (filter (fn [org]
|
||||||
(let [perm (get-in org [:permissions :create-teams])
|
(let [perm (dm/get-in org [:permissions :create-teams])
|
||||||
is-own? (= profile-id (:owner-id org))]
|
is-own? (= profile-id (:owner-id org))]
|
||||||
(or (= perm "any") is-own?))) all-orgs)
|
(or (= perm "any") is-own?))) all-orgs)
|
||||||
team (first (filter #(= (:id %) team-id) teams))
|
team (first (filter #(= (:id %) team-id) teams))
|
||||||
|
|||||||
@ -94,8 +94,7 @@
|
|||||||
{:organization-id (:id organization)
|
{:organization-id (:id organization)
|
||||||
:organization-name (:name organization)}
|
:organization-name (:name organization)}
|
||||||
{}))
|
{}))
|
||||||
(modal/show :no-permission-modal {:type :create-team
|
(modal/show :no-permission-modal {:type :create-team})))))))))))
|
||||||
:organization-name (:name organization)})))))))))))
|
|
||||||
|
|
||||||
(defn check-and-delete-team
|
(defn check-and-delete-team
|
||||||
"Fetches fresh team data from the server to ensure up-to-date org
|
"Fetches fresh team data from the server to ensure up-to-date org
|
||||||
@ -129,8 +128,7 @@
|
|||||||
:message message
|
:message message
|
||||||
:accept-label (tr "modals.delete-team-confirm.accept")
|
:accept-label (tr "modals.delete-team-confirm.accept")
|
||||||
:on-accept delete-fn})
|
:on-accept delete-fn})
|
||||||
(modal/show :no-permission-modal {:type :delete-team
|
(modal/show :no-permission-modal {:type :delete-team})))))))))))
|
||||||
:organization-name (:name org)})))))))))))
|
|
||||||
|
|
||||||
;; --- EVENT: fetch-members
|
;; --- EVENT: fetch-members
|
||||||
|
|
||||||
|
|||||||
@ -469,8 +469,7 @@
|
|||||||
(rx/of (ntf/error (tr "errors.team-leave.owner-cant-leave")))
|
(rx/of (ntf/error (tr "errors.team-leave.owner-cant-leave")))
|
||||||
|
|
||||||
:not-allowed
|
:not-allowed
|
||||||
(rx/of (modal/show :no-permission-modal {:type :delete-team
|
(rx/of (modal/show :no-permission-modal {:type :delete-team}))
|
||||||
:organization-name (dm/get-in team [:organization :name])}))
|
|
||||||
|
|
||||||
(rx/throw error))))
|
(rx/throw error))))
|
||||||
|
|
||||||
@ -717,7 +716,7 @@
|
|||||||
org-teams (mf/with-memo [teams current-org]
|
org-teams (mf/with-memo [teams current-org]
|
||||||
(->> teams
|
(->> teams
|
||||||
vals
|
vals
|
||||||
(filter #(= (:organization-id %) (:id current-org)))))
|
(filter #(= (dm/get-in % [:organization :id]) (:id current-org)))))
|
||||||
|
|
||||||
default-org? (nil? (:id current-org))
|
default-org? (nil? (:id current-org))
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
(ns app.main.ui.dashboard.subscription
|
(ns app.main.ui.dashboard.subscription
|
||||||
(:require-macros [app.main.style :as stl])
|
(:require-macros [app.main.style :as stl])
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.main.data.event :as ev]
|
[app.main.data.event :as ev]
|
||||||
@ -122,16 +121,10 @@
|
|||||||
(let [nitrate? (dnt/is-valid-license? profile)
|
(let [nitrate? (dnt/is-valid-license? profile)
|
||||||
nitrate-license (:subscription profile)
|
nitrate-license (:subscription profile)
|
||||||
subscription-type (if nitrate? (:type nitrate-license) (get-subscription-type (-> profile :props :subscription)))
|
subscription-type (if nitrate? (:type nitrate-license) (get-subscription-type (-> profile :props :subscription)))
|
||||||
orgs (mf/with-memo [teams]
|
no-orgs-created? (mf/with-memo [teams]
|
||||||
(let [orgs (->> teams
|
(->> teams
|
||||||
vals
|
vals
|
||||||
(group-by :organization-id)
|
(not-any? :organization)))
|
||||||
(map (fn [[_group entries]] (first entries)))
|
|
||||||
vec
|
|
||||||
(d/index-by :id))]
|
|
||||||
orgs))
|
|
||||||
|
|
||||||
no-orgs-created? (= (count orgs) 1)
|
|
||||||
|
|
||||||
handle-click
|
handle-click
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
|||||||
@ -1374,7 +1374,7 @@
|
|||||||
all-organizations (mf/with-memo [all-organizations]
|
all-organizations (mf/with-memo [all-organizations]
|
||||||
(->> (vals all-organizations)
|
(->> (vals all-organizations)
|
||||||
(filter :is-default)
|
(filter :is-default)
|
||||||
(filter :organization-id)
|
(filter :organization)
|
||||||
(map dtm/team->organization)))
|
(map dtm/team->organization)))
|
||||||
|
|
||||||
;; Filter to orgs where user is allowed to create/add teams
|
;; Filter to orgs where user is allowed to create/add teams
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
(ns app.main.ui.dashboard.team-form
|
(ns app.main.ui.dashboard.team-form
|
||||||
(:require-macros [app.main.style :as stl])
|
(:require-macros [app.main.style :as stl])
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.types.team :as ctt]
|
[app.common.types.team :as ctt]
|
||||||
[app.main.data.common :as dcm]
|
[app.main.data.common :as dcm]
|
||||||
@ -14,6 +15,7 @@
|
|||||||
[app.main.data.modal :as modal]
|
[app.main.data.modal :as modal]
|
||||||
[app.main.data.notifications :as ntf]
|
[app.main.data.notifications :as ntf]
|
||||||
[app.main.data.team :as dtm]
|
[app.main.data.team :as dtm]
|
||||||
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.components.forms :as fm]
|
[app.main.ui.components.forms :as fm]
|
||||||
[app.main.ui.icons :as deprecated-icon]
|
[app.main.ui.icons :as deprecated-icon]
|
||||||
@ -42,20 +44,19 @@
|
|||||||
(modal/hide))))
|
(modal/hide))))
|
||||||
|
|
||||||
(defn- on-error
|
(defn- on-error
|
||||||
[form organization-name response]
|
[form response]
|
||||||
(let [id (get-in @form [:clean-data :id])
|
(let [id (get-in @form [:clean-data :id])
|
||||||
code (-> response ex-data :code)]
|
code (-> response ex-data :code)]
|
||||||
(if (= code :not-allowed)
|
(if (= code :not-allowed)
|
||||||
(rx/of (modal/show :no-permission-modal {:type :create-team
|
(rx/of (modal/show :no-permission-modal {:type :create-team}))
|
||||||
:organization-name organization-name}))
|
|
||||||
(if id
|
(if id
|
||||||
(rx/of (ntf/error "Error on updating team."))
|
(rx/of (ntf/error "Error on updating team."))
|
||||||
(rx/of (ntf/error "Error on creating team."))))))
|
(rx/of (ntf/error "Error on creating team."))))))
|
||||||
|
|
||||||
(defn- on-create-submit
|
(defn- on-create-submit
|
||||||
[form organization-name]
|
[form]
|
||||||
(let [mdata {:on-success (partial on-create-success form)
|
(let [mdata {:on-success (partial on-create-success form)
|
||||||
:on-error (partial on-error form organization-name)}
|
:on-error (partial on-error form)}
|
||||||
data (:clean-data @form)
|
data (:clean-data @form)
|
||||||
params (cond-> {:name (:name data)}
|
params (cond-> {:name (:name data)}
|
||||||
(:organization-id data) (assoc :organization-id (:organization-id data)))]
|
(:organization-id data) (assoc :organization-id (:organization-id data)))]
|
||||||
@ -65,23 +66,23 @@
|
|||||||
(defn- on-update-submit
|
(defn- on-update-submit
|
||||||
[form]
|
[form]
|
||||||
(let [mdata {:on-success (partial on-update-success form)
|
(let [mdata {:on-success (partial on-update-success form)
|
||||||
:on-error (partial on-error form nil)}
|
:on-error (partial on-error form)}
|
||||||
data (:clean-data @form)
|
data (:clean-data @form)
|
||||||
team (select-keys data [:id :name])]
|
team (select-keys data [:id :name])]
|
||||||
(st/emit! (dtm/update-team (with-meta team mdata))
|
(st/emit! (dtm/update-team (with-meta team mdata))
|
||||||
(modal/hide))))
|
(modal/hide))))
|
||||||
|
|
||||||
(defn- on-submit
|
(defn- on-submit
|
||||||
[organization-name form _]
|
[form _]
|
||||||
(let [data (:clean-data @form)]
|
(let [data (:clean-data @form)]
|
||||||
(if (:id data)
|
(if (:id data)
|
||||||
(on-update-submit form)
|
(on-update-submit form)
|
||||||
(on-create-submit form organization-name))))
|
(on-create-submit form))))
|
||||||
|
|
||||||
(mf/defc team-form-modal
|
(mf/defc team-form-modal
|
||||||
{::mf/register modal/components
|
{::mf/register modal/components
|
||||||
::mf/register-as :team-form}
|
::mf/register-as :team-form}
|
||||||
[{:keys [team organization-id organization-name] :as props}]
|
[{:keys [team organization-id] :as props}]
|
||||||
(let [initial (mf/use-memo
|
(let [initial (mf/use-memo
|
||||||
(mf/deps team organization-id)
|
(mf/deps team organization-id)
|
||||||
(fn []
|
(fn []
|
||||||
@ -94,16 +95,15 @@
|
|||||||
form (fm/use-form :schema schema:team-form
|
form (fm/use-form :schema schema:team-form
|
||||||
:initial initial)
|
:initial initial)
|
||||||
on-submit* (mf/use-fn
|
on-submit* (mf/use-fn
|
||||||
(mf/deps organization-name)
|
(partial on-submit form))
|
||||||
(partial on-submit organization-name))
|
|
||||||
handle-keydown
|
handle-keydown
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps organization-name)
|
(mf/deps form)
|
||||||
(fn [e]
|
(fn [e]
|
||||||
(when (kbd/enter? e)
|
(when (kbd/enter? e)
|
||||||
(dom/prevent-default e)
|
(dom/prevent-default e)
|
||||||
(dom/stop-propagation e)
|
(dom/stop-propagation e)
|
||||||
(on-submit organization-name form e))))]
|
(on-submit form e))))]
|
||||||
|
|
||||||
[:div {:class (stl/css :modal-overlay)}
|
[:div {:class (stl/css :modal-overlay)}
|
||||||
[:div {:class (stl/css :modal-container)}
|
[:div {:class (stl/css :modal-container)}
|
||||||
@ -144,8 +144,10 @@
|
|||||||
"Generic modal for displaying permission-related messages based on error type"
|
"Generic modal for displaying permission-related messages based on error type"
|
||||||
{::mf/register modal/components
|
{::mf/register modal/components
|
||||||
::mf/register-as :no-permission-modal}
|
::mf/register-as :no-permission-modal}
|
||||||
[{:keys [type organization-name]}]
|
[{:keys [type]}]
|
||||||
(let [[title message] (case type
|
(let [team (mf/deref refs/team)
|
||||||
|
organization-name (dm/get-in team [:organization :name])
|
||||||
|
[title message] (case type
|
||||||
:create-team [(tr "labels.create-team")
|
:create-team [(tr "labels.create-team")
|
||||||
(tr "dashboard.no-permission-create-team.message" organization-name)]
|
(tr "dashboard.no-permission-create-team.message" organization-name)]
|
||||||
:delete-team [(tr "dashboard.delete-team")
|
:delete-team [(tr "dashboard.delete-team")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user