From 2c96ecac8718b7a1e8c598df5601babca47fbfb6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 7 May 2021 11:50:31 +0200 Subject: [PATCH] :bug: Fix wrong query for obtain profile default project-id. --- CHANGES.md | 1 + backend/src/app/rpc/queries/profile.clj | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 75192a939..79a1f21ad 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ ### :bug: Bugs fixed - Fix problem with `close-path` command [#917](https://github.com/penpot/penpot/issues/917) +- Fix wrong query for obtain the profile default project-id ## 1.5.1-alpha diff --git a/backend/src/app/rpc/queries/profile.clj b/backend/src/app/rpc/queries/profile.clj index 8016b3d94..ee974c359 100644 --- a/backend/src/app/rpc/queries/profile.clj +++ b/backend/src/app/rpc/queries/profile.clj @@ -41,29 +41,27 @@ {:id uuid/zero :fullname "Anonymous User"})) -;; NOTE: this query make the assumption that union all preserves the -;; order so the first id will always be the team id and the second the -;; project_id; this is a postgresql behavior because UNION ALL works -;; like APPEND operation. - -(def ^:private sql:default-team-and-project - "select t.id +(def ^:private sql:default-profile-team + "select t.id, name from team as t inner join team_profile_rel as tp on (tp.team_id = t.id) where tp.profile_id = ? and tp.is_owner is true - and t.is_default is true - union all - select p.id + and t.is_default is true") + +(def ^:private sql:default-profile-project + "select p.id, name from project as p inner join project_profile_rel as tp on (tp.project_id = p.id) where tp.profile_id = ? and tp.is_owner is true - and p.is_default is true") + and p.is_default is true + and p.team_id = ?") (defn retrieve-additional-data [conn id] - (let [[team project] (db/exec! conn [sql:default-team-and-project id id])] + (let [team (db/exec-one! conn [sql:default-profile-team id]) + project (db/exec-one! conn [sql:default-profile-project id (:id team)])] {:default-team-id (:id team) :default-project-id (:id project)}))