diff --git a/backend/src/app/binfile/common.clj b/backend/src/app/binfile/common.clj index f9af5727c1..6e994b00b5 100644 --- a/backend/src/app/binfile/common.clj +++ b/backend/src/app/binfile/common.clj @@ -454,17 +454,21 @@ (true? (:main-instance shape)))) (defn- has-component-data? - [{:keys [components pages-index]}] + "Whether a components v1 file holds library data that only the removed + v1 to v2 migration could convert: components, shapes linked to them, or + graphics (`:media`), which v2 turns into components." + [{:keys [components media pages-index]}] (or (seq components) + (seq media) (some (fn [page] (some component-shape? (vals (:objects page)))) (vals pages-index)))) (defn check-components-v2 "Check that an imported file can be stored as a components v2 file. A file without the `components/v2` feature is in the deprecated - components v1 format: it is rejected when it has components or shapes - linked to them, and otherwise takes the feature as it is. Returns the - file." + components v1 format: it is rejected when it has components, shapes + linked to them or graphics, and otherwise takes the feature as it is. + Returns the file." [{:keys [features data] :as file}] (cond (contains? features "components/v2") diff --git a/backend/test/backend_tests/binfile_test.clj b/backend/test/backend_tests/binfile_test.clj index 1f04a7ddb1..ac057c7e24 100644 --- a/backend/test/backend_tests/binfile_test.clj +++ b/backend/test/backend_tests/binfile_test.clj @@ -3813,6 +3813,12 @@ (t/is (rejected? (file #{} {:shape-ref (uuid/custom 2 2)} nil))) (t/is (rejected? (file #{} {:main-instance true} nil)))) + (t/testing "a file without components/v2 is rejected when it has graphics" + (let [media-id (uuid/custom 6 1)] + (t/is (rejected? (assoc-in (file #{} {} nil) [:data :media] + {media-id {:id media-id :name "icon" :width 24 :height 24 + :mtype "image/svg+xml" :media-id (uuid/custom 6 2)}}))))) + (t/testing "a file without components/v2 and without component data takes the feature" (t/is (= #{"components/v2"} (:features (bfc/check-components-v2 (file #{} {} nil))))))