0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 22:49:01 -05:00

🐛 Fix problems with team management

This commit is contained in:
alonso.torres 2021-11-24 12:10:25 +01:00 committed by Andrey Antukh
parent 07e8bb00fb
commit 896a07fa9a
4 changed files with 31 additions and 25 deletions

View file

@ -7,6 +7,7 @@
### :bug: Bugs fixed ### :bug: Bugs fixed
- Fix problems when exporting all artboards [Taiga #2234](https://tree.taiga.io/project/penpot/issue/2234). - Fix problems when exporting all artboards [Taiga #2234](https://tree.taiga.io/project/penpot/issue/2234).
- Fix problems with team management [#1353](https://github.com/penpot/penpot/issues/1353)
### :arrow_up: Deps updates ### :arrow_up: Deps updates
### :heart: Community contributions by (Thank you!) ### :heart: Community contributions by (Thank you!)

View file

@ -110,10 +110,10 @@
(sv/defmethod ::leave-team (sv/defmethod ::leave-team
[{:keys [pool] :as cfg} {:keys [id profile-id] :as params}] [{:keys [pool] :as cfg} {:keys [id profile-id] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [perms (teams/check-read-permissions! conn profile-id id) (let [perms (teams/get-permissions conn profile-id id)
members (teams/retrieve-team-members conn id)] members (teams/retrieve-team-members conn id)]
(when (some :is-owner perms) (when (:is-owner perms)
(ex/raise :type :validation (ex/raise :type :validation
:code :owner-cant-leave-team :code :owner-cant-leave-team
:hint "releasing owner before leave")) :hint "releasing owner before leave"))
@ -171,8 +171,7 @@
(sv/defmethod ::update-team-member-role (sv/defmethod ::update-team-member-role
[{:keys [pool] :as cfg} {:keys [team-id profile-id member-id role] :as params}] [{:keys [pool] :as cfg} {:keys [team-id profile-id member-id role] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [perms (teams/check-read-permissions! conn profile-id team-id) (let [perms (teams/get-permissions conn profile-id team-id)
;; We retrieve all team members instead of query the ;; We retrieve all team members instead of query the
;; database for a single member. This is just for ;; database for a single member. This is just for
;; convenience, if this becomes a bottleneck or problematic, ;; convenience, if this becomes a bottleneck or problematic,
@ -180,8 +179,8 @@
members (teams/retrieve-team-members conn team-id) members (teams/retrieve-team-members conn team-id)
member (d/seek #(= member-id (:id %)) members) member (d/seek #(= member-id (:id %)) members)
is-owner? (some :is-owner perms) is-owner? (:is-owner perms)
is-admin? (some :is-admin perms)] is-admin? (:is-admin perms)]
;; If no member is found, just 404 ;; If no member is found, just 404
(when-not member (when-not member
@ -234,9 +233,9 @@
(sv/defmethod ::delete-team-member (sv/defmethod ::delete-team-member
[{:keys [pool] :as cfg} {:keys [team-id profile-id member-id] :as params}] [{:keys [pool] :as cfg} {:keys [team-id profile-id member-id] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [perms (teams/check-read-permissions! conn profile-id team-id)] (let [perms (teams/get-permissions conn profile-id team-id)]
(when-not (or (some :is-owner perms) (when-not (or (:is-owner perms)
(some :is-admin perms)) (:is-admin perms))
(ex/raise :type :validation (ex/raise :type :validation
:code :insufficient-permissions)) :code :insufficient-permissions))

View file

@ -230,9 +230,12 @@
(mf/defc leave-and-reassign-modal (mf/defc leave-and-reassign-modal
{::mf/register modal/components {::mf/register modal/components
::mf/register-as ::leave-and-reassign} ::mf/register-as ::leave-and-reassign}
[{:keys [members profile team accept]}] [{:keys [team accept]}]
(let [form (fm/use-form :spec ::leave-modal-form :initial {}) (let [form (fm/use-form :spec ::leave-modal-form :initial {})
members (some->> members (filterv #(not= (:id %) (:id profile))))
members-map (mf/deref refs/dashboard-team-members)
members (vals members-map)
options (into [{:value "" options (into [{:value ""
:label (tr "modals.leave-and-reassign.select-member-to-promote")}] :label (tr "modals.leave-and-reassign.select-member-to-promote")}]
(map #(hash-map :label (:name %) :value (str (:id %))) members)) (map #(hash-map :label (:name %) :value (str (:id %))) members))
@ -290,7 +293,7 @@
on-leaved-success on-leaved-success
(fn [] (fn []
(st/emit! (modal/hide) (st/emit! (modal/hide)
(dd/go-to-projects (:default-team-id profile)))) (du/fetch-teams)))
leave-fn leave-fn
(st/emitf (dd/leave-team (with-meta {} {:on-success on-leaved-success}))) (st/emitf (dd/leave-team (with-meta {} {:on-success on-leaved-success})))
@ -298,7 +301,8 @@
leave-and-reassign-fn leave-and-reassign-fn
(fn [member-id] (fn [member-id]
(let [params {:reassign-to member-id}] (let [params {:reassign-to member-id}]
(st/emit! (dd/leave-team (with-meta params {:on-success on-leaved-success}))))) (st/emit! (dd/go-to-projects (:default-team-id profile))
(dd/leave-team (with-meta params {:on-success on-leaved-success})))))
on-leave-clicked on-leave-clicked
(st/emitf (modal/show (st/emitf (modal/show
@ -309,12 +313,13 @@
:on-accept leave-fn})) :on-accept leave-fn}))
on-leave-as-owner-clicked on-leave-as-owner-clicked
(st/emitf (modal/show (fn []
{:type ::leave-and-reassign (st/emit! (dd/fetch-team-members)
:profile profile (modal/show
:team team {:type ::leave-and-reassign
:members members :profile profile
:accept leave-and-reassign-fn})) :team team
:accept leave-and-reassign-fn})))
delete-fn delete-fn
(st/emitf (dd/delete-team (with-meta team {:on-success on-leaved-success}))) (st/emitf (dd/delete-team (with-meta team {:on-success on-leaved-success})))
@ -335,14 +340,14 @@
[:li {:on-click on-rename-clicked} (tr "labels.rename")] [:li {:on-click on-rename-clicked} (tr "labels.rename")]
(cond (cond
(:is-owner team) (get-in team [:permissions :is-owner])
[:li {:on-click on-leave-as-owner-clicked} (tr "dashboard.leave-team")] [:li {:on-click on-leave-as-owner-clicked} (tr "dashboard.leave-team")]
(> (count members) 1) (> (count members) 1)
[:li {:on-click on-leave-clicked} (tr "dashboard.leave-team")]) [:li {:on-click on-leave-clicked} (tr "dashboard.leave-team")])
(when (:is-owner team) (when (get-in team [:permissions :is-owner])
[:li {:on-click on-delete-clicked} (tr "dashboard.delete-team")])])) [:li {:on-click on-delete-clicked} (tr "dashboard.delete-team")])]))

View file

@ -124,6 +124,7 @@
(mf/defc team-member (mf/defc team-member
{::mf/wrap [mf/memo]} {::mf/wrap [mf/memo]}
[{:keys [team member profile] :as props}] [{:keys [team member profile] :as props}]
(let [show? (mf/use-state false) (let [show? (mf/use-state false)
set-role set-role
@ -174,8 +175,8 @@
[:span.label (tr "labels.viewer")]) [:span.label (tr "labels.viewer")])
(when (and (not (:is-owner member)) (when (and (not (:is-owner member))
(or (:is-admin team) (or (get-in team [:permissions :is-admin])
(:is-owner team))) (get-in team [:permissions :is-owner])))
[:span.icon {:on-click #(reset! show? true)} i/arrow-down])] [:span.icon {:on-click #(reset! show? true)} i/arrow-down])]
[:& dropdown {:show @show? [:& dropdown {:show @show?
@ -191,8 +192,8 @@
[:hr] [:hr]
[:li {:on-click set-owner} (tr "dashboard.promote-to-owner")]]) [:li {:on-click set-owner} (tr "dashboard.promote-to-owner")]])
[:hr] [:hr]
(when (and (or (:is-owner team) (when (and (or (get-in team [:permissions :is-owner])
(:is-admin team)) (get-in team [:permissions :is-admin]))
(not= (:id profile) (not= (:id profile)
(:id member))) (:id member)))
[:li {:on-click delete} (tr "labels.remove")])]]]])) [:li {:on-click delete} (tr "labels.remove")])]]]]))