From 1bb83b3019ad03005dbe56a3375b4db9f85d021b Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Thu, 25 Aug 2022 17:02:06 +0200 Subject: [PATCH] :bug: Fix bringing complete file data when launching the export dialog --- CHANGES.md | 1 + backend/src/app/http/middleware.clj | 2 +- backend/src/app/rpc.clj | 3 +- backend/src/app/rpc/commands/files.clj | 50 +++++++++++++++++++ .../src/app/main/ui/dashboard/file_menu.cljs | 5 +- .../src/app/main/ui/workspace/header.cljs | 8 ++- 6 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 backend/src/app/rpc/commands/files.clj diff --git a/CHANGES.md b/CHANGES.md index 157fa194c..5416b7d5d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -69,6 +69,7 @@ - Fix unexpected exception and behavior on colorpicker with gradients [Taiga #3448](https://tree.taiga.io/project/penpot/issue/3448) - Fix multiselection with shift not working inside a library group [Taiga #3532](https://tree.taiga.io/project/penpot/issue/3532) - Fix drag and drop graphic assets in groups [Taiga #4002](https://tree.taiga.io/project/penpot/issue/4002) +- Fix bringing complete file data when launching the export dialog [Taiga #4006](https://tree.taiga.io/project/penpot/issue/4006) diff --git a/backend/src/app/http/middleware.clj b/backend/src/app/http/middleware.clj index 626f5a375..95c3a6b17 100644 --- a/backend/src/app/http/middleware.clj +++ b/backend/src/app/http/middleware.clj @@ -115,7 +115,7 @@ (format-response [response request] (let [body (yrs/body response)] - (if (coll? body) + (if (or (boolean? body) (coll? body)) (let [qs (yrq/query request) opts (if (or (contains? cf/flags :transit-readable-response) (str/includes? qs "transit_verbose")) diff --git a/backend/src/app/rpc.clj b/backend/src/app/rpc.clj index 66ffacc52..0f1e61abe 100644 --- a/backend/src/app/rpc.clj +++ b/backend/src/app/rpc.clj @@ -243,7 +243,8 @@ 'app.rpc.commands.comments 'app.rpc.commands.auth 'app.rpc.commands.ldap - 'app.rpc.commands.demo) + 'app.rpc.commands.demo + 'app.rpc.commands.files) (map (partial process-method cfg)) (into {})))) diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj new file mode 100644 index 000000000..5231b1a47 --- /dev/null +++ b/backend/src/app/rpc/commands/files.clj @@ -0,0 +1,50 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) UXBOX Labs SL + +(ns app.rpc.commands.files + (:require + [app.common.spec :as us] + [app.db :as db] + [app.rpc.doc :as-alias doc] + [app.rpc.queries.files :as files] + [app.util.services :as sv] + [clojure.spec.alpha :as s])) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; QUERY COMMANDS +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; --- Query: File Libraries used by a File + +(declare retrieve-has-file-libraries) + +(s/def ::file-id ::us/uuid) +(s/def ::profile-id ::us/uuid) + +(s/def ::has-file-libraries + (s/keys :req-un [::profile-id ::file-id])) + +(sv/defmethod ::has-file-libraries + "Checks if the file has libraries. Returns a boolean" + {::doc/added "1.15.1"} + [{:keys [pool] :as cfg} {:keys [profile-id file-id] :as params}] + (with-open [conn (db/open pool)] + (files/check-read-permissions! pool profile-id file-id) + (retrieve-has-file-libraries conn params))) + +(def ^:private sql:has-file-libraries + "SELECT COUNT(*) > 0 AS has_libraries + FROM file_library_rel AS flr + JOIN file AS fl ON (flr.library_file_id = fl.id) + WHERE flr.file_id = ?::uuid + AND (fl.deleted_at IS NULL OR + fl.deleted_at > now())") + +(defn- retrieve-has-file-libraries + [conn {:keys [file-id]}] + (let [row (db/exec-one! conn [sql:has-file-libraries file-id])] + (:has-libraries row))) + diff --git a/frontend/src/app/main/ui/dashboard/file_menu.cljs b/frontend/src/app/main/ui/dashboard/file_menu.cljs index 7903f591a..0ca0b535f 100644 --- a/frontend/src/app/main/ui/dashboard/file_menu.cljs +++ b/frontend/src/app/main/ui/dashboard/file_menu.cljs @@ -6,7 +6,6 @@ (ns app.main.ui.dashboard.file-menu (:require - [app.common.data :as d] [app.main.data.dashboard :as dd] [app.main.data.events :as ev] [app.main.data.messages :as dm] @@ -166,8 +165,8 @@ (->> (rx/from files) (rx/flat-map (fn [file] - (->> (rp/query :file-libraries {:file-id (:id file)}) - (rx/map #(assoc file :has-libraries? (d/not-empty? %)))))) + (->> (rp/command :has-file-libraries {:file-id (:id file)}) + (rx/map #(assoc file :has-libraries? %))))) (rx/reduce conj []) (rx/subs (fn [files] diff --git a/frontend/src/app/main/ui/workspace/header.cljs b/frontend/src/app/main/ui/workspace/header.cljs index 5f93e4def..bd1228255 100644 --- a/frontend/src/app/main/ui/workspace/header.cljs +++ b/frontend/src/app/main/ui/workspace/header.cljs @@ -6,7 +6,6 @@ (ns app.main.ui.workspace.header (:require - [app.common.data :as d] [app.config :as cf] [app.main.data.events :as ev] [app.main.data.exports :as de] @@ -32,7 +31,6 @@ [potok.core :as ptk] [rumext.alpha :as mf])) - (def workspace-persistence-ref (l/derived :workspace-persistence st/state)) @@ -168,8 +166,8 @@ (->> (rx/of file) (rx/flat-map (fn [file] - (->> (rp/query :file-libraries {:file-id (:id file)}) - (rx/map #(assoc file :has-libraries? (d/not-empty? %)))))) + (->> (rp/command :has-file-libraries {:file-id (:id file)}) + (rx/map #(assoc file :has-libraries? %))))) (rx/reduce conj []) (rx/subs (fn [files] @@ -341,7 +339,7 @@ (if (contains? layout :textpalette) (tr "workspace.header.menu.hide-textpalette") (tr "workspace.header.menu.show-textpalette"))] - [:span.shortcut (sc/get-tooltip :toggle-textpalette)]] + [:span.shortcut (sc/get-tooltip :toggle-textpalette)]] [:li {:on-click #(st/emit! (toggle-flag :display-artboard-names))} [:span