mirror of
https://github.com/penpot/penpot.git
synced 2025-01-06 14:50:20 -05:00
🐛 Fix incorrect teams query on profile deletion
The current approach prevents profile deletion when there are some extra (soft)deleted teams where the profile is owner
This commit is contained in:
parent
2f79d71262
commit
a923d39603
2 changed files with 26 additions and 4 deletions
|
@ -422,7 +422,9 @@
|
||||||
:deleted-at deleted-at
|
:deleted-at deleted-at
|
||||||
:id profile-id}})
|
:id profile-id}})
|
||||||
|
|
||||||
(rph/with-transform {} (session/delete-fn cfg)))))
|
|
||||||
|
(-> (rph/wrap nil)
|
||||||
|
(rph/with-transform (session/delete-fn cfg))))))
|
||||||
|
|
||||||
|
|
||||||
;; --- HELPERS
|
;; --- HELPERS
|
||||||
|
@ -431,8 +433,11 @@
|
||||||
"WITH owner_teams AS (
|
"WITH owner_teams AS (
|
||||||
SELECT tpr.team_id AS id
|
SELECT tpr.team_id AS id
|
||||||
FROM team_profile_rel AS tpr
|
FROM team_profile_rel AS tpr
|
||||||
|
JOIN team AS t ON (t.id = tpr.team_id)
|
||||||
WHERE tpr.is_owner IS TRUE
|
WHERE tpr.is_owner IS TRUE
|
||||||
AND tpr.profile_id = ?
|
AND tpr.profile_id = ?
|
||||||
|
AND (t.deleted_at IS NULL OR
|
||||||
|
t.deleted_at > now())
|
||||||
)
|
)
|
||||||
SELECT tpr.team_id AS id,
|
SELECT tpr.team_id AS id,
|
||||||
count(tpr.profile_id) - 1 AS participants
|
count(tpr.profile_id) - 1 AS participants
|
||||||
|
|
|
@ -203,7 +203,24 @@
|
||||||
edata (ex-data error)]
|
edata (ex-data error)]
|
||||||
(t/is (th/ex-info? error))
|
(t/is (th/ex-info? error))
|
||||||
(t/is (= (:type edata) :validation))
|
(t/is (= (:type edata) :validation))
|
||||||
(t/is (= (:code edata) :owner-teams-with-people))))))
|
(t/is (= (:code edata) :owner-teams-with-people)))
|
||||||
|
|
||||||
|
(let [params {::th/type :delete-team
|
||||||
|
::rpc/profile-id (:id prof1)
|
||||||
|
:id (:id team1)}
|
||||||
|
out (th/command! params)]
|
||||||
|
;; (th/print-result! out)
|
||||||
|
|
||||||
|
(let [team (th/db-get :team {:id (:id team1)} {::db/remove-deleted false})]
|
||||||
|
(t/is (dt/instant? (:deleted-at team)))))
|
||||||
|
|
||||||
|
;; Request profile to be deleted
|
||||||
|
(let [params {::th/type :delete-profile
|
||||||
|
::rpc/profile-id (:id prof1)}
|
||||||
|
out (th/command! params)]
|
||||||
|
;; (th/print-result! out)
|
||||||
|
(t/is (nil? (:result out)))
|
||||||
|
(t/is (nil? (:error out)))))))
|
||||||
|
|
||||||
(t/deftest profile-deletion-3
|
(t/deftest profile-deletion-3
|
||||||
(let [prof1 (th/create-profile* 1)
|
(let [prof1 (th/create-profile* 1)
|
||||||
|
@ -291,7 +308,7 @@
|
||||||
out (th/command! params)]
|
out (th/command! params)]
|
||||||
;; (th/print-result! out)
|
;; (th/print-result! out)
|
||||||
|
|
||||||
(t/is (= {} (:result out)))
|
(t/is (nil? (:result out)))
|
||||||
(t/is (nil? (:error out))))
|
(t/is (nil? (:error out))))
|
||||||
|
|
||||||
;; query files after profile soft deletion
|
;; query files after profile soft deletion
|
||||||
|
@ -336,7 +353,7 @@
|
||||||
::rpc/profile-id (:id prof1)}
|
::rpc/profile-id (:id prof1)}
|
||||||
out (th/command! params)]
|
out (th/command! params)]
|
||||||
;; (th/print-result! out)
|
;; (th/print-result! out)
|
||||||
(t/is (= {} (:result out)))
|
(t/is (nil? (:result out)))
|
||||||
(t/is (nil? (:error out))))
|
(t/is (nil? (:error out))))
|
||||||
|
|
||||||
(th/run-pending-tasks!)
|
(th/run-pending-tasks!)
|
||||||
|
|
Loading…
Reference in a new issue