mirror of
https://github.com/penpot/penpot.git
synced 2026-05-30 04:08:08 +00:00
🐛 Fix nitrate remove-team permission flow
This commit is contained in:
parent
a637dda554
commit
8542d44aaa
@ -215,7 +215,45 @@
|
||||
(->> (rp/cmd! ::remove-team-from-org {:team-id team-id :organization-id organization-id :organization-name organization-name})
|
||||
(rx/mapcat
|
||||
(fn [_]
|
||||
(rx/of (modal/hide))))))))
|
||||
(rx/of (modal/hide))))
|
||||
(rx/catch
|
||||
(fn [cause]
|
||||
(let [code (-> cause ex-data :code)]
|
||||
(if (= code :not-allowed)
|
||||
(rx/of (modal/show :no-permission-modal {:type :no-orgs-change}))
|
||||
(rx/throw cause)))))))))
|
||||
|
||||
(defn show-remove-team-from-org-modal
|
||||
"Fetches fresh team/org data, then shows the remove-from-org confirmation
|
||||
modal or the no-permission modal if the move-team permission blocks it."
|
||||
[{:keys [team-id]}]
|
||||
(ptk/reify ::show-remove-team-from-org-modal
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [profile-id (dm/get-in state [:profile :id])]
|
||||
(dt/with-refreshed-team team-id
|
||||
(fn [team]
|
||||
(let [source-org (:organization team)
|
||||
can-move? (nitrate-perms/allowed?
|
||||
:move-team
|
||||
{:org-perms {:owner-id (:owner-id source-org)
|
||||
:permissions (:permissions source-org)}
|
||||
:profile-id profile-id
|
||||
:team-perms (:permissions team)
|
||||
:target-org-same-owner? false})]
|
||||
(rx/of (if can-move?
|
||||
(modal/show
|
||||
{:type :confirm
|
||||
:title (tr "modals.remove-team-org.title")
|
||||
:message (tr "modals.remove-team-org.text" (:name team) (dm/get-in team [:organization :name]))
|
||||
:hint (tr "modals.remove-team-org.info")
|
||||
:hint-level :default
|
||||
:accept-label (tr "modals.remove-team-org.accept")
|
||||
:on-accept #(st/emit! (remove-team-from-org {:team-id team-id
|
||||
:organization-id (dm/get-in team [:organization :id])
|
||||
:organization-name (dm/get-in team [:organization :name])}))
|
||||
:accept-style :danger})
|
||||
(modal/show :no-permission-modal {:type :no-orgs-change}))))))))))
|
||||
|
||||
|
||||
(defn add-team-to-org
|
||||
|
||||
@ -67,7 +67,7 @@
|
||||
(->> (rp/cmd! :get-teams)
|
||||
(rx/map teams-fetched)))))
|
||||
|
||||
(defn- with-refreshed-team
|
||||
(defn with-refreshed-team
|
||||
"Fetches fresh team data from the server to ensure up-to-date org
|
||||
permissions, updates the app state, and calls f with the fresh team data.
|
||||
Returns an observable of events."
|
||||
|
||||
@ -1521,27 +1521,11 @@
|
||||
(fn [file]
|
||||
(st/emit! (dtm/update-team-photo file)))
|
||||
|
||||
remove-team-from-org-fn
|
||||
(mf/use-fn
|
||||
(mf/deps team)
|
||||
(fn []
|
||||
(st/emit! (dnt/remove-team-from-org {:team-id (:id team)
|
||||
:organization-id (dm/get-in team [:organization :id])
|
||||
:organization-name (dm/get-in team [:organization :name])}))))
|
||||
|
||||
on-remove-team-from-org
|
||||
(mf/use-fn
|
||||
(mf/deps team)
|
||||
(fn []
|
||||
(let [params {:type :confirm
|
||||
:title (tr "modals.remove-team-org.title")
|
||||
:message (tr "modals.remove-team-org.text" (:name team) (dm/get-in team [:organization :name]))
|
||||
:hint (tr "modals.remove-team-org.info")
|
||||
:hint-level :default
|
||||
:accept-label (tr "modals.remove-team-org.accept")
|
||||
:on-accept remove-team-from-org-fn
|
||||
:accept-style :danger}]
|
||||
(st/emit! (modal/show params)))))
|
||||
(st/emit! (dnt/show-remove-team-from-org-modal {:team-id (:id team)}))))
|
||||
|
||||
on-add-team-to-org
|
||||
(mf/use-fn
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user