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

🐛 Fix issue when promoting to owner

This commit is contained in:
alonso.torres 2021-03-29 10:27:44 +02:00 committed by Andrey Antukh
parent 7d68d79fc3
commit ea3f2fbfce
2 changed files with 10 additions and 8 deletions

View file

@ -60,6 +60,7 @@
- Fix text selection in comments [#745](https://github.com/penpot/penpot/issues/745)
- Update Work-Sans font [#744](https://github.com/penpot/penpot/issues/744)
- Fix issue with recent files not showing [Taiga #1493](https://tree.taiga.io/project/penpot/issue/1493)
- Fix issue when promoting to owner [Taiga #1494](https://tree.taiga.io/project/penpot/issue/1494)
### :arrow_up: Deps updates

View file

@ -174,7 +174,10 @@
;; convenience, if this bocomes a bottleneck or problematic,
;; we will change it to more efficient fetch mechanims.
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-admin? (some :is-admin perms)]
;; If no member is found, just 404
(when-not member
@ -182,8 +185,7 @@
:code :member-does-not-exist))
;; First check if we have permissions to change roles
(when-not (or (some :is-owner perms)
(some :is-admin perms))
(when-not (or is-owner? is-admin?)
(ex/raise :type :validation
:code :insufficient-permissions))
@ -193,21 +195,20 @@
:code :cant-change-role-to-owner))
;; Don't allow promote to owner to admin users.
(when (and (= role :owner)
(not (:is-owner perms)))
(when (and (not is-owner?) (= role :owner))
(ex/raise :type :validation
:code :cant-promote-to-owner))
(let [params (role->params role)]
;; Only allow single owner on team
(when (and (= role :owner)
(:is-owner perms))
(when (= role :owner)
(db/update! conn :team-profile-rel
{:is-owner false}
{:team-id team-id
:profile-id profile-id}))
(db/update! conn :team-profile-rel params
(db/update! conn :team-profile-rel
params
{:team-id team-id
:profile-id member-id})
nil))))