0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 14:39:45 -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
- 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
### :heart: Community contributions by (Thank you!)

View file

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

View file

@ -230,9 +230,12 @@
(mf/defc leave-and-reassign-modal
{::mf/register modal/components
::mf/register-as ::leave-and-reassign}
[{:keys [members profile team accept]}]
[{:keys [team accept]}]
(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 ""
:label (tr "modals.leave-and-reassign.select-member-to-promote")}]
(map #(hash-map :label (:name %) :value (str (:id %))) members))
@ -290,7 +293,7 @@
on-leaved-success
(fn []
(st/emit! (modal/hide)
(dd/go-to-projects (:default-team-id profile))))
(du/fetch-teams)))
leave-fn
(st/emitf (dd/leave-team (with-meta {} {:on-success on-leaved-success})))
@ -298,7 +301,8 @@
leave-and-reassign-fn
(fn [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
(st/emitf (modal/show
@ -309,12 +313,13 @@
:on-accept leave-fn}))
on-leave-as-owner-clicked
(st/emitf (modal/show
{:type ::leave-and-reassign
:profile profile
:team team
:members members
:accept leave-and-reassign-fn}))
(fn []
(st/emit! (dd/fetch-team-members)
(modal/show
{:type ::leave-and-reassign
:profile profile
:team team
:accept leave-and-reassign-fn})))
delete-fn
(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")]
(cond
(:is-owner team)
(get-in team [:permissions :is-owner])
[:li {:on-click on-leave-as-owner-clicked} (tr "dashboard.leave-team")]
(> (count members) 1)
[: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")])]))

View file

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